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

[FEAT] 워크플로우 작성 #6

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 🚩 연관 이슈
closed #

# 🗣️ 리뷰 요구사항 (선택)
49 changes: 49 additions & 0 deletions .github/workflows/Auto_PR_Setting.yml
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}"
65 changes: 65 additions & 0 deletions .github/workflows/PR_Comment_Notification.yml
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
Loading