-
Notifications
You must be signed in to change notification settings - Fork 694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GHA to remove needs-more-info upon receiving a response or close if no response #7745
Open
arunchndr
wants to merge
2
commits into
main
Choose a base branch
from
arunchndr-nmi-remove
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+168
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,92 @@ | ||
name: 'Close Issues with Stale Needs More Info Label' | ||
|
||
on: | ||
schedule: | ||
# Run this workflow at 00:00 every day | ||
- cron: '0 0 * * *' | ||
workflow_dispatch: | ||
|
||
permissions: | ||
issues: write | ||
contents: read | ||
|
||
jobs: | ||
close-stale-issues: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Close Stale Issues with Needs More Info Label and Comment | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const labelName = 'needs-more-info'; | ||
const excludedLabel = 'enhancement'; | ||
const staleDays = 14; | ||
const closingComment = "This issue has been automatically closed due to inactivity and having the 'needs-more-info' label for more than 14 days. If the issue still persists, please reopen the issue with the requested information."; | ||
const currentDate = new Date(); | ||
const staleDaysInMilliseconds = staleDays * 24 * 60 * 60 * 1000; | ||
|
||
// Fetch all open issues with 'needs-more-info' label | ||
const issues = await github.paginate(github.rest.issues.listForRepo, { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: labelName, | ||
state: 'open', | ||
}); | ||
|
||
for (const issue of issues) { | ||
// Skip if the issue has 'enhancement' label | ||
const labels = issue.labels.map(label => label.name); | ||
if (labels.includes(excludedLabel)) { | ||
continue; | ||
} | ||
|
||
let labelAddedDate = null; | ||
|
||
// Fetch events for the issue to find when the label was added | ||
const events = await github.paginate(github.rest.issues.listEvents, { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issue.number, | ||
}); | ||
|
||
// Look for the event where the label was added and capture the date | ||
for (const event of events) { | ||
if (event.event === 'labeled' && event.label.name === labelName) { | ||
labelAddedDate = new Date(event.created_at); | ||
break; | ||
} | ||
} | ||
|
||
if (labelAddedDate) { | ||
const issueUpdatedDate = new Date(issue.updated_at); | ||
const labelAddedTime = labelAddedDate.getTime(); | ||
const issueUpdatedTime = issueUpdatedDate.getTime(); | ||
const diffTime = currentDate.getTime() - labelAddedTime; | ||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); | ||
|
||
// Check if the issue was not updated after the label was added and if it has been more than 'staleDays' since the label was added | ||
if (issueUpdatedTime <= labelAddedTime && diffDays > staleDays) { | ||
// Post a closing comment before closing the issue | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issue.number, | ||
body: closingComment, | ||
}); | ||
|
||
// Close the issue | ||
await github.rest.issues.update({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issue.number, | ||
state: 'closed', | ||
}); | ||
|
||
console.log(`Issue #${issue.number} has been closed with a comment as it has had the '${labelName}' label for more than ${staleDays} days and was not updated since the label was applied.`); | ||
} | ||
} | ||
} |
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,76 @@ | ||
name: 'Remove Needs More Info Label' | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
|
||
permissions: | ||
issues: write | ||
contents: read | ||
|
||
jobs: | ||
debug-and-remove-label: | ||
runs-on: ubuntu-latest | ||
if: github.event.issue.pull_request == null # Ensure it runs only for issue comments | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Remove "needs-more-info" Label and Comment | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const issue = context.payload.issue; | ||
const user = context.payload.sender; | ||
|
||
// Check if the comment was made by the issue creator | ||
if (issue.user.login === user.login) { | ||
const issueNumber = issue.number; | ||
const labelName = 'needs-more-info'; | ||
let labelAddedByUser = ''; | ||
|
||
// Find who added the 'needs-more-info' label | ||
for await (const response of github.paginate.iterator(github.rest.issues.listEvents, { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
})) { | ||
const events = response.data; | ||
const labelEvent = events.find(event => event.event === 'labeled' && event.label.name === labelName); | ||
if (labelEvent) { | ||
labelAddedByUser = labelEvent.actor.login; | ||
break; // Stop at the most recent event that added the label | ||
} | ||
} | ||
|
||
// Get all labels for the issue | ||
const { data: labels } = await github.rest.issues.listLabelsOnIssue({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
}); | ||
|
||
// Check if the issue has the specific label | ||
if (labels.some(label => label.name === labelName)) { | ||
// Remove the label | ||
await github.rest.issues.removeLabel({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
name: labelName, | ||
}); | ||
|
||
// If someone added the label, comment and tag that user | ||
if (labelAddedByUser) { | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
body: `@${labelAddedByUser}, the '${labelName}' label has been removed upon receiving further response from the original bug filer.`, | ||
}); | ||
} | ||
|
||
console.log(`Label "${labelName}" removed from issue #${issueNumber}.`); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been using the 'Needs More Info' label - there are currently no open issues with 'needs-more-info'. I don't mind which one, but we should decide here and delete the other one