Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2187 from filecoin-project/fix/close-issues-action
Browse files Browse the repository at this point in the history
Set 4 grace days to close issue (for the first 4 days of the new bot). As the bot has been correctly tested, it may be merged into main with no review needed.
  • Loading branch information
clriesco authored Aug 30, 2023
2 parents 4b95fac + b86f899 commit e8b50d0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 66 deletions.
78 changes: 41 additions & 37 deletions .github/scripts/close_inactive/close_stale_issues.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Octokit } from "@octokit/rest";
import fetch from "node-fetch";
import { checkThrottling, getLastComment } from "./utils.mjs";

const DAYS_TO_WAIT = 14;
const DAYS_TO_WAIT = 18; // Changed from 14 to 18 for the first 4 days of the new bot.
const owner = process.env.GITHUB_REPOSITORY.split('/')[0];
const repo = process.env.GITHUB_REPOSITORY.split('/')[1];

Expand Down Expand Up @@ -32,46 +32,50 @@ async function closeStaleIssues() {
dateThreshold.setDate(dateThreshold.getDate() - DAYS_TO_WAIT);

for (let issue of issues) {
await checkThrottling(octokit);

const lastComment = await getLastComment(octokit, owner, repo, issue.number, false);
let updatedAt = lastComment
? new Date(lastComment.created_at)
: new Date(issue.created_at);
try {
await checkThrottling(octokit);

const lastComment = await getLastComment(octokit, owner, repo, issue.number, false);
let updatedAt = lastComment
? new Date(lastComment.created_at)
: new Date(issue.created_at);

// Let's calculate the difference between the two dates
const diffTime = dateThreshold - updatedAt;
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
// Let's calculate the difference between the two dates
const diffTime = dateThreshold - updatedAt;
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));

if (diffDays > 0) {
await octokit.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: `This application has not seen any responses in the last 14 days, so for now it is being closed. Please feel free to contact the Fil+ Gov team to re-open the application if it is still being processed. Thank you!
\n\n
--
Commented by Stale Bot.`
});
// Add stale label.
await octokit.issues.addLabels({
owner,
repo,
issue_number: issue.number,
labels: ['stale']
});
if (diffDays > 0) {
await octokit.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: `This application has not seen any responses in the last 14 days, so for now it is being closed. Please feel free to contact the Fil+ Gov team to re-open the application if it is still being processed. Thank you!
\n\n
--
Commented by Stale Bot.`
});
// Add stale label.
await octokit.issues.addLabels({
owner,
repo,
issue_number: issue.number,
labels: ['stale']
});

// Close issue.
await octokit.issues.update({
owner,
repo,
issue_number: issue.number,
state: 'closed'
});
// Close issue.
await octokit.issues.update({
owner,
repo,
issue_number: issue.number,
state: 'closed'
});

console.log(`Let's close issue ${issue.number}. Last commented ${diffDays} days ago`);
} else {
console.log(`Issue ${issue.number} will remain open. Updated ${diffDays} days ago`);
console.log(`Let's close issue ${issue.number}. Last commented ${diffDays} days from threshold`);
} else {
console.log(`Issue ${issue.number} will remain open. Updated ${diffDays} days from threshold`);
}
} catch (error) {
console.log(`Error in ${issue.number}: ${error.message}`);
}
}
}
Expand Down
57 changes: 31 additions & 26 deletions .github/scripts/close_inactive/notify_stale_issues.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const octokit = new Octokit({
* This function checks the rate limit status and sleeps if the remaining requests are below the limit.
*/
async function checkAndCommentOnIssues() {

await checkThrottling(octokit);

let issues = await octokit.paginate(octokit.issues.listForRepo, {
Expand All @@ -32,35 +33,39 @@ async function checkAndCommentOnIssues() {
dateThreshold.setDate(dateThreshold.getDate() - DAYS_TO_WAIT);

for (let issue of issues) {
await checkThrottling(octokit);
try {
await checkThrottling(octokit);

const lastComment = await getLastComment(octokit, owner, repo, issue.number, true);
if (lastComment &&
lastComment.user.login == 'github-actions[bot]' &&
lastComment.body.includes("Commented by Stale Bot.")
) continue; //Do not comment again if already commented by bot

const updatedAt = lastComment
? new Date(lastComment.created_at)
: new Date(issue.created_at);
const lastComment = await getLastComment(octokit, owner, repo, issue.number, true);
if (lastComment &&
lastComment.user.login == 'github-actions[bot]' &&
lastComment.body.includes("Commented by Stale Bot.")
) continue; //Do not comment again if already commented by bot
const updatedAt = lastComment
? new Date(lastComment.created_at)
: new Date(issue.created_at);

// Let's calculate the difference between the two dates
const diffTime = dateThreshold - updatedAt;
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
// Let's calculate the difference between the two dates
const diffTime = dateThreshold - updatedAt;
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));

if (diffDays > 0) {
await octokit.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: `This application has not seen any responses in the last 10 days. This issue will be marked with Stale label and will be closed in 4 days. Comment if you want to keep this application open.
\n\n
--
Commented by Stale Bot.`
});
console.log(`Stale advice on issue ${issue.number}. Updated ${diffDays} days ago`);
} else {
console.log(`No stale advice on issue ${issue.number}. Updated ${diffDays} days ago`);
if (diffDays > 0) {
await octokit.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: `This application has not seen any responses in the last 10 days. This issue will be marked with Stale label and will be closed in 4 days. Comment if you want to keep this application open.
\n\n
--
Commented by Stale Bot.`
});
console.log(`Stale advice on issue ${issue.number}. Updated ${diffDays} days from threshold`);
} else {
console.log(`No stale advice on issue ${issue.number}. Updated ${diffDays} days from threshold`);
}
} catch (error) {
console.log(`Error in ${issue.number}: ${error.message}`);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/close-inactive.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: 'Close inactive issues'
on:
workflow_dispatch:
#schedule:
# - cron: '0 1 * * *'
#workflow_dispatch:
schedule:
- cron: '0 1 * * *'

jobs:

Expand Down

0 comments on commit e8b50d0

Please sign in to comment.