Skip to content

Commit

Permalink
[ADS-11]Modify title check and automatic link to Issues for PRs (oap-…
Browse files Browse the repository at this point in the history
  • Loading branch information
Hong authored Feb 22, 2021
1 parent e09272f commit 62b55d7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 85 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 = /^\[ADS-\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/arrow-data-source/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 /^\[ADS-\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);
}
};
9 changes: 5 additions & 4 deletions .github/workflows/dev_cron/title_check.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
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

Then could you also rename ***pull request title*** and ***commit log*** in the following format?
https://github.com/oap-project/arrow-data-source/issues

[OAP-${ISSUES_ID}][optional:${MUDULENAME}] ${detailed message}
Then could you also rename ***commit message*** and ***pull request title*** in the following format?

[ADS-${ISSUES_ID}] ${detailed message}

See also:

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

0 comments on commit 62b55d7

Please sign in to comment.