-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT] 워크플로우 작성
- Loading branch information
Showing
2 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Auto PR Setting | ||
|
||
on: | ||
pull_request: | ||
types: [opened] | ||
|
||
jobs: | ||
assign-issue: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set Auth Token | ||
run: echo "GH_TOKEN=${{ secrets.PERSONAL_ACCESS_TOKEN }}" >> $GITHUB_ENV | ||
|
||
- name: Get Issue Number | ||
id: get_issue | ||
run: | | ||
PR_DATA=$(gh pr view ${{ github.event.pull_request.number }} --json headRefName) | ||
echo "PR_DATA=${PR_DATA}" >> $GITHUB_ENV | ||
BRANCH_NAME=$(echo "${PR_DATA}" | jq -r '.headRefName') | ||
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV | ||
ISSUE_NUMBER=$(echo "${BRANCH_NAME}" | awk -F'#' '{print $2}' | grep -Eo '^[0-9]+') | ||
echo "ISSUE_NUMBER=${ISSUE_NUMBER}" >> $GITHUB_ENV | ||
- name: Get Issue Details | ||
id: get_issue_details | ||
run: | | ||
ISSUE_DATA=$(gh issue view "${ISSUE_NUMBER}" --json assignees,labels,projectItems --jq '{assignees: [.assignees[].login], labels: [.labels[].name], projects: [.projectItems[].title]}') | ||
echo "ISSUE_DATA=${ISSUE_DATA}" >> $GITHUB_ENV | ||
- name: Setting PR | ||
id: setting_pr | ||
run: | | ||
ASSIGNEES=$(echo "${ISSUE_DATA}" | jq -r '.assignees | join(",")') | ||
LABELS=$(echo "${ISSUE_DATA}" | jq -r '.labels | join(",")') | ||
PROJECTS=$(echo "${ISSUE_DATA}" | jq -r '.projects | join(",")') | ||
TEAM_MEMBERS=("unifolio0" "coli-geonwoo" "leegwichan") | ||
IFS=', ' read -r -a ASSIGNEE_ARRAY <<< "${ASSIGNEES}" | ||
REVIEWERS=() | ||
for MEMBER in "${TEAM_MEMBERS[@]}"; do | ||
if [[ ! " ${ASSIGNEE_ARRAY[@]} " =~ " ${MEMBER} " ]]; then | ||
REVIEWERS+=("${MEMBER}") | ||
fi | ||
done | ||
REVIEWER_LIST=$(IFS=', '; echo "${REVIEWERS[*]}") | ||
gh pr edit ${{ github.event.pull_request.number }} --add-assignee "${ASSIGNEES}" --add-label "${LABELS}" --add-reviewer "${REVIEWER_LIST}" --add-project "${PROJECTS}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Discord Notification on PR Comment | ||
|
||
on: | ||
issue_comment: | ||
types: [ created, edited ] | ||
|
||
jobs: | ||
notify-discord: | ||
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/noti') }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Set Environment Variables | ||
env: | ||
TITLE: ${{ github.event.issue.title }} | ||
run: | | ||
echo "AVATAR_URL=${{ secrets.DISCORD_AVATAR_URL }}" >> $GITHUB_ENV | ||
echo "COMMENT_BODY= 🤚백엔드 친구들 모여라~ 🔊" >> $GITHUB_ENV | ||
echo "USERNAME=망나뇽" >> $GITHUB_ENV | ||
echo "WEB_HOOK=${{ secrets.DISCORD_WEB_HOOK }}" >> $GITHUB_ENV | ||
- name: Notify Discord | ||
env: | ||
COMMENT_BODY: ${{ env.COMMENT_BODY }} | ||
COMMENT_AUTHOR: ${{ github.event.comment.user.login }} | ||
PR_URL: ${{ github.event.issue.pull_request.html_url }} | ||
AUTHOR_URL: ${{ github.event.comment.user.avatar_url }} | ||
AVATAR_URL: ${{ env.AVATAR_URL }} | ||
CONTENT: ${{ github.event.comment.body }} | ||
USERNAME: ${{ env.USERNAME }} | ||
WEB_HOOK: ${{ env.WEB_HOOK }} | ||
run: | | ||
if [ -n "$WEB_HOOK" ]; then | ||
JSON_PAYLOAD=$(jq -n \ | ||
--arg content "$CONTENT" \ | ||
--arg description "$COMMENT_BODY" \ | ||
--arg username "$USERNAME" \ | ||
--arg avatar_url "$AVATAR_URL" \ | ||
--arg title "Pull Request Command" \ | ||
--arg url "$PR_URL" \ | ||
--arg author_url "$AUTHOR_URL" \ | ||
--arg author_name "$COMMENT_AUTHOR" \ | ||
--arg color "5814783" \ | ||
--arg timestamp "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \ | ||
'{ | ||
content: $content, | ||
username: $username, | ||
avatar_url: $avatar_url, | ||
embeds: [{ | ||
title: $title, | ||
url: $url, | ||
author: { | ||
name: $author_name, | ||
icon_url: $author_url | ||
}, | ||
description: $description, | ||
color: ($color | tonumber), | ||
timestamp: $timestamp | ||
}] | ||
}') | ||
curl -X POST -H "Content-Type: application/json" -d "$JSON_PAYLOAD" "$WEB_HOOK" | ||
else | ||
echo "No matching title found. Skipping notification." | ||
fi |