Skip to content

Commit

Permalink
Merge pull request #1591 from microsoft/arunchndr-close-nmi
Browse files Browse the repository at this point in the history
Update close-stale-needs-more-info.yml
  • Loading branch information
arunchndr authored Nov 7, 2024
2 parents c081020 + 5236aab commit d4ef44f
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions .github/workflows/close-stale-needs-more-info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
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:
Expand All @@ -27,18 +27,27 @@ jobs:
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 + ', -' + excludedLabel, // Excludes issues with 'enhancement' label
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 to find when the label was added
const events = await github.paginate(github.rest.issues.listEventsForRepo, {
// 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,
Expand All @@ -56,11 +65,11 @@ jobs:
const issueUpdatedDate = new Date(issue.updated_at);
const labelAddedTime = labelAddedDate.getTime();
const issueUpdatedTime = issueUpdatedDate.getTime();
const diffTime = Math.abs(currentDate - labelAddedDate);
const diffTime = currentDate.getTime() - labelAddedTime;
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
// Check if the issue was updated after the label was added and if it has been more than 'staleDays' since the label was added
if (issueUpdatedTime > labelAddedTime && diffDays > staleDays) {
// 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,
Expand All @@ -77,7 +86,7 @@ jobs:
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 updated since the label was applied.`);
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.`);
}
}
}

0 comments on commit d4ef44f

Please sign in to comment.