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 5c5dc38 commit 56a10b8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ on:
required: false
default: ${{ github.ref }}
type: string
outputs:
run_id:
description: The run id of the build action
value: ${{ jobs.build.outputs.run_id }}

jobs:
build:
name: Build
runs-on: ubuntu-latest
outputs:
run_id: ${{ steps.output_run_id.outputs.run_id }}
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
Expand Down Expand Up @@ -40,4 +46,7 @@ jobs:
uses: actions/upload-artifact@v4.3.1
with:
name: japanese
path: ./out/
path: ./out/
- name: Output run id
id: output_run_id
run: echo run_id=${{ github.run_id }} >> $GITHUB_OUTPUT
39 changes: 37 additions & 2 deletions .github/workflows/build_on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,47 @@ jobs:
run: gh pr diff ${{ fromJSON(needs.download_data.outputs.event_data).number }} --repo ${{ github.repository }} > ./out/diff.log
env:
GH_TOKEN: ${{ github.token }}
- name: Submit review
run: ../../node_modules/.bin/ts-node ./submit_review.ts ${{ github.token }} ${{ fromJSON(needs.download_data.outputs.event_data).number }} ${{ fromJSON(needs.download_data.outputs.event_data).pull_request.head.sha }} '${{ needs.test.outputs.test_1 }}' '${{ needs.test.outputs.test_2 }}'
- name: Create review data
run: ../../node_modules/.bin/ts-node ./submit_review.ts ${{ fromJSON(needs.download_data.outputs.event_data).pull_request.head.sha }} '${{ needs.test.outputs.test_1 }}' '${{ needs.test.outputs.test_2 }}'
working-directory: ./src/tests/
- name: Output review data
id: output_review
run: echo review_data=$(<./out/review.json) >> $GITHUB_OUTPUT
- name: Submit review
run: |
curl -L \
-X POST \
-H 'Accept: application/vnd.github+json' \
-H 'Authorization: Bearer ${{ github.token }}' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ fromJSON(needs.download_data.outputs.event_data).number }}/reviews \
-d '${{ steps.output_review.outputs.review_data }}'
build:
name: Build
needs:
- download_data
- review
if: ${{ fromJSON(needs.review.outputs.review_data).event == 'APPROVE' }}
uses: ./.github/workflows/build.yml
with:
ref: ${{ fromJSON(needs.download_data.outputs.event_data).pull_request.head.sha }}
comment:
name: Send comment
needs:
- download_data
- build
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Create comment file
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 }}
EOF
- name: Send comment
run: gh pr comment ${{ fromJSON(needs.download_data.outputs.event_data).number }} --body-file ./comment.txt --repo ${{ github.repository }}
request_review:
name: Request a review for the pull request to Gakuto1112
needs:
Expand Down
24 changes: 6 additions & 18 deletions src/tests/submit_review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ interface LineComment {
}

/**
* Botレビュー用のGitHub CLIを出力する。
* @param token Bot操作に使用するトークン
* @param pullNumber レビュー対象のプルリクエストの番号
* Botレビュー用のデータを出力する。
* @param commitId レビュー対象のコミットID
* @param test1ResultJson テスト1の結果を示すJSON形式の文字列
* @param test2ResultJson テスト2の結果を示すJSON形式の文字列
* @returns Botレビュー用のGitHub CLIコマンド
*/
async function generateAPIRequest(token: string, pullNumber: number, commitId: string, test1ResultJson: string, test2ResultJson: string): Promise<void> {
async function createReviewData(commitId: string, test1ResultJson: string, test2ResultJson: string): Promise<void> {
return new Promise(async (resolve: () => void) => {
const reviewOptions: ReviewOptions = {
commit_id: commitId,
Expand All @@ -70,7 +67,7 @@ async function generateAPIRequest(token: string, pullNumber: number, commitId: s
reviewOptions.body += testResults[1].points.map((point: TestPoint) => `- Line ${point.line}\n`).join("");
reviewOptions.body += "Please 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#翻訳のルールについて)";
reviewOptions.body += "For more information about tests, please see [CONTRIBUTING.md](https://github.com/Gakuto1112/Test/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.";

//ソースファイルへのレビューコメントを作成
Expand Down Expand Up @@ -119,20 +116,11 @@ async function generateAPIRequest(token: string, pullNumber: number, commitId: s
await generateLineComments();
}

//リクエスト送信
//レビューデータを出力
fs.writeFileSync("../../out/review.json", JSON.stringify(reviewOptions), {encoding: "utf-8"});
const response = await fetch(`https://api.github.com/repos/Gakuto1112/Stormworks-JapaneseTranslation/pulls/${pullNumber}/reviews`, {
method: "POST",
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${token}`,
"X-GitHub-Api-Version": "2022-11-28"
},
body: JSON.stringify(reviewOptions)
});
console.debug(response);

resolve();
});
}

generateAPIRequest(process.argv[2], Number(process.argv[3]), process.argv[4], process.argv[5], process.argv[6]);
createReviewData(process.argv[2], process.argv[3], process.argv[4]);

0 comments on commit 56a10b8

Please sign in to comment.