Skip to content

Commit

Permalink
Merge pull request #9 from HongW2019/workflow
Browse files Browse the repository at this point in the history
[ML-8]Modify title check of PRs on Github Actions
  • Loading branch information
zhixingheyi-tian authored Feb 7, 2021
2 parents ac20823 + a799db1 commit 47aae78
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 84 deletions.
61 changes: 28 additions & 33 deletions .github/workflows/dev_cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,44 @@
# specific language governing permissions and limitations
# under the License.

name: Dev Cron
name: Dev PR

on:
push:
paths:
- '.github/workflows/dev_cron.yml'
pull_request:
paths:
- '.github/workflows/dev_cron.yml'
schedule:
- cron: |
*/15 * * * *

jobs:
pull_request_target:
types:
- opened
- edited
- synchronize

issues-link:
if: github.repository == 'Intel-bigdata/OAP'
name: issues link
jobs:
process:
name: Process
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Comment
uses: actions/github-script@master
- uses: actions/checkout@v2

- name: Comment Issues link
if: |
github.event_name == 'pull_request_target' &&
(github.event.action == 'opened' ||
github.event.action == 'edited')
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require("fs");
const path = ".github/workflows/dev_cron/issues_link.js";
const script = fs.readFileSync(path).toString();
eval(script);
const script = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_cron/issues_link.js`);
script({github, context});
title-check:
if: github.repository == 'Intel-bigdata/OAP'
name: Title check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Check
uses: actions/github-script@master
- name: Check title
if: |
github.event_name == 'pull_request_target' &&
(github.event.action == 'opened' ||
github.event.action == 'edited')
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require("fs");
const path = ".github/workflows/dev_cron/title_check.js";
const script = fs.readFileSync(path).toString();
eval(script);
const script = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_cron/title_check.js`);
script({github, context});
42 changes: 17 additions & 25 deletions .github/workflows/dev_cron/issues_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@
// specific language governing permissions and limitations
// under the License.

const {owner: owner, repo: repo} = context.repo;

function detectISSUESID(title) {
if (!title) {
return null;
}
const matched = /^\[OAP-\d+\]/.exec(title);
const matched = /^\[ML-\d+\]/.exec(title);
if (!matched) {
return null;
}
const issues_number = matched[0].replace(/[^0-9]/ig,"");
return issues_number;
}

async function haveComment(pullRequestNumber, body) {
async function haveComment(github, context, pullRequestNumber, body) {
const options = {
owner: owner,
repo: repo,
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequestNumber,
page: 1
};
Expand All @@ -49,30 +47,24 @@ async function haveComment(pullRequestNumber, body) {
return false;
}

async function commentISSUESURL(pullRequestNumber, issuesID) {
const issuesURL = `https://github.com/Intel-bigdata/OAP/issues/${issuesID}`;
if (await haveComment(pullRequestNumber, issuesURL)) {
async function commentISSUESURL(github, context, pullRequestNumber, issuesID) {
const issuesURL = `https://github.com/oap-project/oap-mllib/issues/${issuesID}`;
if (await haveComment(github, context, pullRequestNumber, issuesURL)) {
return;
}
await github.issues.createComment({
owner: owner,
repo: repo,
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequestNumber,
body: issuesURL
});
}

(async () => {
const {data: pulls} = await github.pulls.list({
owner: owner,
repo: repo,
});
pulls.forEach(async (pull) => {
const pullRequestNumber = pull.number;
const title = pull.title;
const issuesID = detectISSUESID(title);
if (issuesID) {
await commentISSUESURL(pullRequestNumber, issuesID);
}
});
})();
module.exports = async ({github, context}) => {
const pullRequestNumber = context.payload.number;
const title = context.payload.pull_request.title;
const issuesID = detectISSUESID(title);
if (issuesID) {
await commentISSUESURL(github, context, pullRequestNumber, issuesID);
}
};
36 changes: 13 additions & 23 deletions .github/workflows/dev_cron/title_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@
// specific language governing permissions and limitations
// under the License.

console.log("title-check");

const fs = require("fs");

const {owner: owner, repo: repo} = context.repo;

function haveISSUESID(title) {
if (!title) {
return false;
}
return /^\[OAP-\d+\]/.test(title);
return /^\[ML-\d+\]/.test(title);
}

async function commentOpenISSUESIssue(pullRequestNumber) {
async function commentOpenISSUESIssue(github, context, pullRequestNumber) {
const {data: comments} = await github.issues.listComments({
owner: owner,
repo: repo,
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequestNumber,
per_page: 1
});
Expand All @@ -41,23 +37,17 @@ async function commentOpenISSUESIssue(pullRequestNumber) {
const commentPath = ".github/workflows/dev_cron/title_check.md";
const comment = fs.readFileSync(commentPath).toString();
await github.issues.createComment({
owner: owner,
repo: repo,
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequestNumber,
body: comment
});
}

(async () => {
const {data: pulls} = await github.pulls.list({
owner: owner,
repo: repo,
});
pulls.forEach(async (pull) => {
const pullRequestNumber = pull.number;
const title = pull.title;
if (!haveISSUESID(title)) {
await commentOpenISSUESIssue(pullRequestNumber);
}
});
})();
module.exports = async ({github, context}) => {
const pullRequestNumber = context.payload.number;
const title = context.payload.pull_request.title;
if (!haveISSUESID(title)) {
await commentOpenISSUESIssue(github, context, pullRequestNumber);
}
};
6 changes: 3 additions & 3 deletions .github/workflows/dev_cron/title_check.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
Thanks for opening a pull request!

Could you open an issue for this pull request on Github Issues?
https://github.com/Intel-bigdata/OAP/issues
https://github.com/oap-project/oap-mllib/issues

Then could you also rename ***pull request title*** and ***commit log*** in the following format?

[OAP-${ISSUES_ID}][optional:${MUDULENAME}] ${detailed message}
[ML-${ISSUES_ID}] ${detailed message}

See also:

* [Other pull requests](https://github.com/Intel-bigdata/OAP/pulls/)
* [Other pull requests](https://github.com/oap-project/oap-mllib/pulls/)

0 comments on commit 47aae78

Please sign in to comment.