Skip to content

Commit

Permalink
自動レビューシステムを色々変更
Browse files Browse the repository at this point in the history
  • Loading branch information
Gakuto1112 committed Apr 7, 2024
1 parent f0eac9a commit da265a1
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 69 deletions.
35 changes: 31 additions & 4 deletions .github/workflows/build_on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 \
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/build_on_pull_request_trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
25 changes: 3 additions & 22 deletions .github/workflows/comment_when_changes_requested.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
uses: Gakuto1112/PublicPullRequestWorkflows/.github/workflows/comment_when_changes_requested_core.yml@main
16 changes: 13 additions & 3 deletions .github/workflows/comment_when_changes_requested_trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
17 changes: 0 additions & 17 deletions .github/workflows/request_review.yml

This file was deleted.

14 changes: 0 additions & 14 deletions .github/workflows/request_review_trigger.yml

This file was deleted.

13 changes: 6 additions & 7 deletions src/tests/submit_review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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")
});
Expand Down

0 comments on commit da265a1

Please sign in to comment.