init
This commit is contained in:
commit
fc52d17b1c
10486
package-lock.json
generated
Normal file
10486
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
37
package.json
Normal file
37
package.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "glados",
|
||||
"version": "1.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"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.5",
|
||||
"@actions/github": "^4.0.0",
|
||||
"ts-node": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.14",
|
||||
"@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"
|
||||
}
|
||||
}
|
||||
120
src/main.ts
Normal file
120
src/main.ts
Normal file
@ -0,0 +1,120 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
|
||||
const g = process.env.TOKEN;
|
||||
if (!g) {
|
||||
console.error('no TOKEN env provided');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
async function run(): Promise<void> {
|
||||
const octokit = github.getOctokit(g)
|
||||
|
||||
try {
|
||||
const {data: pullRequests} = await octokit.pulls.list({
|
||||
repo: 'BlueWallet',
|
||||
owner:'BlueWallet',
|
||||
state: 'open'
|
||||
});
|
||||
|
||||
|
||||
for (const pr of pullRequests) {
|
||||
// if (pr.number !== 2021) continue;
|
||||
console.log(`${pr.title} (${pr.number})`, );
|
||||
|
||||
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',
|
||||
ref: pr.head.sha,
|
||||
});
|
||||
|
||||
for (const check of checks.data.check_runs) {
|
||||
if (check.name.startsWith('Travis CI') && check.conclusion === 'success') e2ePassed = true;
|
||||
}
|
||||
|
||||
|
||||
if (reviews.data.length >= 1) {
|
||||
let _approves = {};
|
||||
for (const review of reviews.data) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
approved = (Object.values(_approves).filter((el) => el === false).length === 0);
|
||||
}
|
||||
|
||||
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 status of statuses.data.statuses) {
|
||||
if (status.context.startsWith('ci/circleci') && status.state === 'success') unitTestsPassed = true;
|
||||
}
|
||||
|
||||
console.log({approved, e2ePassed, unitTestsPassed, outsiderContributor, thereAreBlockerLabels});
|
||||
|
||||
if (approved && e2ePassed && unitTestsPassed && !outsiderContributor && !thereAreBlockerLabels) {
|
||||
console.log('LGTM. lets merge');
|
||||
// continue; // fixme
|
||||
|
||||
const mergeResult = await octokit.pulls.merge({
|
||||
repo: 'BlueWallet',
|
||||
owner:'BlueWallet',
|
||||
pull_number: pr.number,
|
||||
})
|
||||
|
||||
if (mergeResult.data.message.indexOf('successfully') !== -1) {
|
||||
console.log({mergeResult});
|
||||
await octokit.issues.createComment({
|
||||
repo: 'BlueWallet',
|
||||
owner: 'BlueWallet',
|
||||
issue_number: pr.number,
|
||||
body: 'Unbelievable! You, Subject Name Here, must be the pride of Subject Hometown Here.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
console.log('=======================================================\n');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.warn(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
run();
|
||||
Loading…
Reference in New Issue
Block a user