Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: 프로젝트에 PR 추가 후 status를 '처리대기'로 변경하는 워크플로우 추가 #6

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .github/workflows/project_automation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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
Loading