Skip to content
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

Close issues with status/needs-feedback that were last updated more than a month ago #108

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ The script will also lock issues and pull requests that have been closed for 3
months. If the issue was commented on in the last two weeks, a comment will be
posted suggesting opening a new issue to continue the discussion.

### Feedback

The script will close issues with the label `status/needs-feedback` if a month
has passed since they were updated.

### Maintainer commands

The script can execute some actions like updating a PR's branch if requested by
Expand Down
28 changes: 28 additions & 0 deletions src/feedback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { addComment, closeIssue, fetchOpenIssuesWithLabel } from "./github.ts";

export const run = async () => {
// get all issues with the label "status/needs-feedback"
const issuesWithStatusNeedsFeedback = await fetchOpenIssuesWithLabel(
"status/needs-feedback",
);
return Promise.all(issuesWithStatusNeedsFeedback.items.map(handleIssue));
};

// close issue if a month has passed since it was last updated
const handleIssue = async (issue: {
number: number;
updated_at: string;
}) => {
const oneMonthAgo = (new Date(Date.now() - 1000 * 60 * 60 * 24 * 30))
.getTime();
if ((new Date(issue.updated_at)).getTime() < oneMonthAgo) {
console.log(`Closing issue #${issue.number} due to feedback timeout`);
await addComment(
issue.number,
`We close issues that need feedback from the author if there were no new comments for a month. :tea:`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems somewhat unfriendly imo.

This issue has the status/needs-feedback label and hasn't received activity in a month or more, so it is being closed. If you feel this was in error (misplaced label or otherwise), please let us know so we can re-evaluate. If you are not the original author, consider opening a new issue linking to this one instead.

Or something along those lines? The current wording seems very strong to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, send a PR to change it

);

// close issue
await closeIssue(issue.number);
}
};
26 changes: 26 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ export const fetchMergedWithLabel = async (label: string) => {
return json;
};

// returns a list of open issues with the given label
export const fetchOpenIssuesWithLabel = async (label: string) => {
const response = await fetch(
`${GITHUB_API}/search/issues?q=` +
encodeURIComponent(
`is:issue is:open label:${label} repo:go-gitea/gitea`,
),
{ headers: HEADERS },
);
const json = await response.json();
return json;
};

// returns a list of PRs pending merge (have the label reviewed/wait-merge)
export const fetchPendingMerge = async () => {
const response = await fetch(
Expand Down Expand Up @@ -476,3 +489,16 @@ export const fetchLastComment = async (issueNumber: number) => {
if (!json.length) return null;
return json[0];
};

// closes the given issue
export const closeIssue = async (issueNumber: number) => {
const response = await fetch(
`${GITHUB_API}/repos/go-gitea/gitea/issues/${issueNumber}`,
{
method: "PATCH",
headers: HEADERS,
body: JSON.stringify({ state: "closed" }),
},
);
return response.json();
};
4 changes: 3 additions & 1 deletion src/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as lgtm from "./lgtm.ts";
import * as comments from "./comments.ts";
import * as lock from "./lock.ts";
import * as prActions from "./prActions.ts";
import * as feedback from "./feedback.ts";

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

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

// we should take this opportunity to run the label, merge queue, and lock maintenance
// we should take this opportunity to run the label, merge queue, lock, and feedback maintenance
labels.run();
mergeQueue.run();
lock.run();
feedback.run();
});

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