REF: cleanup deps; remove catch from scripts so failures would be visible as failed runs on GithubActions
This commit is contained in:
parent
cd21fc4b15
commit
83fec205b7
11040
package-lock.json
generated
11040
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@ -1,37 +1,21 @@
|
||||
{
|
||||
"name": "glados",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"package": "ncc build --source-map --license licenses.txt",
|
||||
"test": "jest",
|
||||
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
|
||||
"format-check": "prettier --check **/*.ts"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@actions/github": "^4.0.0",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.14",
|
||||
"typescript": "^4.0.2",
|
||||
"@types/node": "^14.6.0",
|
||||
"@typescript-eslint/parser": "^3.10.1",
|
||||
"@vercel/ncc": "^0.24.1",
|
||||
"eslint": "^7.7.0",
|
||||
"eslint-plugin-github": "^4.1.1",
|
||||
"eslint-plugin-jest": "^24.0.1",
|
||||
"jest": "^24.9.0",
|
||||
"jest-circus": "^26.4.2",
|
||||
"js-yaml": "^3.14.0",
|
||||
"prettier": "2.1.1",
|
||||
"ts-jest": "^24.3.0",
|
||||
"typescript": "^4.0.2"
|
||||
"prettier": "2.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,86 +9,101 @@ if (!token) {
|
||||
async function run(): Promise<void> {
|
||||
const octokit = github.getOctokit(token);
|
||||
|
||||
try {
|
||||
const { data: pullRequests } = await octokit.pulls.list({
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
state: "open",
|
||||
});
|
||||
const { data: pullRequests } = await octokit.pulls.list({
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
state: "open",
|
||||
});
|
||||
|
||||
for (const pr of pullRequests) {
|
||||
console.log(`${pr.title} (${pr.number})`);
|
||||
for (const pr of pullRequests) {
|
||||
console.log(`${pr.title} (${pr.number})`);
|
||||
|
||||
let thereAreBlockerLabels = false;
|
||||
for (const label of pr.labels) {
|
||||
if (label.name.toUpperCase().startsWith("DO NOT MERGE") || label.name.toUpperCase().startsWith("WIP")) {
|
||||
thereAreBlockerLabels = true;
|
||||
}
|
||||
let thereAreBlockerLabels = false;
|
||||
for (const label of pr.labels) {
|
||||
if (
|
||||
label.name.toUpperCase().startsWith("DO NOT MERGE") ||
|
||||
label.name.toUpperCase().startsWith("WIP")
|
||||
) {
|
||||
thereAreBlockerLabels = true;
|
||||
}
|
||||
if (thereAreBlockerLabels) continue;
|
||||
}
|
||||
if (thereAreBlockerLabels) continue;
|
||||
|
||||
// cleaning up old glados comments.
|
||||
// comments are sorted by default
|
||||
const comments = await octokit.request(
|
||||
"GET " + pr.comments_url + "?per_page=1000"
|
||||
// cleaning up old glados comments.
|
||||
// comments are sorted by default
|
||||
const comments = await octokit.request(
|
||||
"GET " + pr.comments_url + "?per_page=1000"
|
||||
);
|
||||
if (comments?.data?.length >= 1) {
|
||||
const filteredComments = comments.data.filter(
|
||||
(c) =>
|
||||
c?.user?.login === "GladosBlueWallet" &&
|
||||
c?.body?.includes("Wake the fuck up samurai")
|
||||
);
|
||||
if (comments?.data?.length >= 1) {
|
||||
const filteredComments = comments.data.filter(
|
||||
(c) => c?.user?.login === "GladosBlueWallet" && c?.body?.includes('Wake the fuck up samurai')
|
||||
|
||||
for (const comment of filteredComments) {
|
||||
if (
|
||||
comment.created_at >
|
||||
new Date(+new Date() - 23 * 3600 * 1000).toISOString()
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.warn(
|
||||
"deleting old reminder comment",
|
||||
comment.id,
|
||||
"from PR",
|
||||
pr.number,
|
||||
"dated",
|
||||
comment.created_at
|
||||
);
|
||||
|
||||
for (const comment of filteredComments) {
|
||||
if (comment.created_at > new Date((+new Date()) - 23 * 3600 * 1000).toISOString()) {
|
||||
continue;
|
||||
await octokit.request(
|
||||
"DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}",
|
||||
{
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
comment_id: comment.id,
|
||||
}
|
||||
|
||||
console.warn("deleting old reminder comment", comment.id, "from PR", pr.number, 'dated', comment.created_at);
|
||||
|
||||
await octokit.request(
|
||||
"DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}",
|
||||
{
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
comment_id: comment.id,
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
// end comments cleanup
|
||||
}
|
||||
// end comments cleanup
|
||||
|
||||
const _requestedReviewers = {};
|
||||
const _requestedReviewers = {};
|
||||
|
||||
const requestedReviews = await octokit.request("GET /repos/{owner}/{repo}/pulls/{ref}/requested_reviewers", {
|
||||
const requestedReviews = await octokit.request(
|
||||
"GET /repos/{owner}/{repo}/pulls/{ref}/requested_reviewers",
|
||||
{
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
ref: pr.number,
|
||||
});
|
||||
|
||||
for (const reviewer of requestedReviews?.data?.users || []) {
|
||||
_requestedReviewers[reviewer.login] = true;
|
||||
}
|
||||
);
|
||||
|
||||
console.warn('requested reviewers:', _requestedReviewers);
|
||||
|
||||
for (const user of requestedReviews?.data?.users) {
|
||||
const reviewer = user.login;
|
||||
console.log(reviewer, 'SHOULD BE NOTIFIED');
|
||||
const body = "Wake the fuck up samurai, we have PRs to merge\n\n" +
|
||||
"\n\n" +
|
||||
`[all PRs for @${reviewer}] https://github.com/BlueWallet/BlueWallet/pulls/review-requested/${reviewer}`
|
||||
|
||||
await octokit.issues.createComment({
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
issue_number: pr.number,
|
||||
body,
|
||||
});
|
||||
}
|
||||
|
||||
console.log("=======================================================\n");
|
||||
for (const reviewer of requestedReviews?.data?.users || []) {
|
||||
_requestedReviewers[reviewer.login] = true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(error);
|
||||
|
||||
console.warn("requested reviewers:", _requestedReviewers);
|
||||
|
||||
for (const user of requestedReviews?.data?.users) {
|
||||
const reviewer = user.login;
|
||||
console.log(reviewer, "SHOULD BE NOTIFIED");
|
||||
const body =
|
||||
"Wake the fuck up samurai, we have PRs to merge\n\n" +
|
||||
"\n\n" +
|
||||
`[all PRs for @${reviewer}] https://github.com/BlueWallet/BlueWallet/pulls/review-requested/${reviewer}`;
|
||||
|
||||
await octokit.issues.createComment({
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
issue_number: pr.number,
|
||||
body,
|
||||
});
|
||||
}
|
||||
|
||||
console.log("=======================================================\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
258
src/main.ts
258
src/main.ts
@ -9,148 +9,168 @@ if (!token) {
|
||||
async function run(): Promise<void> {
|
||||
const octokit = github.getOctokit(token);
|
||||
|
||||
try {
|
||||
const { data: pullRequests } = await octokit.pulls.list({
|
||||
const { data: pullRequests } = await octokit.pulls.list({
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
state: "open",
|
||||
});
|
||||
|
||||
for (const pr of pullRequests) {
|
||||
console.log(`${pr.title} (${pr.number})`);
|
||||
|
||||
// cleaning up old glados comments.
|
||||
// comments are sorted by default
|
||||
const comments = await octokit.request(
|
||||
"GET " + pr.comments_url + "?per_page=1000"
|
||||
);
|
||||
if (comments?.data?.length >= 1) {
|
||||
const filteredComments = comments.data.filter(
|
||||
(c) =>
|
||||
c?.user?.login === "GladosBlueWallet" &&
|
||||
c?.body?.includes("HUGE SUCCESS")
|
||||
);
|
||||
const deleteMax = filteredComments.length - 1;
|
||||
let deleted = 0;
|
||||
for (const comment of filteredComments) {
|
||||
if (deleted++ >= deleteMax) break;
|
||||
console.warn("deleting comment", comment.id, "from PR", pr.number);
|
||||
|
||||
await octokit.request(
|
||||
"DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}",
|
||||
{
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
comment_id: comment.id,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
// end comments cleanup
|
||||
|
||||
let approved = false;
|
||||
let e2ePassed = false;
|
||||
let unitTestsPassed = false;
|
||||
let thereAreBlockerLabels = false;
|
||||
let outsiderContributor =
|
||||
pr.head.repo.full_name !== "BlueWallet/BlueWallet";
|
||||
|
||||
for (const label of pr.labels) {
|
||||
if (
|
||||
label.name.toUpperCase().startsWith("DO NOT MERGE") ||
|
||||
label.name.toUpperCase().startsWith("WIP")
|
||||
) {
|
||||
thereAreBlockerLabels = true;
|
||||
}
|
||||
}
|
||||
|
||||
const reviews = await octokit.request(
|
||||
"GET /repos/{owner}/{repo}/pulls/{ref}/reviews",
|
||||
{
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
ref: pr.number,
|
||||
}
|
||||
);
|
||||
|
||||
const checks = await octokit.checks.listForRef({
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
state: "open",
|
||||
ref: pr.head.sha,
|
||||
});
|
||||
|
||||
for (const pr of pullRequests) {
|
||||
console.log(`${pr.title} (${pr.number})`);
|
||||
for (const check of checks.data.check_runs) {
|
||||
if (check.name.startsWith("Travis CI") && check.conclusion === "success")
|
||||
e2ePassed = true;
|
||||
if (check.name === "e2e" && check.conclusion === "success")
|
||||
e2ePassed = true;
|
||||
if (check.name === "test" && check.conclusion === "success")
|
||||
unitTestsPassed = true;
|
||||
// so if Travis or GithubActions passes - it still gets green lights since its the same set of tests
|
||||
}
|
||||
|
||||
// cleaning up old glados comments.
|
||||
// comments are sorted by default
|
||||
const comments = await octokit.request(
|
||||
"GET " + pr.comments_url + "?per_page=1000"
|
||||
);
|
||||
if (comments?.data?.length >= 1) {
|
||||
const filteredComments = comments.data.filter(
|
||||
(c) => c?.user?.login === "GladosBlueWallet" && c?.body?.includes('HUGE SUCCESS')
|
||||
);
|
||||
const deleteMax = filteredComments.length - 1;
|
||||
let deleted = 0;
|
||||
for (const comment of filteredComments) {
|
||||
if (deleted++ >= deleteMax) break;
|
||||
console.warn("deleting comment", comment.id, "from PR", pr.number);
|
||||
|
||||
await octokit.request(
|
||||
"DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}",
|
||||
{
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
comment_id: comment.id,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
// end comments cleanup
|
||||
|
||||
let approved = false;
|
||||
let e2ePassed = false;
|
||||
let unitTestsPassed = false;
|
||||
let thereAreBlockerLabels = false;
|
||||
let outsiderContributor = pr.head.repo.full_name !== "BlueWallet/BlueWallet";
|
||||
|
||||
for (const label of pr.labels) {
|
||||
if (label.name.toUpperCase().startsWith("DO NOT MERGE") || label.name.toUpperCase().startsWith("WIP")) {
|
||||
thereAreBlockerLabels = true;
|
||||
if (reviews.data.length >= 1) {
|
||||
let _approves = {};
|
||||
for (const review of reviews.data) {
|
||||
if (review["state"] === "COMMENTED") continue;
|
||||
if (review["state"] !== "APPROVED") {
|
||||
console.log("NOT approved by", review.user.login);
|
||||
_approves[review.user.login] = false;
|
||||
} else {
|
||||
console.log("approved by", review.user.login);
|
||||
_approves[review.user.login] = true;
|
||||
}
|
||||
}
|
||||
|
||||
const reviews = await octokit.request("GET /repos/{owner}/{repo}/pulls/{ref}/reviews", {
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
ref: pr.number,
|
||||
});
|
||||
approved =
|
||||
Object.values(_approves).filter((el) => el === false).length === 0;
|
||||
}
|
||||
|
||||
const checks = await octokit.checks.listForRef({
|
||||
if (pr.requested_reviewers.length !== 0) {
|
||||
console.log("not all requested reviews are done");
|
||||
approved = false;
|
||||
}
|
||||
|
||||
const statuses = await octokit.request(
|
||||
"GET /repos/{owner}/{repo}/commits/{ref}/status",
|
||||
{
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
ref: pr.head.sha,
|
||||
});
|
||||
|
||||
for (const check of checks.data.check_runs) {
|
||||
if (check.name.startsWith("Travis CI") && check.conclusion === "success") e2ePassed = true;
|
||||
if (check.name === 'e2e' && check.conclusion === "success") e2ePassed = true;
|
||||
if (check.name === 'test' && check.conclusion === "success") unitTestsPassed = true;
|
||||
// so if Travis or GithubActions passes - it still gets green lights since its the same set of tests
|
||||
}
|
||||
);
|
||||
|
||||
if (reviews.data.length >= 1) {
|
||||
let _approves = {};
|
||||
for (const review of reviews.data) {
|
||||
if (review["state"] === "COMMENTED") continue;
|
||||
if (review["state"] !== "APPROVED") {
|
||||
console.log("NOT approved by", review.user.login);
|
||||
_approves[review.user.login] = false;
|
||||
} else {
|
||||
console.log("approved by", review.user.login);
|
||||
_approves[review.user.login] = true;
|
||||
}
|
||||
}
|
||||
for (const status of statuses.data.statuses) {
|
||||
if (
|
||||
status.context.startsWith("ci/circleci") &&
|
||||
status.state === "success"
|
||||
)
|
||||
unitTestsPassed = true;
|
||||
}
|
||||
|
||||
approved = Object.values(_approves).filter((el) => el === false).length === 0;
|
||||
}
|
||||
console.log({
|
||||
approved,
|
||||
e2ePassed,
|
||||
unitTestsPassed,
|
||||
outsiderContributor,
|
||||
thereAreBlockerLabels,
|
||||
});
|
||||
|
||||
if (pr.requested_reviewers.length !== 0) {
|
||||
console.log("not all requested reviews are done");
|
||||
approved = false;
|
||||
}
|
||||
if (
|
||||
approved &&
|
||||
e2ePassed &&
|
||||
unitTestsPassed &&
|
||||
!outsiderContributor &&
|
||||
!thereAreBlockerLabels
|
||||
) {
|
||||
console.log("LGTM. lets merge");
|
||||
// continue; // fixme
|
||||
|
||||
const statuses = await octokit.request(
|
||||
"GET /repos/{owner}/{repo}/commits/{ref}/status",
|
||||
{
|
||||
try {
|
||||
const mergeResult = await octokit.pulls.merge({
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
ref: pr.head.sha,
|
||||
pull_number: pr.number,
|
||||
});
|
||||
|
||||
let body = "I could not merge it.";
|
||||
if (mergeResult.data.message.indexOf("successfully") !== -1) {
|
||||
console.log({ mergeResult });
|
||||
body =
|
||||
"Unbelievable. You, [subject name here], must be the pride of [subject hometown here]!";
|
||||
}
|
||||
);
|
||||
|
||||
for (const status of statuses.data.statuses) {
|
||||
if (status.context.startsWith("ci/circleci") && status.state === "success") unitTestsPassed = true;
|
||||
await octokit.issues.createComment({
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
issue_number: pr.number,
|
||||
body,
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn(error.message);
|
||||
}
|
||||
|
||||
console.log({
|
||||
approved,
|
||||
e2ePassed,
|
||||
unitTestsPassed,
|
||||
outsiderContributor,
|
||||
thereAreBlockerLabels,
|
||||
});
|
||||
|
||||
if (approved && e2ePassed && unitTestsPassed && !outsiderContributor && !thereAreBlockerLabels) {
|
||||
console.log("LGTM. lets merge");
|
||||
// continue; // fixme
|
||||
|
||||
try {
|
||||
const mergeResult = await octokit.pulls.merge({
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
pull_number: pr.number,
|
||||
});
|
||||
|
||||
let body = "I could not merge it.";
|
||||
if (mergeResult.data.message.indexOf("successfully") !== -1) {
|
||||
console.log({ mergeResult });
|
||||
body = "Unbelievable. You, [subject name here], must be the pride of [subject hometown here]!";
|
||||
}
|
||||
|
||||
await octokit.issues.createComment({
|
||||
repo: "BlueWallet",
|
||||
owner: "BlueWallet",
|
||||
issue_number: pr.number,
|
||||
body,
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("=======================================================\n");
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(error);
|
||||
|
||||
console.log("=======================================================\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user