Skip to content

Commit e4ca979

Browse files
committed
in progress: v6 release
1 parent 92b8e7d commit e4ca979

10 files changed

Lines changed: 974 additions & 32 deletions

File tree

src/github.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,21 @@ export async function reopenIssue(issue: number, token: string) {
138138
});
139139
}
140140

141-
function getIssueLabelDate(timeline: Timeline, label: string) {
141+
export function getIssueLabelDate(timeline: Timeline, label: string) {
142142
// Return when the label was last applied
143-
return timeline.reduce((p, c) => {
144-
if (c.updated_at && c.label?.name === label) {
145-
if (Date.parse(c.updated_at) > p) {
146-
return Date.parse(c.updated_at);
143+
return timeline
144+
.filter(te => te.event === 'labeled')
145+
.reduce((p, c) => {
146+
if (c.updated_at && c.label?.name === label) {
147+
if (Date.parse(c.updated_at) > p) {
148+
return Date.parse(c.updated_at);
149+
} else {
150+
return p;
151+
}
147152
} else {
148153
return p;
149154
}
150-
} else {
151-
return p;
152-
}
153-
}, 0);
155+
}, 0);
154156
}
155157

156158
export function issueDateCompare(issueDate: string, configuredDays: number) {

test/bin/normalize.mjs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,27 @@ export async function normalizeFixtures(fixtureDirectory) {
4141
fixtureObject.original_path = file;
4242
return fixtureObject;
4343
})
44-
);
44+
).catch(e => {
45+
process.exitCode = 1;
46+
console.error(e);
47+
});
4548

4649
// Run octokit's normalization and write back
47-
await Promise.all(
48-
fixtureContents.map(async fixture => {
49-
for (const fixtureKey in fixture) {
50-
// skip original path, this is just for us
51-
if (fixtureKey === 'original_path') continue;
50+
if (fixtureContents) {
51+
await Promise.all(
52+
fixtureContents.map(async fixture => {
53+
for (const fixtureKey in fixture) {
54+
// skip original path, this is just for us
55+
if (fixtureKey === 'original_path') continue;
5256

53-
const normalized = await normalize('test', fixture[fixtureKey]);
54-
// while octokit's normalization requires request headers, if we include them our nocks won't match
55-
delete normalized.reqheaders;
56-
delete fixture[fixtureKey];
57-
fixture[fixtureKey] = normalized;
58-
}
59-
await fs.writeFile(fixture.original_path, JSON.stringify(fixture, null, 2), { encoding: 'utf-8' });
60-
})
61-
);
57+
const normalized = await normalize({ commitSha: {}, ids: {} }, fixture[fixtureKey]);
58+
// while octokit's normalization requires request headers, if we include them our nocks won't match
59+
delete normalized.reqheaders;
60+
delete fixture[fixtureKey];
61+
fixture[fixtureKey] = normalized;
62+
}
63+
await fs.writeFile(fixture.original_path, JSON.stringify(fixture, null, 2), { encoding: 'utf-8' });
64+
})
65+
);
66+
}
6267
}

