Skip to content

Commit

Permalink
in progress: v6 release
Browse files Browse the repository at this point in the history
  • Loading branch information
kellertk committed May 11, 2022
1 parent 92b8e7d commit e4ca979
Show file tree
Hide file tree
Showing 10 changed files with 974 additions and 32 deletions.
20 changes: 11 additions & 9 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,21 @@ export async function reopenIssue(issue: number, token: string) {
});
}

function getIssueLabelDate(timeline: Timeline, label: string) {
export function getIssueLabelDate(timeline: Timeline, label: string) {
// Return when the label was last applied
return timeline.reduce((p, c) => {
if (c.updated_at && c.label?.name === label) {
if (Date.parse(c.updated_at) > p) {
return Date.parse(c.updated_at);
return timeline
.filter(te => te.event === 'labeled')
.reduce((p, c) => {
if (c.updated_at && c.label?.name === label) {
if (Date.parse(c.updated_at) > p) {
return Date.parse(c.updated_at);
} else {
return p;
}
} else {
return p;
}
} else {
return p;
}
}, 0);
}, 0);
}

export function issueDateCompare(issueDate: string, configuredDays: number) {
Expand Down
35 changes: 20 additions & 15 deletions test/bin/normalize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,27 @@ export async function normalizeFixtures(fixtureDirectory) {
fixtureObject.original_path = file;
return fixtureObject;
})
);
).catch(e => {
process.exitCode = 1;
console.error(e);
});

