New Script: Snipe IT #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Close Matching Issue on PR Merge | |
on: | |
pull_request: | |
types: | |
- closed | |
jobs: | |
close_issue: | |
if: github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
steps: | |
- name: Extract and Process PR Title | |
id: extract_title | |
run: | | |
# Strip "New Script:" from the title and convert it to lowercase | |
title=$(echo "${{ github.event.pull_request.title }}" | sed 's/^New Script://g' | tr '[:upper:]' '[:lower:]' | sed 's/ //g' | sed 's/-//g') | |
echo "Processed Title: $title" | |
echo "title=$title" >> $GITHUB_ENV | |
- name: Search for Issues with Similar Titles | |
id: find_issue | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Get all issues in the target repository | |
issues=$(gh issue list --repo community-scripts/ProxmoxVED --json number,title --jq '.[] | {number, title}') | |
# Find the issue with the closest match by calculating similarity | |
best_match_score=0 | |
best_match_number=0 | |
for issue in $(echo "$issues" | jq -r '. | @base64'); do | |
_jq() { | |
echo ${issue} | base64 --decode | jq -r ${1} | |
} | |
issue_title=$(_jq '.title' | tr '[:upper:]' '[:lower:]' | sed 's/ //g' | sed 's/-//g') | |
issue_number=$(_jq '.number') | |
# Simple scoring: count matching characters (you can extend this logic) | |
match_score=$(echo "$title" | grep -o "$issue_title" | wc -l) | |
if [ "$match_score" -gt "$best_match_score" ]; then | |
best_match_score=$match_score | |
best_match_number=$issue_number | |
fi | |
done | |
if [ "$best_match_number" != "0" ]; then | |
echo "issue_number=$best_match_number" >> $GITHUB_ENV | |
else | |
echo "No matching issue found." | |
exit 0 | |
fi | |
- name: Comment on the Best-Matching Issue and Close It | |
if: env.issue_number != '' | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh issue comment $issue_number --repo community-scripts/ProxmoxVED --body "Merged with #${{ github.event.pull_request.number }} in ProxmoxVE" | |
gh issue close $issue_number --repo community-scripts/ProxmoxVED |