forked from apache/bookkeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BOT] Implement ci bot using github-script
### Motivation `GitHub Action` is deprecated! Implement ci bot using `actions/github-script`, instead. https://github.com/actions/github https://github.com/actions/github-script ### Changes Implement ci using `actions/github-script`, based on https://github.com/zymap/bot/tree/v1.0.1 Reviewers: Jia Zhai <[email protected]>, Enrico Olivelli <[email protected]>, Yong Zhang <[email protected]>, Sijie Guo <None> This closes apache#2352 from lamber-ken/bot-v2
- Loading branch information
Showing
4 changed files
with
134 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "github-action-bot", | ||
"description": "Bot for github actions", | ||
"version": "1.1.1", | ||
"author": "GitHub", | ||
"license": "Apache LICENSE 2.0", | ||
"main": "dist/index.js", | ||
"private": true, | ||
"scripts": { | ||
"build": "ncc build src/run.js" | ||
}, | ||
"dependencies": { | ||
"@actions/core": "^1.2.4", | ||
"@actions/github": "^2.2.0", | ||
"@actions/io": "^1.0.2" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^25.1.4", | ||
"@typescript-eslint/eslint-plugin": "^2.33.0", | ||
"@typescript-eslint/parser": "^2.33.0", | ||
"@zeit/ncc": "^0.22.0", | ||
"eslint": "^7.0.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"husky": "^4.2.5", | ||
"jest": "^25.1.0", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.0.5", | ||
"ts-jest": "^25.2.1", | ||
"typescript": "^3.8.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
async function run(core, context, github) { | ||
|
||
try { | ||
const owner = process.env.PROVIDER; | ||
const repo = process.env.REPOSITORY; | ||
const reRunCmd = process.env.RERUN_CMD; | ||
const comment = context.payload.comment.body; | ||
|
||
if (comment !== reRunCmd) { | ||
console.log("this is not a bot command"); | ||
return; | ||
} | ||
|
||
const { | ||
data: { | ||
head: { | ||
sha: prRef, | ||
} | ||
} | ||
} = await github.pulls.get({ | ||
owner, | ||
repo, | ||
pull_number: context.issue.number, | ||
}); | ||
|
||
const jobs = await github.checks.listForRef({ | ||
owner, | ||
repo, | ||
ref: prRef, | ||
status: "completed" | ||
}); | ||
|
||
jobs.data.check_runs.forEach(job => { | ||
if (job.conclusion === 'failure' || job.conclusion === 'cancelled') { | ||
console.log("rerun job " + job.name); | ||
github.checks.rerequestSuite({ | ||
owner, | ||
repo, | ||
check_suite_id: job.check_suite.id | ||
}) | ||
} | ||
}); | ||
} catch (e) { | ||
core.setFailed(e); | ||
} | ||
|
||
} | ||
|
||
module.exports = ({core}, {context}, {github}) => { | ||
return run(core, context, github); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters