-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from shubhagarwal1/main
Add GitHub Workflow for Auto-Closing Similar Issue Requests and autolabeler
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Auto Label Issues and PRs | ||
|
||
on: | ||
issues: | ||
types: [opened] | ||
pull_request_target: # Correct indentation here | ||
types: [opened] | ||
|
||
jobs: | ||
add-labels: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Add labels to new issues | ||
if: github.event_name == 'issues' | ||
uses: actions-ecosystem/action-add-labels@v1 | ||
with: | ||
github_token: ${{ secrets.PAT_TOKEN }} # Use PAT_TOKEN for issues | ||
labels: | | ||
gssoc-ext | ||
hacktoberfest-accepted | ||
- name: Add labels to new pull requests | ||
if: github.event_name == 'pull_request_target' | ||
uses: actions-ecosystem/action-add-labels@v1 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} # Use GITHUB_TOKEN for PRs | ||
labels: | | ||
gssoc-ext | ||
hacktoberfest-accepted |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Check for Duplicate Issues | ||
|
||
on: | ||
issues: | ||
types: [opened] | ||
|
||
jobs: | ||
check_duplicate: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install jq | ||
run: sudo apt-get update && sudo apt-get install -y jq | ||
|
||
- name: Search for existing issues | ||
id: search_issues | ||
run: | | ||
# URL encode the issue title (replace spaces with %20) | ||
issue_title=$(echo "${{ github.event.issue.title }}" | sed 's/ /%20/g') | ||
# Search for issues with a similar title | ||
existing_issues=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
"https://api.github.com/search/issues?q=repo:${{ github.repository }}+type:issue+state:open+${issue_title}") | ||
# Extract issue numbers from the search result | ||
echo "$existing_issues" | jq -r '.items[] | .number' > issue_numbers.txt | ||
- name: Check if a duplicate exists | ||
id: check_duplicate | ||
run: | | ||
issue_count=$(wc -l < issue_numbers.txt) | ||
if [ "$issue_count" -gt 0 ]; then | ||
echo "Duplicate issue(s) found." | ||
exit 0 | ||
else | ||
echo "No duplicates found." | ||
exit 1 | ||
fi | ||
- name: Comment and close the new issue if duplicate exists | ||
if: steps.check_duplicate.outcome == 'success' | ||
run: | | ||
issue_numbers=$(cat issue_numbers.txt | tr '\n' ', ' | sed 's/, $//') | ||
existing_issue=$(head -n 1 issue_numbers.txt) | ||
# Comment on the new issue | ||
curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
-H "Content-Type: application/json" \ | ||
-d "{\"body\": \"Thanks for raising this issue! However, we believe a similar issue already exists. Kindly go through all the open issues and ask to be assigned to that issue.If you believe that your issue is unique , feel free to comment and ask for it to be reopened , or you can also start a discussion regarding the same ! \"}" \ | ||
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" | ||
# Close the new issue | ||
curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
-H "Content-Type: application/json" \ | ||
-d '{"state": "closed"}' \ | ||
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" |