Skip to content

Commit

Permalink
fix: apply stricter config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Jan 19, 2019
1 parent 7ee7d4b commit 53b6320
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ daysUntilLock: 365
# 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
# Issues and pull requests with these labels will be ignored. Set to `[]` to disable
exemptLabels: []

# Label to add before locking, such as `outdated`. Set to `false` to disable
Expand Down
2 changes: 1 addition & 1 deletion assets/app-description.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ daysUntilLock: 365
# 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
# Issues and pull requests with these labels will be ignored. Set to `[]` to disable
exemptLabels: []

# Label to add before locking, such as `outdated`. Set to `false` to disable
Expand Down
10 changes: 7 additions & 3 deletions src/lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = class Lock {
}

if (skipCreatedBefore) {
query += ` created:>${skipCreatedBefore}`;
query += ` created:>${this.getISOTimestamp(skipCreatedBefore)}`;
}

if (type === 'issues') {
Expand All @@ -93,14 +93,18 @@ module.exports = class Lock {
per_page: 30
})).data.items;

// `is:unlocked` search qualifier is undocumented, skip wrong results
// `is:unlocked` search qualifier is undocumented, skip locked issues
return results.filter(issue => !issue.locked);
}

getUpdatedTimestamp(days) {
const ttl = days * 24 * 60 * 60 * 1000;
const date = new Date(new Date() - ttl);
return date.toISOString().replace(/\.\d{3}\w$/, '');
return this.getISOTimestamp(date);
}

getISOTimestamp(date) {
return date.toISOString().split('.')[0] + 'Z';
}

getConfigValue(type, key) {
Expand Down
34 changes: 29 additions & 5 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,47 @@ const fields = {
),

skipCreatedBefore: Joi.alternatives()
.try(Joi.string(), Joi.boolean().only(false))
.try(
Joi.date()
.iso()
.min('1970-01-01T00:00:00Z')
.max('2970-12-31T23:59:59Z'),
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())
.items(
Joi.string()
.trim()
.max(50)
)
.description(
'Issues and pull requests with these labels will not be locked. Set to `[]` to disable'
),

lockLabel: Joi.alternatives()
.try(Joi.string(), Joi.boolean().only(false))
.try(
Joi.string()
.trim()
.max(50),
Joi.boolean().only(false)
)
.description(
'Label to add before locking, such as `outdated`. Set to `false` to disable'
),

lockComment: Joi.alternatives()
.try(Joi.string(), Joi.boolean().only(false))
.try(
Joi.string()
.trim()
.max(10000),
Joi.boolean().only(false)
)
.description('Comment to post before locking. Set to `false` to disable'),

setLockReason: Joi.boolean().description(
Expand All @@ -49,11 +69,15 @@ const schema = Joi.object().keys({
),
setLockReason: fields.setLockReason.default(true),
only: Joi.string()
.trim()
.valid('issues', 'pulls')
.description('Limit to only `issues` or `pulls`'),
pulls: Joi.object().keys(fields),
issues: Joi.object().keys(fields),
_extends: Joi.string().description('Repository to extend settings from'),
_extends: Joi.string()
.trim()
.max(260)
.description('Repository to extend settings from'),
perform: Joi.boolean().default(!process.env.DRY_RUN)
});

Expand Down

0 comments on commit 53b6320

Please sign in to comment.