From c2e6305b034ba90a924f83082530ecc9793b7180 Mon Sep 17 00:00:00 2001 From: harupy Date: Thu, 2 Dec 2021 11:33:46 +0900 Subject: [PATCH 1/4] checkout to fork Signed-off-by: harupy --- .github/workflows/autoformat.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/autoformat.js b/.github/workflows/autoformat.js index ca76af3d415fd..25483b225dbf9 100644 --- a/.github/workflows/autoformat.js +++ b/.github/workflows/autoformat.js @@ -18,9 +18,10 @@ const createStatus = async (context, github) => { const pull_number = context.issue.number; const pr = await github.pulls.get({ owner, repo, pull_number }); const { sha, ref } = pr.data.head; + const repository = pr.data.repo.full_name; await createCommitStatus(context, github, sha, 'pending'); return { - repository: `${owner}/${repo}`, + repository, pull_number, sha, ref, From a396b2352dc2405caeb7d6c7d61fe1f7c7ae3dbd Mon Sep 17 00:00:00 2001 From: harupy Date: Thu, 2 Dec 2021 11:46:25 +0900 Subject: [PATCH 2/4] validation Signed-off-by: harupy --- .github/workflows/autoformat.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/autoformat.js b/.github/workflows/autoformat.js index 25483b225dbf9..0955e7953c9f5 100644 --- a/.github/workflows/autoformat.js +++ b/.github/workflows/autoformat.js @@ -13,13 +13,16 @@ const createCommitStatus = async (context, github, sha, state) => { }); }; -const createStatus = async (context, github) => { +const createStatus = async (context, github, core) => { const { owner, repo } = context.repo; const pull_number = context.issue.number; const pr = await github.pulls.get({ owner, repo, pull_number }); const { sha, ref } = pr.data.head; const repository = pr.data.repo.full_name; await createCommitStatus(context, github, sha, 'pending'); + if (repository === 'mlflow/mlflow' && ref === 'master') { + core.setFailed('Running autoformat bot against master branch of mlflow/mlflow is not allowed.'); + } return { repository, pull_number, From e53d620377c6ccecd7108d792bbb80c3c3c15e2a Mon Sep 17 00:00:00 2001 From: harupy Date: Thu, 2 Dec 2021 11:47:42 +0900 Subject: [PATCH 3/4] pass core Signed-off-by: harupy --- .github/workflows/autoformat.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/autoformat.yml b/.github/workflows/autoformat.yml index a70407c0a1dab..984aa4d218f0e 100644 --- a/.github/workflows/autoformat.yml +++ b/.github/workflows/autoformat.yml @@ -36,7 +36,7 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const autoformat = require('./.github/workflows/autoformat.js'); - return await autoformat.createStatus(context, github); + return await autoformat.createStatus(context, github, core); check-diff: runs-on: ubuntu-latest From 775b518619b9ffeac998c08aac988cc4018b9ddb Mon Sep 17 00:00:00 2001 From: harupy Date: Thu, 2 Dec 2021 12:19:47 +0900 Subject: [PATCH 4/4] fix Signed-off-by: harupy --- .github/workflows/autoformat.js | 11 +++++++---- .github/workflows/autoformat.yml | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/autoformat.js b/.github/workflows/autoformat.js index 0955e7953c9f5..e4051a8cf76da 100644 --- a/.github/workflows/autoformat.js +++ b/.github/workflows/autoformat.js @@ -17,14 +17,17 @@ const createStatus = async (context, github, core) => { const { owner, repo } = context.repo; const pull_number = context.issue.number; const pr = await github.pulls.get({ owner, repo, pull_number }); - const { sha, ref } = pr.data.head; - const repository = pr.data.repo.full_name; + const { + sha, + ref, + repo: { full_name }, + } = pr.data.head; await createCommitStatus(context, github, sha, 'pending'); - if (repository === 'mlflow/mlflow' && ref === 'master') { + if (full_name === 'mlflow/mlflow' && ref === 'master') { core.setFailed('Running autoformat bot against master branch of mlflow/mlflow is not allowed.'); } return { - repository, + repository: full_name, pull_number, sha, ref, diff --git a/.github/workflows/autoformat.yml b/.github/workflows/autoformat.yml index 984aa4d218f0e..609bf6489137d 100644 --- a/.github/workflows/autoformat.yml +++ b/.github/workflows/autoformat.yml @@ -55,7 +55,7 @@ jobs: - name: Check diff id: check-diff run: | - repository="${{ needs.check-comment.outputs.repository }}" + repository="${{ github.repository }}" pull_number="${{ needs.check-comment.outputs.pull_number }}" changed_files="$(python dev/list_changed_files.py --repository $repository --pr-num $pull_number)" py_changed=$([[ -z $(echo "$changed_files" | grep '\.py$') ]] && echo "false" || echo "true")