From ace8c2d9ab62922bc899025d12f67e7d51706848 Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Thu, 8 Nov 2018 06:37:44 +0100 Subject: [PATCH] feat: support for skipping issues created before a given timestamp --- README.md | 4 ++++ assets/app-description.md | 4 ++++ src/lock.js | 5 +++++ src/schema.js | 8 ++++++++ 4 files changed, 21 insertions(+) diff --git a/README.md b/README.md index c2e3150..f7f2172 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,10 @@ The file can be empty, or it can override any of these default settings: # Number of days of inactivity before a closed issue or pull request is locked daysUntilLock: 365 +# Skip issues and pull requests created before a given timestamp. Timestamp must +# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable. +skipCreatedBefore: false + # Issues and pull requests with these labels will not be locked. Set to `[]` to disable exemptLabels: [] diff --git a/assets/app-description.md b/assets/app-description.md index e68f9a5..646486a 100644 --- a/assets/app-description.md +++ b/assets/app-description.md @@ -18,6 +18,10 @@ Create `.github/lock.yml` in the default branch to enable the app. The file can # Number of days of inactivity before a closed issue or pull request is locked daysUntilLock: 365 +# Skip issues and pull requests created before a given timestamp. Timestamp must +# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable. +skipCreatedBefore: false + # Issues and pull requests with these labels will not be locked. Set to `[]` to disable exemptLabels: [] diff --git a/src/lock.js b/src/lock.js index 1114a84..a110cf1 100644 --- a/src/lock.js +++ b/src/lock.js @@ -62,6 +62,7 @@ module.exports = class Lock { const {owner, repo} = this.context.repo(); const daysUntilLock = this.getConfigValue(type, 'daysUntilLock'); const exemptLabels = this.getConfigValue(type, 'exemptLabels'); + const skipCreatedBeforeTimestamp = this.getConfigValue(type, 'skipCreatedBefore'); const timestamp = this.getUpdatedTimestamp(daysUntilLock); @@ -78,6 +79,10 @@ module.exports = class Lock { query += ' is:pr'; } + if (skipCreatedBeforeTimestamp) { + query += ` created:>${skipCreatedBeforeTimestamp}`; + } + this.log.info({repo: {owner, repo}}, `Searching ${type}`); return this.context.github.search.issues({ q: query, diff --git a/src/schema.js b/src/schema.js index ad5af38..9b45ed6 100644 --- a/src/schema.js +++ b/src/schema.js @@ -7,6 +7,13 @@ const fields = { 'Number of days of inactivity before a closed issue or pull request is locked' ), + skipCreatedBefore: Joi.alternatives() + .try(Joi.string(), Joi.boolean().only(false)) + .description( + 'Skip issues and pull requests created before a given timestamp. Timestamp' + + 'must follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable.' + ), + exemptLabels: Joi.array() .single() .items(Joi.string()) @@ -31,6 +38,7 @@ const fields = { const schema = Joi.object().keys({ daysUntilLock: fields.daysUntilLock.default(365), + skipCreatedBefore: fields.skipCreatedBefore.default(false), exemptLabels: fields.exemptLabels.default([]), lockLabel: fields.lockLabel.default(false), lockComment: fields.lockComment.default(