From f72614baf43ec2aeca7de4a7176a7f528441afe3 Mon Sep 17 00:00:00 2001 From: uwoobeat Date: Fri, 24 Nov 2023 16:32:16 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20PR=20=EC=B6=94=EA=B0=80=20=ED=9B=84=20?= =?UTF-8?q?status=EB=A5=BC=20=EB=B3=80=EA=B2=BD=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=9B=8C=ED=81=AC=ED=94=8C=EB=A1=9C=EC=9A=B0=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/project_automation.yml | 105 +++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 .github/workflows/project_automation.yml diff --git a/.github/workflows/project_automation.yml b/.github/workflows/project_automation.yml new file mode 100644 index 000000000..9d08856df --- /dev/null +++ b/.github/workflows/project_automation.yml @@ -0,0 +1,105 @@ +name: Add PR to project as pending status + +on: + pull_request: + types: + - opened + +jobs: + track_pr: + runs-on: ubuntu-latest + steps: + # Github App을 사용하여 토큰 생성 + - name: Generate token + id: generate_token + uses: actions/create-github-app-token@v1 + with: + app_id: ${{ secrets.BOT_APP_ID }} + private_key: ${{ secrets.BOT_APP_PEM }} + + # Github CLI를 사용하여 프로젝트 ID 및 필드 정보를 조회 후 project_data.json 파일에 저장 + - name: Get project data + env: + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} + ORGANIZATION: depromeet + PROJECT_NUMBER: 49 + run: | + gh api graphql -f query=' + query($org: String!, $number: Int!) { + organization(login: $org){ + projectV2(number: $number) { + id + fields(first:20) { + nodes { + ... on ProjectV2Field { + id + name + } + ... on ProjectV2SingleSelectField { + id + name + options { + id + name + } + } + } + } + } + } + }' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json + + # json 파일에서 프로젝트 ID 및 필드 정보를 파싱하여 환경변수에 저장 + # 저장 필드 : 프로젝트 ID, Status 필드 ID, Status 필드의 Pending 옵션 ID + - name: Parse project data + run: | + echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV + echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV + echo 'PENDING_OPTION_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="처리 대기") |.id' project_data.json) >> $GITHUB_ENV + + # PR을 프로젝트에 추가 후 item_id를 환경변수에 저장 + - name: Add PR to project + env: + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} + PR_ID: ${{ github.event.pull_request.node_id }} + run: | + item_id="$( gh api graphql -f query=' + mutation($project:ID!, $pr:ID!) { + addProjectV2ItemById(input: {projectId: $project, contentId: $pr}) { + item { + id + } + } + }' -f project=$PROJECT_ID -f pr=$PR_ID --jq '.data.addProjectV2ItemById.item.id')" + + echo 'ITEM_ID='$item_id >> $GITHUB_ENV + + # 프로젝트에 추가된 PR의 item_id를 환경변수에서 읽어와 Status 필드의 값을 Pending으로 변경 + - name: Set status to pending + env: + GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} + run: | + gh api graphql -f query=' + mutation ( + $project: ID! + $item: ID! + $status_field: ID! + $status_value: String! + ) { + set_status: updateProjectV2ItemFieldValue(input: { + projectId: $project + itemId: $item + fieldId: $status_field + value: { + singleSelectOptionId: $status_value + } + }) { + projectV2Item { + id + } + }' + -f project=$PROJECT_ID + -f item=$ITEM_ID + -f status_field=$STATUS_FIELD_ID + -f status_value=$PENDING_OPTION_ID + --silent