test/data/timeline.json

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
[
2+
{
3+
"id": 3504742193,
4+
"node_id": "MDEyOkxhYmVsZWRFdmVudDM1MDQ3NDIxOTM=",
5+
"url": "https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/events/3504742193",
6+
"actor": {
7+
"login": "kellertk",
8+
"id": 1083460,
9+
"node_id": "MDQ6VXNlcjEwODM0NjA=",
10+
"avatar_url": "https://avatars.githubusercontent.com/u/1083460?v=4",
11+
"gravatar_id": "",
12+
"url": "https://api.github.com/users/kellertk",
13+
"html_url": "https://github.com/kellertk",
14+
"followers_url": "https://api.github.com/users/kellertk/followers",
15+
"following_url": "https://api.github.com/users/kellertk/following{/other_user}",
16+
"gists_url": "https://api.github.com/users/kellertk/gists{/gist_id}",
17+
"starred_url": "https://api.github.com/users/kellertk/starred{/owner}{/repo}",
18+
"subscriptions_url": "https://api.github.com/users/kellertk/subscriptions",
19+
"organizations_url": "https://api.github.com/users/kellertk/orgs",
20+
"repos_url": "https://api.github.com/users/kellertk/repos",
21+
"events_url": "https://api.github.com/users/kellertk/events{/privacy}",
22+
"received_events_url": "https://api.github.com/users/kellertk/received_events",
23+
"type": "User",
24+
"site_admin": false
25+
},
26+
"event": "labeled",
27+
"commit_id": null,
28+
"commit_url": null,
29+
"created_at": "2020-07-02T00:23:09Z",
30+
"label": {
31+
"name": "enhancement",
32+
"color": "a2eeef"
33+
},
34+
"performed_via_github_app": null
35+
},
36+
{
37+
"url": "https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/comments/652710305",
38+
"html_url": "https://github.com/aws-actions/stale-issue-cleanup/issues/38#issuecomment-652710305",
39+
"issue_url": "https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/38",
40+
"id": 652710305,
41+
"node_id": "MDEyOklzc3VlQ29tbWVudDY1MjcxMDMwNQ==",
42+
"user": {
43+
"login": "kellertk",
44+
"id": 1083460,
45+
"node_id": "MDQ6VXNlcjEwODM0NjA=",
46+
"avatar_url": "https://avatars.githubusercontent.com/u/1083460?v=4",
47+
"gravatar_id": "",
48+
"url": "https://api.github.com/users/kellertk",
49+
"html_url": "https://github.com/kellertk",
50+
"followers_url": "https://api.github.com/users/kellertk/followers",
51+
"following_url": "https://api.github.com/users/kellertk/following{/other_user}",
52+
"gists_url": "https://api.github.com/users/kellertk/gists{/gist_id}",
53+
"starred_url": "https://api.github.com/users/kellertk/starred{/owner}{/repo}",
54+
"subscriptions_url": "https://api.github.com/users/kellertk/subscriptions",
55+
"organizations_url": "https://api.github.com/users/kellertk/orgs",
56+
"repos_url": "https://api.github.com/users/kellertk/repos",
57+
"events_url": "https://api.github.com/users/kellertk/events{/privacy}",
58+
"received_events_url": "https://api.github.com/users/kellertk/received_events",
59+
"type": "User",
60+
"site_admin": false
61+
},
62+
"created_at": "2020-07-02T00:26:11Z",
63+
"updated_at": "2020-07-02T00:26:11Z",
64+
"author_association": "CONTRIBUTOR",
65+
"body": "I suppose that would depend on how verbose you wanted your bot to be. Our thought this this was the bot should warn that it's going to do a thing, then do that thing, and that would be the end of it. This is what we planned:\r\n\r\n`10` You (a human) add a `response-requested` label.\r\n`20` After a configurable time, the bot posts a reminder message to customers, and adds a `closing-soon` label.\r\n`30` IF a response is received on the issue, the bot removes the `response-requested` label, GOTO 10, ELSE GOTO 40\r\n`40` After a configurable amount of time, the bot removes the `closing-soon` label and closes out the issue. It also adds a `closed-for-staleness` label so people know why it was closed.\r\n\r\nOur thought was that adding an additional closure message at end was redundant. There are some changes in the way you handle this that might make this read smoother, at least in the way we had intended for the bot to be used:\r\n\r\n* Change your stale-issue-message to better explain that the thread is going to be automatically closed. For example, take a look at [aws/aws-sdk-java's messaging](https://github.com/aws/aws-sdk-java/blob/master/.github/workflows/stale-issue.yml), or [aws/aws-sdk-cpp's messaging](https://github.com/aws/aws-sdk-cpp/blob/master/.github/workflows/stale_issue.yml).\r\n* Don't add `response-requested` labels unless you're actually requesting a response. In the issue you linked, it isn't clear what you're asking the customer to provide on the last response there: we had originally intended `response-requested` to be only used alongside you asking a question. For the linked issue, it might read better if you were to have closed the issue manually after [this comment](https://github.com/aws/aws-sdk-js/issues/3299#issuecomment-645127228), or said something like \"We'll leave this open for now, let us know how it goes\"\r\n* Consider changing the name of your `closed-for-staleness` label to better communicate what had happened. Perhaps something like `auto-closed` would work?\r\n\r\nIf you'd like to add the extra messaging I'd accept a PR for it, but for now we don't intend to make any changes",
66+
"reactions": {
67+
"url": "https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/comments/652710305/reactions",
68+
"total_count": 0,
69+
"+1": 0,
70+
"-1": 0,
71+
"laugh": 0,
72+
"hooray": 0,
73+
"confused": 0,
74+
"heart": 0,
75+
"rocket": 0,
76+
"eyes": 0
77+
},
78+
"performed_via_github_app": null,
79+
"event": "commented",
80+
"actor": {
81+
"login": "kellertk",
82+
"id": 1083460,
83+
"node_id": "MDQ6VXNlcjEwODM0NjA=",
84+
"avatar_url": "https://avatars.githubusercontent.com/u/1083460?v=4",
85+
"gravatar_id": "",
86+
"url": "https://api.github.com/users/kellertk",
87+
"html_url": "https://github.com/kellertk",
88+
"followers_url": "https://api.github.com/users/kellertk/followers",
89+
"following_url": "https://api.github.com/users/kellertk/following{/other_user}",
90+
"gists_url": "https://api.github.com/users/kellertk/gists{/gist_id}",
91+
"starred_url": "https://api.github.com/users/kellertk/starred{/owner}{/repo}",
92+
"subscriptions_url": "https://api.github.com/users/kellertk/subscriptions",
93+
"organizations_url": "https://api.github.com/users/kellertk/orgs",
94+
"repos_url": "https://api.github.com/users/kellertk/repos",
95+
"events_url": "https://api.github.com/users/kellertk/events{/privacy}",
96+
"received_events_url": "https://api.github.com/users/kellertk/received_events",
97+
"type": "User",
98+
"site_admin": false
99+
}
100+
},
101+
{
102+
"id": 3504749386,
103+
"node_id": "MDEyOkxhYmVsZWRFdmVudDM1MDQ3NDkzODY=",
104+
"url": "https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/events/3504749386",
105+
"actor": {
106+
"login": "kellertk",
107+
"id": 1083460,
108+
"node_id": "MDQ6VXNlcjEwODM0NjA=",
109+
"avatar_url": "https://avatars.githubusercontent.com/u/1083460?v=4",
110+
"gravatar_id": "",
111+
"url": "https://api.github.com/users/kellertk",
112+
"html_url": "https://github.com/kellertk",
113+
"followers_url": "https://api.github.com/users/kellertk/followers",
114+
"following_url": "https://api.github.com/users/kellertk/following{/other_user}",
115+
"gists_url": "https://api.github.com/users/kellertk/gists{/gist_id}",
116+
"starred_url": "https://api.github.com/users/kellertk/starred{/owner}{/repo}",
117+
"subscriptions_url": "https://api.github.com/users/kellertk/subscriptions",
118+
"organizations_url": "https://api.github.com/users/kellertk/orgs",
119+
"repos_url": "https://api.github.com/users/kellertk/repos",
120+
"events_url": "https://api.github.com/users/kellertk/events{/privacy}",
121+
"received_events_url": "https://api.github.com/users/kellertk/received_events",
122+
"type": "User",
123+
"site_admin": false
124+
},
125+
"event": "labeled",
126+
"commit_id": null,
127+
"commit_url": null,
128+
"created_at": "2020-07-02T00:26:23Z",
129+
"label": {
130+
"name": "wontfix",
131+
"color": "ffffff"
132+
},
133+
"performed_via_github_app": null
134+
},
135+
{
136+
"id": 3504749502,
137+
"node_id": "MDExOkNsb3NlZEV2ZW50MzUwNDc0OTUwMg==",
138+
"url": "https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/events/3504749502",
139+
"actor": {
140+
"login": "kellertk",
141+
"id": 1083460,
142+
"node_id": "MDQ6VXNlcjEwODM0NjA=",
143+
"avatar_url": "https://avatars.githubusercontent.com/u/1083460?v=4",
144+
"gravatar_id": "",
145+
"url": "https://api.github.com/users/kellertk",
146+
"html_url": "https://github.com/kellertk",
147+
"followers_url": "https://api.github.com/users/kellertk/followers",
148+
"following_url": "https://api.github.com/users/kellertk/following{/other_user}",
149+
"gists_url": "https://api.github.com/users/kellertk/gists{/gist_id}",
150+
"starred_url": "https://api.github.com/users/kellertk/starred{/owner}{/repo}",
151+
"subscriptions_url": "https://api.github.com/users/kellertk/subscriptions",
152+
"organizations_url": "https://api.github.com/users/kellertk/orgs",
153+
"repos_url": "https://api.github.com/users/kellertk/repos",
154+
"events_url": "https://api.github.com/users/kellertk/events{/privacy}",
155+
"received_events_url": "https://api.github.com/users/kellertk/received_events",
156+
"type": "User",
157+
"site_admin": false
158+
},
159+
"event": "closed",
160+
"commit_id": null,
161+
"commit_url": null,
162+
"created_at": "2020-07-02T00:26:26Z",
163+
"performed_via_github_app": null
164+
}
165+
]

