From c340d63e771b662839768e93344a79a2ea85534a Mon Sep 17 00:00:00 2001 From: OllisGit Date: Fri, 15 Jan 2021 22:18:23 +0100 Subject: [PATCH 1/3] added closedLabel feature --- lib/schema.js | 8 ++++++++ lib/stale.js | 31 ++++++++++++++++++++++++++++++- package.json | 6 +++--- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/schema.js b/lib/schema.js index d0586a7..e2f78d5 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -26,6 +26,12 @@ const fields = { staleLabel: Joi.string() .description('Label to use when marking as stale'), + // closedLabel: Joi.string() + // .description('Label to use when clsoing an issue'), + 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'), @@ -52,6 +58,8 @@ const schema = Joi.object().keys({ exemptMilestones: fields.exemptMilestones.default(false), exemptAssignees: fields.exemptMilestones.default(false), staleLabel: fields.staleLabel.default('wontfix'), + // closedLabel: fields.closedLabel.default('closedByBot'), + 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?' + diff --git a/lib/stale.js b/lib/stale.js index 0c13b8d..a379a46 100644 --- a/lib/stale.js +++ b/lib/stale.js @@ -36,6 +36,7 @@ module.exports = class Stale { await this.sweep(type) } + // Mark an issue async mark (type) { await this.ensureStaleLabelExists(type) @@ -48,6 +49,19 @@ module.exports = class Stale { ) } + + async closeDriver (issue) { + + this.remainingActions = 30 + + this.close('issue', issue) + // const closableItems = (await this.getClosable(type)).data.items + // const closableItems = [issue] + + + } + + // Sweep an issue async sweep (type) { const { owner, repo } = this.config const daysUntilClose = this.getConfigValue(type, 'daysUntilClose') @@ -155,7 +169,13 @@ module.exports = class Stale { if (closeComment) { await this.github.issues.createComment({ owner, repo, number, body: closeComment }) } - return this.github.issues.edit({ owner, repo, number, state: 'closed' }) + 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.update({ owner, repo, number, state: 'closed' }) } else { this.logger.info('%s/%s#%d would have been closed (dry-run)', owner, repo, number) } @@ -214,6 +234,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) diff --git a/package.json b/package.json index 7e1614c..d196ac6 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,17 @@ { - "name": "probot-stale", + "name": "ollis-probot-stale", "version": "1.1.0", "description": "A GitHub App built with Probot that closes abandoned Issues and Pull Requests after a period of inactivity.", "author": "Brandon Keepers", "license": "ISC", "homepage": "https://probot.github.io/apps/stale/", - "bugs": "https://github.com/probot/stale/issues", + "bugs": "https://github.com/OllisGit/stale/issues", "keywords": [ "probot", "github", "probot-app" ], - "repository": "https://github.com/probot/stale", + "repository": "https://github.com/OllisGit/stale", "scripts": { "start": "probot run ./index.js", "test": "jest && standard" From ca7b82bc6da9181994c44b2320ffebfcada32080 Mon Sep 17 00:00:00 2001 From: OllisGit Date: Sat, 16 Jan 2021 17:17:24 +0100 Subject: [PATCH 2/3] Cleanup some stuff --- lib/schema.js | 3 --- lib/stale.js | 15 +-------------- package.json | 6 +++--- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/lib/schema.js b/lib/schema.js index e2f78d5..d7ba6dd 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -26,8 +26,6 @@ const fields = { staleLabel: Joi.string() .description('Label to use when marking as stale'), - // closedLabel: Joi.string() - // .description('Label to use when clsoing an issue'), 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'), @@ -58,7 +56,6 @@ const schema = Joi.object().keys({ exemptMilestones: fields.exemptMilestones.default(false), exemptAssignees: fields.exemptMilestones.default(false), staleLabel: fields.staleLabel.default('wontfix'), - // closedLabel: fields.closedLabel.default('closedByBot'), closedLabel: fields.closeComment.default(false), markComment: fields.markComment.default( 'Is this still relevant? If so, what is blocking it? ' + diff --git a/lib/stale.js b/lib/stale.js index a379a46..0f5dd39 100644 --- a/lib/stale.js +++ b/lib/stale.js @@ -36,7 +36,6 @@ module.exports = class Stale { await this.sweep(type) } - // Mark an issue async mark (type) { await this.ensureStaleLabelExists(type) @@ -49,19 +48,6 @@ module.exports = class Stale { ) } - - async closeDriver (issue) { - - this.remainingActions = 30 - - this.close('issue', issue) - // const closableItems = (await this.getClosable(type)).data.items - // const closableItems = [issue] - - - } - - // Sweep an issue async sweep (type) { const { owner, repo } = this.config const daysUntilClose = this.getConfigValue(type, 'daysUntilClose') @@ -169,6 +155,7 @@ 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) diff --git a/package.json b/package.json index d196ac6..7e1614c 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,17 @@ { - "name": "ollis-probot-stale", + "name": "probot-stale", "version": "1.1.0", "description": "A GitHub App built with Probot that closes abandoned Issues and Pull Requests after a period of inactivity.", "author": "Brandon Keepers", "license": "ISC", "homepage": "https://probot.github.io/apps/stale/", - "bugs": "https://github.com/OllisGit/stale/issues", + "bugs": "https://github.com/probot/stale/issues", "keywords": [ "probot", "github", "probot-app" ], - "repository": "https://github.com/OllisGit/stale", + "repository": "https://github.com/probot/stale", "scripts": { "start": "probot run ./index.js", "test": "jest && standard" From 64397dbcfa019bd876113fd4caf8c19cbb699222 Mon Sep 17 00:00:00 2001 From: OllisGit Date: Sun, 17 Jan 2021 10:42:06 +0100 Subject: [PATCH 3/3] fixed tests and executed standard --fix --- lib/schema.js | 2 +- lib/stale.js | 6 ++---- test/schema.test.js | 1 + test/stale.test.js | 22 +++++++++++----------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/schema.js b/lib/schema.js index d7ba6dd..3c718c3 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -29,7 +29,7 @@ const fields = { 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'), diff --git a/lib/stale.js b/lib/stale.js index 0f5dd39..9d0e154 100644 --- a/lib/stale.js +++ b/lib/stale.js @@ -155,14 +155,12 @@ 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){ + if (closedLabel && closedLabel.trim().length !== 0) { await this.ensureClosedLabelExists(type) this.github.issues.addLabels({ owner, repo, number, labels: [closedLabel] }) } - - return this.github.issues.update({ owner, repo, number, state: 'closed' }) + 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) } diff --git a/test/schema.test.js b/test/schema.test.js index 10ea3d3..0d97c2f 100644 --- a/test/schema.test.js +++ b/test/schema.test.js @@ -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?' + diff --git a/test/stale.test.js b/test/stale.test.js index aedf1e6..8d0b591 100644 --- a/test/stale.test.js +++ b/test/stale.test.js @@ -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 { @@ -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() @@ -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: [] } })) @@ -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: [] } })) @@ -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: [] } })) @@ -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: { @@ -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: { @@ -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: { @@ -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({ @@ -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({ @@ -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({