|
| 1 | +name: Close Matching Issue on PR Merge |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: |
| 5 | + - closed |
| 6 | +jobs: |
| 7 | + close_issue: |
| 8 | + if: github.event.pull_request.merged == true |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + steps: |
| 12 | + - name: Extract and Process PR Title |
| 13 | + id: extract_title |
| 14 | + run: | |
| 15 | + title=$(echo "${{ github.event.pull_request.title }}" | sed 's/^New Script://g' | tr '[:upper:]' '[:lower:]' | sed 's/ //g' | sed 's/-//g') |
| 16 | + echo "Processed Title: $title" |
| 17 | + echo "title=$title" >> $GITHUB_ENV |
| 18 | +
|
| 19 | + - name: Search for Issues with Similar Titles |
| 20 | + id: find_issue |
| 21 | + env: |
| 22 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 23 | + run: | |
| 24 | + issues=$(gh issue list --repo community-scripts/ProxmoxVED --json number,title --jq '.[] | {number, title}') |
| 25 | + |
| 26 | + best_match_score=0 |
| 27 | + best_match_number=0 |
| 28 | + |
| 29 | + for issue in $(echo "$issues" | jq -r '. | @base64'); do |
| 30 | + _jq() { |
| 31 | + echo ${issue} | base64 --decode | jq -r ${1} |
| 32 | + } |
| 33 | +
|
| 34 | + issue_title=$(_jq '.title' | tr '[:upper:]' '[:lower:]' | sed 's/ //g' | sed 's/-//g') |
| 35 | + issue_number=$(_jq '.number') |
| 36 | +
|
| 37 | + match_score=$(echo "$title" | grep -o "$issue_title" | wc -l) |
| 38 | + |
| 39 | + if [ "$match_score" -gt "$best_match_score" ]; then |
| 40 | + best_match_score=$match_score |
| 41 | + best_match_number=$issue_number |
| 42 | + fi |
| 43 | + done |
| 44 | +
|
| 45 | + if [ "$best_match_number" != "0" ]; then |
| 46 | + echo "issue_number=$best_match_number" >> $GITHUB_ENV |
| 47 | + else |
| 48 | + echo "No matching issue found." |
| 49 | + exit 0 |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Comment on the Best-Matching Issue and Close It |
| 53 | + if: env.issue_number != '' |
| 54 | + env: |
| 55 | + GH_TOKEN: ${{ secrets.PAT_MICHEL }} |
| 56 | + run: | |
| 57 | + gh issue comment $issue_number --repo community-scripts/ProxmoxVED --body "Merged with #${{ github.event.pull_request.number }} in ProxmoxVE" |
| 58 | + gh issue close $issue_number --repo community-scripts/ProxmoxVED |
0 commit comments