test/fixtures/add-label.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[
2+
{
3+
"scope": "https://api.github.com:443",
4+
"method": "POST",
5+
"path": "/repos/kellertk/aws-github-test/issues/1/labels",
6+
"body": {
7+
"labels": [
8+
"bug",
9+
"documentation",
10+
"duplicate"
11+
]
12+
},
13+
"status": 200,
14+
"response": [
15+
"1f8b0800000000000003add2c14a03311006e05709b978699b5dbbbad29be0414110b10745a4a4c9b41b36bb899989b54adfddaca5a556682f3dfe33e1271fc9eb37379a8f8a3c2fcabcb8ccb31e6f9d864937e4f7d7937a71f3703b8ecf57aacc1f5f264bdee331d8b4ab883c8e8490de0ce686aa381d28d78800dea1a8c15a08540bb9c0fe7adb274012564ec1a298c6792a6a6503a9691d94b32ea4a4cba12c64da6a98c968898f2844e822aa603c19d7a6534fae01aa4c3b6706db33620b17ea94f8aab7e7c90f7bbe4ee3d14ec5065a92bfd7dbcaf6c71b63969517eaa8f1aef1c17d40d78bcc0526b5365d3f3272ec6ff53ff6f96176762276f4d62849b043de196db86aa687ba3cf6a4e3ca607a4d8cd0617db49605788fe9d730690348bd64f0699090afde7e00640d646bb6020000"
16+
],
17+
"responseIsBinary": false,
18+
"headers": {
19+
"access-control-allow-origin": "*",
20+
"access-control-expose-headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
21+
"cache-control": "private, max-age=60, s-maxage=60",
22+
"connection": "close",
23+
"content-encoding": "gzip",
24+
"content-security-policy": "default-src 'none'",
25+
"content-type": "application/json; charset=utf-8",
26+
"date": "Tue, 10 Oct 2017 16:00:00 GMT",
27+
"etag": "\"00000000000000000000000000000000\"",
28+
"referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
29+
"strict-transport-security": "max-age=31536000; includeSubdomains; preload",
30+
"x-accepted-oauth-scopes": "",
31+
"x-content-type-options": "nosniff",
32+
"x-frame-options": "deny",
33+
"x-github-media-type": "github.v3; format=json",
34+
"x-github-request-id": "0000:00000:0000000:0000000:00000000",
35+
"x-oauth-scopes": "read:org, read:repo_hook, read:user, repo, user:email, write:discussion",
36+
"x-ratelimit-limit": "5000",
37+
"x-ratelimit-remaining": "4999",
38+
"x-ratelimit-reset": "1507651200000",
39+
"x-ratelimit-resource": "core",
40+
"x-ratelimit-used": 1,
41+
"x-xss-protection": "0",
42+
"content-length": "618"
43+
}
44+
}
45+
]

