Skip to content

Commit aab91a4

Browse files
Close issues with status/needs-feedback that were last updated more than a month ago (#108)
* Close issues with `status/needs-feedback` that were last updated more than a month ago We will close issues with the label `status/needs-feedback` if there is no new activity in the past month. Co-authored-by: silverwind <[email protected]>
1 parent cd9cf57 commit aab91a4

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ The script will also lock issues and pull requests that have been closed for 3
6262
months. If the issue was commented on in the last two weeks, a comment will be
6363
posted suggesting opening a new issue to continue the discussion.
6464

65+
### Feedback
66+
67+
The script will close issues with the label `status/needs-feedback` if a month
68+
has passed since they were updated.
69+
6570
### Maintainer commands
6671

6772
The script can execute some actions like updating a PR's branch if requested by

src/feedback.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { addComment, closeIssue, fetchOpenIssuesWithLabel } from "./github.ts";
2+
3+
export const run = async () => {
4+
// get all issues with the label "status/needs-feedback"
5+
const issuesWithStatusNeedsFeedback = await fetchOpenIssuesWithLabel(
6+
"status/needs-feedback",
7+
);
8+
return Promise.all(issuesWithStatusNeedsFeedback.items.map(handleIssue));
9+
};
10+
11+
// close issue if a month has passed since it was last updated
12+
const handleIssue = async (issue: {
13+
number: number;
14+
updated_at: string;
15+
}) => {
16+
const oneMonthAgo = (new Date(Date.now() - 1000 * 60 * 60 * 24 * 30))
17+
.getTime();
18+
if ((new Date(issue.updated_at)).getTime() < oneMonthAgo) {
19+
console.log(`Closing issue #${issue.number} due to feedback timeout`);
20+
await addComment(
21+
issue.number,
22+
`We close issues that need feedback from the author if there were no new comments for a month. :tea:`,
23+
);
24+
25+
// close issue
26+
await closeIssue(issue.number);
27+
}
28+
};

src/github.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ export const fetchMergedWithLabel = async (label: string) => {
4040
return json;
4141
};
4242

43+
// returns a list of open issues with the given label
44+
export const fetchOpenIssuesWithLabel = async (label: string) => {
45+
const response = await fetch(
46+
`${GITHUB_API}/search/issues?q=` +
47+
encodeURIComponent(
48+
`is:issue is:open label:${label} repo:go-gitea/gitea`,
49+
),
50+
{ headers: HEADERS },
51+
);
52+
const json = await response.json();
53+
return json;
54+
};
55+
4356
// returns a list of PRs pending merge (have the label reviewed/wait-merge)
4457
export const fetchPendingMerge = async () => {
4558
const response = await fetch(
@@ -476,3 +489,16 @@ export const fetchLastComment = async (issueNumber: number) => {
476489
if (!json.length) return null;
477490
return json[0];
478491
};
492+
493+
// closes the given issue
494+
export const closeIssue = async (issueNumber: number) => {
495+
const response = await fetch(
496+
`${GITHUB_API}/repos/go-gitea/gitea/issues/${issueNumber}`,
497+
{
498+
method: "PATCH",
499+
headers: HEADERS,
500+
body: JSON.stringify({ state: "closed" }),
501+
},
502+
);
503+
return response.json();
504+
};

src/webhook.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as lgtm from "./lgtm.ts";
99
import * as comments from "./comments.ts";
1010
import * as lock from "./lock.ts";
1111
import * as prActions from "./prActions.ts";
12+
import * as feedback from "./feedback.ts";
1213

1314
const secret = Deno.env.get("BACKPORTER_GITHUB_SECRET");
1415

@@ -31,10 +32,11 @@ webhook.on("push", ({ payload }) => {
3132
backport.run();
3233
}
3334

34-
// we should take this opportunity to run the label, merge queue, and lock maintenance
35+
// we should take this opportunity to run the label, merge queue, lock, and feedback maintenance
3536
labels.run();
3637
mergeQueue.run();
3738
lock.run();
39+
feedback.run();
3840
});
3941

4042
// on pull request labeling events, run the label and merge queue maintenance

0 commit comments

Comments
 (0)