// Run octokit's normalization and write back
await Promise.all(
fixtureContents.map(async fixture => {
for (const fixtureKey in fixture) {
// skip original path, this is just for us
if (fixtureKey === 'original_path') continue;
if (fixtureContents) {
await Promise.all(
fixtureContents.map(async fixture => {
for (const fixtureKey in fixture) {
// skip original path, this is just for us
if (fixtureKey === 'original_path') continue;

const normalized = await normalize('test', fixture[fixtureKey]);
// while octokit's normalization requires request headers, if we include them our nocks won't match
delete normalized.reqheaders;
delete fixture[fixtureKey];
fixture[fixtureKey] = normalized;
}
await fs.writeFile(fixture.original_path, JSON.stringify(fixture, null, 2), { encoding: 'utf-8' });
})
);
const normalized = await normalize({ commitSha: {}, ids: {} }, fixture[fixtureKey]);
// while octokit's normalization requires request headers, if we include them our nocks won't match
delete normalized.reqheaders;
delete fixture[fixtureKey];
fixture[fixtureKey] = normalized;
}
await fs.writeFile(fixture.original_path, JSON.stringify(fixture, null, 2), { encoding: 'utf-8' });
})
);
}
}
165 changes: 165 additions & 0 deletions test/data/timeline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
[
{
"id": 3504742193,
"node_id": "MDEyOkxhYmVsZWRFdmVudDM1MDQ3NDIxOTM=",
"url": "https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/events/3504742193",
"actor": {
"login": "kellertk",
"id": 1083460,
"node_id": "MDQ6VXNlcjEwODM0NjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/1083460?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kellertk",
"html_url": "https://github.com/kellertk",
"followers_url": "https://api.github.com/users/kellertk/followers",
"following_url": "https://api.github.com/users/kellertk/following{/other_user}",
"gists_url": "https://api.github.com/users/kellertk/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kellertk/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kellertk/subscriptions",
"organizations_url": "https://api.github.com/users/kellertk/orgs",
"repos_url": "https://api.github.com/users/kellertk/repos",
"events_url": "https://api.github.com/users/kellertk/events{/privacy}",
"received_events_url": "https://api.github.com/users/kellertk/received_events",
"type": "User",
"site_admin": false
},
"event": "labeled",
"commit_id": null,
"commit_url": null,
"created_at": "2020-07-02T00:23:09Z",
"label": {
"name": "enhancement",
"color": "a2eeef"
},
"performed_via_github_app": null
},
{
"url": "https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/comments/652710305",
"html_url": "https://github.com/aws-actions/stale-issue-cleanup/issues/38#issuecomment-652710305",
"issue_url": "https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/38",
"id": 652710305,
"node_id": "MDEyOklzc3VlQ29tbWVudDY1MjcxMDMwNQ==",
"user": {
"login": "kellertk",
"id": 1083460,
"node_id": "MDQ6VXNlcjEwODM0NjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/1083460?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kellertk",
"html_url": "https://github.com/kellertk",
"followers_url": "https://api.github.com/users/kellertk/followers",
"following_url": "https://api.github.com/users/kellertk/following{/other_user}",
"gists_url": "https://api.github.com/users/kellertk/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kellertk/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kellertk/subscriptions",
"organizations_url": "https://api.github.com/users/kellertk/orgs",
"repos_url": "https://api.github.com/users/kellertk/repos",
"events_url": "https://api.github.com/users/kellertk/events{/privacy}",
"received_events_url": "https://api.github.com/users/kellertk/received_events",
"type": "User",
"site_admin": false
},
"created_at": "2020-07-02T00:26:11Z",
"updated_at": "2020-07-02T00:26:11Z",
"author_association": "CONTRIBUTOR",
"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",
"reactions": {
"url": "https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/comments/652710305/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
},
"performed_via_github_app": null,
"event": "commented",
"actor": {
"login": "kellertk",
"id": 1083460,
"node_id": "MDQ6VXNlcjEwODM0NjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/1083460?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kellertk",
"html_url": "https://github.com/kellertk",
"followers_url": "https://api.github.com/users/kellertk/followers",
"following_url": "https://api.github.com/users/kellertk/following{/other_user}",
"gists_url": "https://api.github.com/users/kellertk/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kellertk/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kellertk/subscriptions",
"organizations_url": "https://api.github.com/users/kellertk/orgs",
"repos_url": "https://api.github.com/users/kellertk/repos",
"events_url": "https://api.github.com/users/kellertk/events{/privacy}",
"received_events_url": "https://api.github.com/users/kellertk/received_events",
"type": "User",
"site_admin": false
}
},
{
"id": 3504749386,
"node_id": "MDEyOkxhYmVsZWRFdmVudDM1MDQ3NDkzODY=",
"url": "https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/events/3504749386",
"actor": {
"login": "kellertk",
"id": 1083460,
"node_id": "MDQ6VXNlcjEwODM0NjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/1083460?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kellertk",
"html_url": "https://github.com/kellertk",
"followers_url": "https://api.github.com/users/kellertk/followers",
"following_url": "https://api.github.com/users/kellertk/following{/other_user}",
"gists_url": "https://api.github.com/users/kellertk/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kellertk/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kellertk/subscriptions",
"organizations_url": "https://api.github.com/users/kellertk/orgs",
"repos_url": "https://api.github.com/users/kellertk/repos",
"events_url": "https://api.github.com/users/kellertk/events{/privacy}",
"received_events_url": "https://api.github.com/users/kellertk/received_events",
"type": "User",
"site_admin": false
},
"event": "labeled",
"commit_id": null,
"commit_url": null,
"created_at": "2020-07-02T00:26:23Z",
"label": {
"name": "wontfix",
"color": "ffffff"
},
"performed_via_github_app": null
},
{
"id": 3504749502,
"node_id": "MDExOkNsb3NlZEV2ZW50MzUwNDc0OTUwMg==",
"url": "https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/events/3504749502",
"actor": {
"login": "kellertk",
"id": 1083460,
"node_id": "MDQ6VXNlcjEwODM0NjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/1083460?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kellertk",
"html_url": "https://github.com/kellertk",
"followers_url": "https://api.github.com/users/kellertk/followers",
"following_url": "https://api.github.com/users/kellertk/following{/other_user}",
"gists_url": "https://api.github.com/users/kellertk/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kellertk/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kellertk/subscriptions",
"organizations_url": "https://api.github.com/users/kellertk/orgs",
"repos_url": "https://api.github.com/users/kellertk/repos",
"events_url": "https://api.github.com/users/kellertk/events{/privacy}",
"received_events_url": "https://api.github.com/users/kellertk/received_events",
"type": "User",
"site_admin": false
},
"event": "closed",
"commit_id": null,
"commit_url": null,
"created_at": "2020-07-02T00:26:26Z",
"performed_via_github_app": null
}
]
45 changes: 45 additions & 0 deletions test/fixtures/add-label.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[
{
"scope": "https://api.github.com:443",
"method": "POST",
"path": "/repos/kellertk/aws-github-test/issues/1/labels",
"body": {
"labels": [
"bug",
"documentation",
"duplicate"
]
},
"status": 200,
"response": [
"1f8b0800000000000003add2c14a03311006e05709b978699b5dbbbad29be0414110b10745a4a4c9b41b36bb899989b54adfddaca5a556682f3dfe33e1271fc9eb37379a8f8a3c2fcabcb8ccb31e6f9d864937e4f7d7937a71f3703b8ecf57aacc1f5f264bdee331d8b4ab883c8e8490de0ce686aa381d28d78800dea1a8c15a08540bb9c0fe7adb274012564ec1a298c6792a6a6503a9691d94b32ea4a4cba12c64da6a98c968898f2844e822aa603c19d7a6534fae01aa4c3b6706db33620b17ea94f8aab7e7c90f7bbe4ee3d14ec5065a92bfd7dbcaf6c71b63969517eaa8f1aef1c17d40d78bcc0526b5365d3f3272ec6ff53ff6f96176762276f4d62849b043de196db86aa687ba3cf6a4e3ca607a4d8cd0617db49605788fe9d730690348bd64f0699090afde7e00640d646bb6020000"
],
"responseIsBinary": false,
"headers": {
"access-control-allow-origin": "*",
"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",
"cache-control": "private, max-age=60, s-maxage=60",
"connection": "close",
"content-encoding": "gzip",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 10 Oct 2017 16:00:00 GMT",
"etag": "\"00000000000000000000000000000000\"",
"referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"strict-transport-security": "max-age=31536000; includeSubdomains; preload",
"x-accepted-oauth-scopes": "",
"x-content-type-options": "nosniff",
"x-frame-options": "deny",
"x-github-media-type": "github.v3; format=json",
"x-github-request-id": "0000:00000:0000000:0000000:00000000",
"x-oauth-scopes": "read:org, read:repo_hook, read:user, repo, user:email, write:discussion",
"x-ratelimit-limit": "5000",
"x-ratelimit-remaining": "4999",
"x-ratelimit-reset": "1507651200000",
"x-ratelimit-resource": "core",
"x-ratelimit-used": 1,
"x-xss-protection": "0",
"content-length": "618"
}
}
]
41 changes: 41 additions & 0 deletions test/fixtures/close-issue.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[
{
"scope": "https://api.github.com:443",
"method": "PATCH",
"path": "/repos/kellertk/aws-github-test/issues/1",
"body": {
"state": "closed"
},
"status": 200,
"response": [
"1f8b0800000000000003ed565d6fd33014fd2b535e59e7246bc7883421c48600699b40630c108adcc44dbc3a76643bad4ab4ffceb1d3766b41a3dd269ef694c4bee7dcebfb719c3668b40892a0b4b6360921b4e67b05b76533dccb544534ab9521632604d3764ce8d4f4badd9e65c6126e4cc30c8982ddc05b72abf42c7d042388041d32611e43b20c8b745c2d91b46237e0c6912a26ed13b12fd840cc264f47db7181b4b49558cbc39dd26c52149e074914ef87f1201ac483dd40aa9ca56e31f8908ea7c7e7ef2f9aabc36cf0f1f2edb77770289b6ac83420bb81e55630d8b932eff832efb82a37c6edb781500597d85e04812def2b3cdcef1f84771d9d1e7f3ab8bc3a13d9f5c9f4fcf8343cbb7e73046b3aa196eaf52afb45336f40e72b53d222b3be171b32a77f3d39ea83a2d073127f2017dc7d9decd86e3b79e3ecc270a4845053a0d7a35d1d95550764895a3270593c8001a896285b32240b47705d5c70f3af165e0bc6235ae21e28bfe33048b466f95601cd3108672a1149ebd5c193354393695e5baee476595a418249e9824afe8b6ecf04a4018197a1ad4ee511406e32c26b69ed202da9359fd06ce652a159c6f804897d00dd1a166c7656bb21fce2a60e69e696a534afdce48da830ec66a19641f2e3a7afa975e6995086e50008958df1d21963e68ce1856430918d10b7dfa683575c60d8955cee2ff52dc144679a813d4fa98587388ce35e38e885af2ee228090f92fee03bfc3575fea74d145dc47112bd4cfaa1b3e9825ba55933a18d2d954e11aecab86f05b83cff7a76f219789a59e43775474b1192719bdd71862a9f2ddee75e86587816abbfdcebcf62f52c56ff5fac30af985edc116e2aefbdad37fcefc40db46084582a4b459aa94642a2a0582f22ffe8750f419ba2f40ba5529a42189ca82939c2284022dd3aa3ba436aa79bdd2b9b31441b42692daf98e092dd7fb96c1af8820d8a56333d52ba82b64e384dbb3fbc94d675a76537bf01c73ca455a20b0000"
],
"responseIsBinary": false,
"headers": {
"access-control-allow-origin": "*",
"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",
"cache-control": "private, max-age=60, s-maxage=60",
"connection": "close",
"content-encoding": "gzip",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 10 Oct 2017 16:00:00 GMT",
"etag": "\"00000000000000000000000000000000\"",
"referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"strict-transport-security": "max-age=31536000; includeSubdomains; preload",
"x-accepted-oauth-scopes": "",
"x-content-type-options": "nosniff",
"x-frame-options": "deny",
"x-github-media-type": "github.v3; format=json",
"x-github-request-id": "0000:00000:0000000:0000000:00000000",
"x-oauth-scopes": "read:org, read:repo_hook, read:user, repo, user:email, write:discussion",
"x-ratelimit-limit": "5000",
"x-ratelimit-remaining": "4999",
"x-ratelimit-reset": "1507651200000",
"x-ratelimit-resource": "core",
"x-ratelimit-used": 1,
"x-xss-protection": "0",
"content-length": "1456"
}
}
]
Loading

0 comments on commit e4ca979

Please sign in to comment.