test/fixtures/close-issue.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[
2+
{
3+
"scope": "https://api.github.com:443",
4+
"method": "PATCH",
5+
"path": "/repos/kellertk/aws-github-test/issues/1",
6+
"body": {
7+
"state": "closed"
8+
},
9+
"status": 200,
10+
"response": [
11+
"1f8b0800000000000003ed565d6fd33014fd2b535e59e7246bc7883421c48600699b40630c108adcc44dbc3a76643bad4ab4ffceb1d3766b41a3dd269ef694c4bee7dcebfb719c3668b40892a0b4b6360921b4e67b05b76533dccb544534ab9521632604d3764ce8d4f4badd9e65c6126e4cc30c8982ddc05b72abf42c7d042388041d32611e43b20c8b745c2d91b46237e0c6912a26ed13b12fd840cc264f47db7181b4b49558cbc39dd26c52149e074914ef87f1201ac483dd40aa9ca56e31f8908ea7c7e7ef2f9aabc36cf0f1f2edb77770289b6ac83420bb81e55630d8b932eff832efb82a37c6edb781500597d85e04812def2b3cdcef1f84771d9d1e7f3ab8bc3a13d9f5c9f4fcf8343cbb7e73046b3aa196eaf52afb45336f40e72b53d222b3be171b32a77f3d39ea83a2d073127f2017dc7d9decd86e3b79e3ecc270a4845053a0d7a35d1d95550764895a3270593c8001a896285b32240b47705d5c70f3af165e0bc6235ae21e28bfe33048b466f95601cd3108672a1149ebd5c193354393695e5baee476595a418249e9824afe8b6ecf04a4018197a1ad4ee511406e32c26b69ed202da9359fd06ce652a159c6f804897d00dd1a166c7656bb21fce2a60e69e696a534afdce48da830ec66a19641f2e3a7afa975e6995086e50008958df1d21963e68ce1856430918d10b7dfa683575c60d8955cee2ff52dc144679a813d4fa98587388ce35e38e885af2ee228090f92fee03bfc3575fea74d145dc47112bd4cfaa1b3e9825ba55933a18d2d954e11aecab86f05b83cff7a76f219789a59e43775474b1192719bdd71862a9f2ddee75e86587816abbfdcebcf62f52c56ff5fac30af985edc116e2aefbdad37fcefc40db46084582a4b459aa94642a2a0582f22ffe8750f419ba2f40ba5529a42189ca82939c2284022dd3aa3ba436aa79bdd2b9b31441b42692daf98e092dd7fb96c1af8820d8a56333d52ba82b64e384dbb3fbc94d675a76537bf01c73ca455a20b0000"
12+
],
13+
"responseIsBinary": false,
14+
"headers": {
15+
"access-control-allow-origin": "*",
16+
"access-control-expose-headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
17+
"cache-control": "private, max-age=60, s-maxage=60",
18+
"connection": "close",
19+
"content-encoding": "gzip",
20+
"content-security-policy": "default-src 'none'",
21+
"content-type": "application/json; charset=utf-8",
22+
"date": "Tue, 10 Oct 2017 16:00:00 GMT",
23+
"etag": "\"00000000000000000000000000000000\"",
24+
"referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
25+
"strict-transport-security": "max-age=31536000; includeSubdomains; preload",
26+
"x-accepted-oauth-scopes": "",
27+
"x-content-type-options": "nosniff",
28+
"x-frame-options": "deny",
29+
"x-github-media-type": "github.v3; format=json",
30+
"x-github-request-id": "0000:00000:0000000:0000000:00000000",
31+
"x-oauth-scopes": "read:org, read:repo_hook, read:user, repo, user:email, write:discussion",
32+
"x-ratelimit-limit": "5000",
33+
"x-ratelimit-remaining": "4999",
34+
"x-ratelimit-reset": "1507651200000",
35+
"x-ratelimit-resource": "core",
36+
"x-ratelimit-used": 1,
37+
"x-xss-protection": "0",
38+
"content-length": "1456"
39+
}
40+
}
41+
]

0 commit comments

Comments
 (0)