@@ -11,24 +11,51 @@ jobs:
1111    runs-on : ubuntu-latest 
1212
1313    steps :
14-       - name : Extract PR Title in Lowercase  
14+       - name : Extract and Process PR Title  
1515        id : extract_title 
16-         run : echo "title=$(echo '${{ github.event.pull_request.title }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV 
16+         run : | 
17+           # Strip "New Script:" from the title and convert it to lowercase 
18+           title=$(echo "${{ github.event.pull_request.title }}" | sed 's/^New Script://g' | tr '[:upper:]' '[:lower:]' | sed 's/ //g' | sed 's/-//g') 
19+           echo "Processed Title: $title" 
20+           echo "title=$title" >> $GITHUB_ENV 
1721
18-       - name : Search for Issue  with Matching Title  
22+ name : Search for Issues  with Similar Titles  
1923        id : find_issue 
2024        env :
2125          GH_TOKEN : ${{ secrets.GITHUB_TOKEN }} 
2226        run : | 
23-           ISSUE=$(gh issue list --repo community-scripts/ProxmoxVED --search "$title" --json number --jq '.[0].number') 
24-           if [ -n "$ISSUE" ]; then 
25-             echo "issue_number=$ISSUE" >> $GITHUB_ENV 
27+           # Get all issues in the target repository 
28+           issues=$(gh issue list --repo community-scripts/ProxmoxVED --json number,title --jq '.[] | {number, title}') 
29+            
30+           # Find the issue with the closest match by calculating similarity 
31+           best_match_score=0 
32+           best_match_number=0 
33+            
34+           for issue in $(echo "$issues" | jq -r '. | @base64'); do 
35+             _jq() { 
36+               echo ${issue} | base64 --decode | jq -r ${1} 
37+             } 
38+ 
39+             issue_title=$(_jq '.title' | tr '[:upper:]' '[:lower:]' | sed 's/ //g' | sed 's/-//g') 
40+             issue_number=$(_jq '.number') 
41+              
42+             # Simple scoring: count matching characters (you can extend this logic) 
43+             match_score=$(echo "$title" | grep -o "$issue_title" | wc -l) 
44+              
45+             if [ "$match_score" -gt "$best_match_score" ]; then 
46+               best_match_score=$match_score 
47+               best_match_number=$issue_number 
48+             fi 
49+           done 
50+ 
51+           if [ "$best_match_number" != "0" ]; then 
52+             echo "issue_number=$best_match_number" >> $GITHUB_ENV 
2653          else 
2754            echo "No matching issue found." 
2855            exit 0 
2956          fi 
3057
31- name : Comment on Issue and Close It 
58+ name : Comment on the Best-Matching  Issue and Close It 
3259        if : env.issue_number != '' 
3360        env :
3461          GH_TOKEN : ${{ secrets.GITHUB_TOKEN }} 
0 commit comments