Skip to content

Commit

Permalink
✨ Delete unnecessary issues automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 19, 2020
1 parent 43988a0 commit 8f75e5b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface UpptimeConfig {
skipDescriptionUpdate?: boolean;
skipTopicsUpdate?: boolean;
skipHomepageUpdate?: boolean;
skipDeleteIssues?: boolean;
commitMessages?: {
readmeContent?: string;
summaryJson?: string;
Expand Down
34 changes: 34 additions & 0 deletions src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,40 @@ export const update = async (shouldCommit = false) => {
}
push();

if (!config.skipDeleteIssues) {
// Find all the opened issues that shouldn't have opened
// Say, Upptime found a down monitor and it was back up within 5 min
const issuesRecentlyClosed = await octokit.issues.listForRepo({
owner,
repo,
state: "closed",
labels: "status",
per_page: 10,
});
console.log("Found recently closed issues", issuesRecentlyClosed.data.length);
for await (const issue of issuesRecentlyClosed.data) {
if (
// If this issue was closed within 15 minutes
new Date(issue.closed_at).getTime() - new Date(issue.created_at).getTime() < 900000 &&
// It has 1 comment (the default Upptime one)
issue.comments === 1
) {
try {
console.log("Trying to delete issue", issue.number, issue.node_id);
const result = await octokit.graphql(`
mutation deleteIssue {
deleteIssue(input:{issueId:"${issue.node_id}"}) {
clientMutationId
}
}`);
console.log("Success", result);
} catch (error) {
console.log("Error deleting this issue", error);
}
}
}
}

if (hasDelta) generateSummary();
};

Expand Down

0 comments on commit 8f75e5b

Please sign in to comment.