-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close issues when inactive for long period of time
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// @flow | ||
|
||
import github from '../../github'; | ||
import Logger from '../../logger'; | ||
|
||
const { log } = new Logger('issues/closing.js'); | ||
|
||
type ClosingIssuesPayload = { | ||
repository: { | ||
owner: { login: string; }; | ||
name: string; | ||
} | ||
} | ||
|
||
const closingIssueMessage = "Closing this issue because it has been inactive for a long period of time."; | ||
|
||
const isInactive = updatedAt => { | ||
const idleTime = 30 * 24 * 60 * 60 * 1000; | ||
const currentDate = new Date(); | ||
const updateDate = new Date(updatedAt); | ||
return currentDate - updateDate > idleTime; | ||
} | ||
|
||
export default function({ repository }: ClosingIssuesPayload) { | ||
const { owner: { login: owner }, name: repo } = repository; | ||
|
||
github.getLabeledIssues({ | ||
labels: encodeURIComponent("Needs Info"), | ||
owner: owner, | ||
repo: repo | ||
}).then(issues => { | ||
issues.forEach(({ pull_request, number, updated_at }) => { | ||
if (!pull_request && isInactive(updated_at)) { | ||
log(`Adding comment to issue #${number}`, 'verbose'); | ||
github.addIssueComment( | ||
number, | ||
owner, | ||
repo, | ||
closingIssueMessage | ||
).then(res => { | ||
log(`Closing issue #${number}`, 'verbose') | ||
return github.closeIssue({ | ||
id: number, | ||
owner: owner, | ||
repo: repo | ||
}); | ||
}).catch(err => { | ||
log(`Failed closing issue ${number}. Details: ${err.message}`); | ||
}); | ||
} | ||
}) | ||
}); | ||
} |