@@ -11,24 +11,51 @@ jobs:
11
11
runs-on : ubuntu-latest
12
12
13
13
steps :
14
- - name : Extract PR Title in Lowercase
14
+ - name : Extract and Process PR Title
15
15
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
17
21
18
- - name : Search for Issue with Matching Title
22
+ - name : Search for Issues with Similar Titles
19
23
id : find_issue
20
24
env :
21
25
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
22
26
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
26
53
else
27
54
echo "No matching issue found."
28
55
exit 0
29
56
fi
30
57
31
- - name : Comment on Issue and Close It
58
+ - name : Comment on the Best-Matching Issue and Close It
32
59
if : env.issue_number != ''
33
60
env :
34
61
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments