Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.
Open
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 lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const fields = {
staleLabel: Joi.string()
.description('Label to use when marking as stale'),

closedLabel: Joi.alternatives().try(Joi.string(), Joi.boolean().only(false))
.error(() => '"closedLabel" must be a string or false')
.description('Label to use when issue is closed. Set to `false` to disable'),

markComment: Joi.alternatives().try(Joi.string(), Joi.any().only(false))
.error(() => '"markComment" must be a string or false')
.description('Comment to post when marking as stale. Set to `false` to disable'),
Expand All @@ -52,6 +56,7 @@ const schema = Joi.object().keys({
exemptMilestones: fields.exemptMilestones.default(false),
exemptAssignees: fields.exemptMilestones.default(false),
staleLabel: fields.staleLabel.default('wontfix'),
closedLabel: fields.closeComment.default(false),
markComment: fields.markComment.default(
'Is this still relevant? If so, what is blocking it? ' +
'Is there anything you can do to help move it forward?' +
Expand Down
14 changes: 14 additions & 0 deletions lib/stale.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ module.exports = class Stale {
if (closeComment) {
await this.github.issues.createComment({ owner, repo, number, body: closeComment })
}
const closedLabel = this.getConfigValue(type, 'closedLabel')
if (closedLabel && closedLabel.trim().length !== 0) {
await this.ensureClosedLabelExists(type)
this.github.issues.addLabels({ owner, repo, number, labels: [closedLabel] })
}
return this.github.issues.edit({ owner, repo, number, state: 'closed' })
} else {
this.logger.info('%s/%s#%d would have been closed (dry-run)', owner, repo, number)
Expand Down Expand Up @@ -214,6 +219,15 @@ module.exports = class Stale {
})
}

async ensureClosedLabelExists (type) {
const { owner, repo } = this.config
const closedLabel = this.getConfigValue(type, 'closedLabel')

return this.github.issues.getLabel({ owner, repo, name: closedLabel }).catch(() => {
return this.github.issues.createLabel({ owner, repo, name: closedLabel, color: 'E99695' })
})
}

since (days) {
const ttl = days * 24 * 60 * 60 * 1000
let date = new Date(new Date() - ttl)
Expand Down
1 change: 1 addition & 0 deletions test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('schema', () => {
exemptMilestones: false,
exemptAssignees: false,
staleLabel: 'wontfix',
closedLabel: false,
perform: true,
markComment: 'Is this still relevant? If so, what is blocking it? ' +
'Is there anything you can do to help move it forward?' +
Expand Down
22 changes: 11 additions & 11 deletions test/stale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('stale', () => {
test(
'removes the stale label and ignores if it has already been removed',
async () => {
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
const stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })

for (const type of ['pulls', 'issues']) {
try {
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('stale', () => {
test(
'should not close issues if daysUntilClose is configured as false',
async () => {
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
const stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.config.daysUntilClose = false
stale.getStale = jest.fn().mockImplementation(() => Promise.resolve({ data: { items: [] } }))
stale.getClosable = jest.fn()
Expand All @@ -154,7 +154,7 @@ describe('stale', () => {
test(
'should not close issues if the keyword pulls or keyword issues is used, and daysUntilClose is configured as false',
async () => {
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
const stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.config.pulls = { daysUntilClose: false }
stale.config.issues = { daysUntilClose: false }
stale.getStale = jest.fn().mockImplementation(() => Promise.resolve({ data: { items: [] } }))
Expand All @@ -171,7 +171,7 @@ describe('stale', () => {
test(
'should not close issues if only keyword is configured with the pulls value',
async () => {
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
const stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.config.only = 'pulls'
stale.config.daysUntilClose = 1
stale.getStale = jest.fn().mockImplementation(() => Promise.resolve({ data: { items: [] } }))
Expand All @@ -185,7 +185,7 @@ describe('stale', () => {
test(
'should not close pull requests if only keyword is configured with the issues value',
async () => {
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
const stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.config.only = 'issues'
stale.config.daysUntilClose = 1
stale.getStale = jest.fn().mockImplementation(() => Promise.resolve({ data: { items: [] } }))
Expand All @@ -200,7 +200,7 @@ describe('stale', () => {
test(
'should not mark issue if it is already closed',
async () => {
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
const stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.getStale = jest.fn().mockImplementation(() => {
return Promise.resolve({
data: {
Expand All @@ -220,7 +220,7 @@ describe('stale', () => {
test(
'should not mark issue if it is locked',
async () => {
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
const stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.getStale = jest.fn().mockImplementation(() => {
return Promise.resolve({
data: {
Expand All @@ -240,7 +240,7 @@ describe('stale', () => {
test(
'should mark issue if it is open',
async () => {
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
const stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.getStale = jest.fn().mockImplementation(() => {
return Promise.resolve({
data: {
Expand All @@ -263,7 +263,7 @@ describe('stale', () => {
'should not close issue if it is already closed',
async () => {
const staleLabel = 'stale'
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
const stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.config.daysUntilClose = 1
stale.getClosable = jest.fn().mockImplementation(() => {
return Promise.resolve({
Expand All @@ -285,7 +285,7 @@ describe('stale', () => {
'should not close issue if it is locked',
async () => {
const staleLabel = 'stale'
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
const stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.config.daysUntilClose = 1
stale.getClosable = jest.fn().mockImplementation(() => {
return Promise.resolve({
Expand All @@ -307,7 +307,7 @@ describe('stale', () => {
'should close issue if it is open',
async () => {
const staleLabel = 'stale'
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
const stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.config.daysUntilClose = 1
stale.getClosable = jest.fn().mockImplementation(() => {
return Promise.resolve({
Expand Down