name: Auto Label Issues on: issues: types: - opened - edited jobs: auto-label: if: ${{ github.event.issue.body && contains(github.event.issue.body, '### Plugin') }} runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 - name: Extract the severity from issue body id: extract-severity run: | USER_SELECTED_SEVERITY=$(echo "${{ github.event.issue.body }}" | grep "### Severity" -A 2 | tail -n 1 | sed 's/[[:space:]]*$//') SELECTED_SEVERITY="" case "$USER_SELECTED_SEVERITY" in "Wrong formatting"|"Wrong content"|"Missing chapter"|"Missing images"|"Can't load novels") SELECTED_SEVERITY="$USER_SELECTED_SEVERITY" ;; *) SELECTED_SEVERITY="Other" ;; esac echo "SELECTED_SEVERITY=$SELECTED_SEVERITY" >> $GITHUB_ENV - name: Extract the plugin from issue body id: parse-issue run: | SELECTED_PLUGIN=$(echo "${{ github.event.issue.body }}" | grep "### Plugin" -A 2 | tail -n 1 | sed 's/[[:space:]]*$//') echo "SELECTED_PLUGIN=$SELECTED_PLUGIN" >> $GITHUB_ENV - name: Determine corresponding label id: determine-label run: | LABELS="$( jq --arg keys "${{ env.SELECTED_PLUGIN }}" '. as $data | $keys | split(", ") as $keyList | $keyList[] | . as $key | if $data[$key] != null then "\($key)[\($data[$key])]" else empty end' ./.github/scripts/keys.json | sed 's/"//g' | sed 's/^[^:]*: //' )" # Add "Plugin: " in front of each label LABELS_WITH_PREFIX="$(echo "$LABELS" | sed 's/^/Plugin: /')" # Save to GitHub environment printf "LABELS<> $GITHUB_ENV - name: Add label to the issue if: env.LABELS != '' uses: actions-ecosystem/action-add-labels@v1 with: labels: | BUG Severity: ${{ env.SELECTED_SEVERITY }} ${{ env.LABELS }} - name: Handle missing label if: env.LABELS == '' run: echo "No matching label found for the selected plugin."