Skip to content

Commit 53b6320

Browse files
author
dessant
committed
fix: apply stricter config validation
1 parent 7ee7d4b commit 53b6320

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ daysUntilLock: 365
4343
# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable
4444
skipCreatedBefore: false
4545

46-
# Issues and pull requests with these labels will not be locked. Set to `[]` to disable
46+
# Issues and pull requests with these labels will be ignored. Set to `[]` to disable
4747
exemptLabels: []
4848

4949
# Label to add before locking, such as `outdated`. Set to `false` to disable

assets/app-description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ daysUntilLock: 365
2424
# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable
2525
skipCreatedBefore: false
2626

27-
# Issues and pull requests with these labels will not be locked. Set to `[]` to disable
27+
# Issues and pull requests with these labels will be ignored. Set to `[]` to disable
2828
exemptLabels: []
2929

3030
# Label to add before locking, such as `outdated`. Set to `false` to disable

src/lock.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module.exports = class Lock {
7676
}
7777

7878
if (skipCreatedBefore) {
79-
query += ` created:>${skipCreatedBefore}`;
79+
query += ` created:>${this.getISOTimestamp(skipCreatedBefore)}`;
8080
}
8181

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

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

100100
getUpdatedTimestamp(days) {
101101
const ttl = days * 24 * 60 * 60 * 1000;
102102
const date = new Date(new Date() - ttl);
103-
return date.toISOString().replace(/\.\d{3}\w$/, '');
103+
return this.getISOTimestamp(date);
104+
}
105+
106+
getISOTimestamp(date) {
107+
return date.toISOString().split('.')[0] + 'Z';
104108
}
105109

106110
getConfigValue(type, key) {

src/schema.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,47 @@ const fields = {
99
),
1010

1111
skipCreatedBefore: Joi.alternatives()
12-
.try(Joi.string(), Joi.boolean().only(false))
12+
.try(
13+
Joi.date()
14+
.iso()
15+
.min('1970-01-01T00:00:00Z')
16+
.max('2970-12-31T23:59:59Z'),
17+
Joi.boolean().only(false)
18+
)
1319
.description(
1420
'Skip issues and pull requests created before a given timestamp. Timestamp ' +
1521
'must follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable'
1622
),
1723

1824
exemptLabels: Joi.array()
1925
.single()
20-
.items(Joi.string())
26+
.items(
27+
Joi.string()
28+
.trim()
29+
.max(50)
30+
)
2131
.description(
2232
'Issues and pull requests with these labels will not be locked. Set to `[]` to disable'
2333
),
2434

2535
lockLabel: Joi.alternatives()
26-
.try(Joi.string(), Joi.boolean().only(false))
36+
.try(
37+
Joi.string()
38+
.trim()
39+
.max(50),
40+
Joi.boolean().only(false)
41+
)
2742
.description(
2843
'Label to add before locking, such as `outdated`. Set to `false` to disable'
2944
),
3045

3146
lockComment: Joi.alternatives()
32-
.try(Joi.string(), Joi.boolean().only(false))
47+
.try(
48+
Joi.string()
49+
.trim()
50+
.max(10000),
51+
Joi.boolean().only(false)
52+
)
3353
.description('Comment to post before locking. Set to `false` to disable'),
3454

3555
setLockReason: Joi.boolean().description(
@@ -49,11 +69,15 @@ const schema = Joi.object().keys({
4969
),
5070
setLockReason: fields.setLockReason.default(true),
5171
only: Joi.string()
72+
.trim()
5273
.valid('issues', 'pulls')
5374
.description('Limit to only `issues` or `pulls`'),
5475
pulls: Joi.object().keys(fields),
5576
issues: Joi.object().keys(fields),
56-
_extends: Joi.string().description('Repository to extend settings from'),
77+
_extends: Joi.string()
78+
.trim()
79+
.max(260)
80+
.description('Repository to extend settings from'),
5781
perform: Joi.boolean().default(!process.env.DRY_RUN)
5882
});
5983

0 commit comments

Comments
 (0)