Skip to content

Commit

Permalink
chore: PR 추가 후 status를 변경하는 워크플로우 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
uwoobeat committed Nov 24, 2023
1 parent 83f57c2 commit f72614b
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/project_automation.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f72614b

Please sign in to comment.