Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML-8]Modify title check of PRs on Github Actions #9

Merged
merged 2 commits into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/)