diff --git a/.github/workflows/dev_cron.yml b/.github/workflows/dev_cron.yml index 0e9998541..ab2840ebd 100644 --- a/.github/workflows/dev_cron.yml +++ b/.github/workflows/dev_cron.yml @@ -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}); + diff --git a/.github/workflows/dev_cron/issues_link.js b/.github/workflows/dev_cron/issues_link.js index 3d23b9644..f3b4dd6d3 100644 --- a/.github/workflows/dev_cron/issues_link.js +++ b/.github/workflows/dev_cron/issues_link.js @@ -15,13 +15,11 @@ // 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; } @@ -29,10 +27,10 @@ function detectISSUESID(title) { 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 }; @@ -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); + } +}; diff --git a/.github/workflows/dev_cron/title_check.js b/.github/workflows/dev_cron/title_check.js index 90c90afcd..030cf01a8 100644 --- a/.github/workflows/dev_cron/title_check.js +++ b/.github/workflows/dev_cron/title_check.js @@ -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 }); @@ -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); + } +}; diff --git a/.github/workflows/dev_cron/title_check.md b/.github/workflows/dev_cron/title_check.md index b04efea9b..38a6460dd 100644 --- a/.github/workflows/dev_cron/title_check.md +++ b/.github/workflows/dev_cron/title_check.md @@ -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/)