diff --git a/.github/workflows/build_on_pull_request.yml b/.github/workflows/build_on_pull_request.yml index 7bf892b..50aedc0 100644 --- a/.github/workflows/build_on_pull_request.yml +++ b/.github/workflows/build_on_pull_request.yml @@ -78,7 +78,7 @@ jobs: needs: - download_data - review - if: ${{ fromJSON(needs.review.outputs.review_data).event == 'APPROVE' }} + if: ${{ fromJSON(needs.review.outputs.review_data).event == 'COMMENT' }} uses: ./.github/workflows/build.yml with: ref: ${{ fromJSON(needs.download_data.outputs.event_data).pull_request.head.sha }} @@ -95,19 +95,46 @@ jobs: run: | cat << EOF > ./comment.txt Finished building translation data. You can get it from the following link: - https://github.com/Gakuto1112/TestRepo/actions/runs/${{ needs.build.outputs.run_id }} + https://github.com/Gakuto1112/Stormworks-JapaneseTranslation/actions/runs/${{ needs.build.outputs.run_id }} EOF - name: Send comment run: gh pr comment ${{ fromJSON(needs.download_data.outputs.event_data).number }} --body-file ./comment.txt --repo ${{ github.repository }} + env: + GH_TOKEN: ${{ github.token }} request_review: name: Request a review for the pull request to Gakuto1112 needs: - download_data - review - if: ${{ fromJSON(needs.review.outputs.review_data).event == 'APPROVE' && fromJSON(needs.download_data.outputs.event_data).pull_request.user.login != 'Gakuto1112' }} + if: ${{ fromJSON(needs.review.outputs.review_data).event == 'COMMENT' && fromJSON(needs.download_data.outputs.event_data).pull_request.user.login != 'Gakuto1112' }} runs-on: ubuntu-latest + permissions: + pull-requests: write steps: - - name: Request a review for the pull request to ${{ inputs.reviewer }} + - name: Check requested reviewers + id: check_reviewers + continue-on-error: true + run: | + gh api \ + -H 'Accept: application/vnd.github+json' \ + -H 'X-GitHub-Api-Version: 2022-11-28' \ + /repos/${{ github.repository }}/pulls/${{ fromJSON(needs.download_data.outputs.event_data).number }}/requested_reviewers \ + | jq .users[].login | grep Gakuto1112 + env: + GH_TOKEN: ${{ github.token }} + - name: Check reviews + id: check_reviews + continue-on-error: true + run: | + gh api \ + -H 'Accept: application/vnd.github+json' \ + -H 'X-GitHub-Api-Version: 2022-11-28' \ + /repos/${{ github.repository }}/pulls/${{ fromJSON(needs.download_data.outputs.event_data).number }}/reviews \ + | jq .[].user.login | grep Gakuto1112 + env: + GH_TOKEN: ${{ github.token }} + - name: Request a review for the pull request to Gakuto1112 + if: ${{ steps.check_reviewers.outcome == 'failure' && steps.check_reviews.outcome == 'failure' }} run: | gh api \ --method POST \ diff --git a/.github/workflows/build_on_pull_request_trigger.yml b/.github/workflows/build_on_pull_request_trigger.yml index 2d3b7e8..2e398c4 100644 --- a/.github/workflows/build_on_pull_request_trigger.yml +++ b/.github/workflows/build_on_pull_request_trigger.yml @@ -3,12 +3,14 @@ name: Trigger "Review and build" action on: pull_request: types: - - review_requested + - opened + - ready_for_review + - synchronize jobs: call_workflow: name: Trigger "Review and build" action - if: ${{ github.event.requested_reviewer.login == 'github-actions[bot]' }} + if: ${{ github.event.requested_reviewer == null || github.event.requested_reviewer.login == 'github-actions[bot]' }} uses: Gakuto1112/PublicPullRequestWorkflows/.github/workflows/request_review_trigger_core.yml@main with: reviewer: github-actions[bot] \ No newline at end of file diff --git a/.github/workflows/comment_when_changes_requested.yml b/.github/workflows/comment_when_changes_requested.yml index 2763a13..245765a 100644 --- a/.github/workflows/comment_when_changes_requested.yml +++ b/.github/workflows/comment_when_changes_requested.yml @@ -8,27 +8,8 @@ on: - completed jobs: - comment: - if: ${{ github.event.workflow_run.conclusion == 'success' && fromJSON(steps.output_event_data.outputs.event_data).review.user.type == 'User' }} - runs-on: ubuntu-latest + call_workflow: + name: Call workflow permissions: pull-requests: write - steps: - - name: Download artifact - uses: dawidd6/action-download-artifact@v3.1.4 - with: - workflow: comment_when_changes_requested_trigger.yml - name: event_data - - name: Output event data - id: output_event_data - run: echo event_data=$(<./event_data.json) >> $GITHUB_OUTPUT - - name: Create comment file - run: | - cat << EOF > ./comment.txt - @${{ fromJSON(steps.output_event_data.outputs.event_data).pull_request.user.login }} - ${{ fromJSON(steps.output_event_data.outputs.event_data).review.user.login }} requested you to make some changes. Once you make changes, please re-request github-actions[bot] to review by clicking "re-request review" button 🔄 (located in the reviewers list on the right side of this page). - EOF - - name: Post comment - run: gh pr comment ${{ fromJSON(steps.output_event_data.outputs.event_data).pull_request.number }} --body-file ./comment.txt --repo ${{ github.repository }} - env: - GH_TOKEN: ${{ github.token }} \ No newline at end of file + uses: Gakuto1112/PublicPullRequestWorkflows/.github/workflows/comment_when_changes_requested_core.yml@main \ No newline at end of file diff --git a/.github/workflows/comment_when_changes_requested_trigger.yml b/.github/workflows/comment_when_changes_requested_trigger.yml index 55e65b1..f8a9e16 100644 --- a/.github/workflows/comment_when_changes_requested_trigger.yml +++ b/.github/workflows/comment_when_changes_requested_trigger.yml @@ -6,6 +6,16 @@ on: - submitted jobs: - call_workflow: - name: Call workflow - uses: Gakuto1112/PublicPullRequestWorkflows/.github/workflows/comment_when_changes_requested_trigger_core.yml@main \ No newline at end of file + get_data: + name: Get event data + if: ${{ github.event.review.state == 'changes_requested' && github.event.review.user.type != 'Bot' }} + runs-on: ubuntu-latest + steps: + - name: Get event data + run: echo '${{ toJSON(github.event) }}' > ./event_data.json + - name: Upload event data + uses: actions/upload-artifact@v4.3.1 + with: + name: event_data + path: ./event_data.json + retention-days: 1 \ No newline at end of file diff --git a/.github/workflows/request_review.yml b/.github/workflows/request_review.yml deleted file mode 100644 index 16af186..0000000 --- a/.github/workflows/request_review.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Request review - -on: - workflow_run: - workflows: - - Trigger "Request review to GitHub Actions" action - types: - - completed - -jobs: - call_workflow: - name: Request review to GitHub Actions - permissions: - pull-requests: write - uses: Gakuto1112/PublicPullRequestWorkflows/.github/workflows/request_review_core.yml@main - with: - reviewer: github-actions[bot] \ No newline at end of file diff --git a/.github/workflows/request_review_trigger.yml b/.github/workflows/request_review_trigger.yml deleted file mode 100644 index 1f90eb2..0000000 --- a/.github/workflows/request_review_trigger.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Trigger "Request review to GitHub Actions" action - -on: - pull_request: - types: - - opened - - ready_for_review - -jobs: - call_workflow: - name: Trigger "Request review to GitHub Actions" action - uses: Gakuto1112/PublicPullRequestWorkflows/.github/workflows/request_review_trigger_core.yml@main - with: - reviewer: github-actions[bot] \ No newline at end of file diff --git a/src/tests/submit_review.ts b/src/tests/submit_review.ts index 0bd3aaf..1fe8a50 100644 --- a/src/tests/submit_review.ts +++ b/src/tests/submit_review.ts @@ -47,28 +47,27 @@ async function createReviewData(commitId: string, test1ResultJson: string, test2 const reviewOptions: ReviewOptions = { commit_id: commitId, body: "## Test Results\n### Check prohibited characters\nThis test checks whether you use prohibited characters or not in your changes.\n\n**Result: ", - event: "APPROVE", + event: "COMMENT", comments: [] }; const testResults: TestResult[] = [JSON.parse(test1ResultJson), JSON.parse(test2ResultJson)]; //レビュー判定とコメントを作成 - reviewOptions.event = testResults[0].passed && testResults[1].passed ? "APPROVE" : "REQUEST_CHANGES"; + reviewOptions.event = testResults[0].passed && testResults[1].passed ? "COMMENT" : "REQUEST_CHANGES"; if(testResults[0].passed) reviewOptions.body += "🟢 Passed**\n\nNo prohibited character detected in your changes.\n\n"; else { reviewOptions.body += "🔴 Failed**\n\nOne or more prohibited characters detected in your changes. Lines that include prohibited characters are followings:\n"; reviewOptions.body += testResults[0].points.map((point: TestPoint) => `- Line ${point.line}\n`).join(""); - reviewOptions.body += "Please remove or replace them.\n\n"; + reviewOptions.body += "\nPlease remove or replace them.\n\n"; } reviewOptions.body += "### Check missing translations\nThis test checks whether there are one or more missing translations or not in your changes.\n\n**Result: "; if(testResults[1].passed) reviewOptions.body += "🟢 Passed**\n\nNo missing translation detected in your changes.\n\n"; else { reviewOptions.body += "🔴 Failed**\n\nOne or more missing translations detected in your changes. Lines whose translation is missing are followings:\n"; reviewOptions.body += testResults[1].points.map((point: TestPoint) => `- Line ${point.line}\n`).join(""); - reviewOptions.body += "Please fill all translations\n\n"; + reviewOptions.body += "\nPlease fill all translations\n\n"; } - reviewOptions.body += "For more information about tests, please see [CONTRIBUTING.md](https://github.com/Gakuto1112/Stormworks-JapaneseTranslation/blob/main/.github/CONTRIBUTING.md#翻訳のルールについて)"; - if(!testResults[0].passed || !testResults[1].passed) reviewOptions.body += "\n\nOnce you fixed your changes, please request me again by clicking \"re-request review\" button 🔄 (located in the reviewers list on the right side of this page). I\\'ll check your changes again."; + reviewOptions.body += "For more information about tests, please see [CONTRIBUTING.md](https://github.com/Gakuto1112/Stormworks-JapaneseTranslation/blob/main/.github/CONTRIBUTING.md#翻訳のルールについて)."; //ソースファイルへのレビューコメントを作成 if(reviewOptions.event == "REQUEST_CHANGES") { @@ -99,7 +98,7 @@ async function createReviewData(commitId: string, test1ResultJson: string, test2 testResults.forEach((result: TestResult) => linePoints = linePoints.concat(result.points.filter((point: TestPoint) => point.line == fileLineCounter))); if(linePoints.length > 0) { reviewOptions.comments.push({ - path: "/src/translation_data/japanese.tsv", + path: "src/translation_data/japanese.tsv", position: lineCounter, body: linePoints.map((point: TestPoint) => point.reason == ReasonCode.USED_PROHIBITED_CHARS ? "Used one or more prohibited characters in this line." : "A translation is missing in this line.").join("\n\n") });