0530

github PR setting 자동화도 했다
name: Auto PR Settingson: pull_request: types: [opened]permissions: contents: read pull-requests: write issues: write repository-projects: read statuses: read checks: readjobs: updatePullRequest: runs-on: ubuntu-latest steps: - name: Check out the repository uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.ref }} - name: Make changes to pull request run: date +%s > report.txt - name: Get branch names id: branch-names uses: tj-actions/branch-names@v8 - name: Get branch prefix id: get_branch_prefix if: steps.branch-names.outputs.is_default == 'false' run: | PREFIX=$(echo ${{ steps.branch-names.outputs.current_branch }} | awk -F'/' '{print toupper($1)}') echo "prefix=$PREFIX" >> $GITHUB_OUTPUT - name: Determine label based on base branch id: get_label run: | BASE_BRANCH=${{ github.event.pull_request.base.ref }} PREFIX=${{ steps.get_branch_prefix.outputs.PREFIX }} LABELS=() # Add the prefix as a label LABELS+=("$PREFIX") # Add the label based on the base branch if [[ "$BASE_BRANCH" == "develop" ]]; then LABELS+=("Develop") elif [[ "$BASE_BRANCH" == "staging" ]]; then LABELS+=("Staging") elif [[ "$BASE_BRANCH" == "main" ]]; then LABELS+=("Main") else LABELS+=("Unknown") fi # Join the labels with a comma LABEL_STRING=$(IFS=, ; echo "${LABELS[*]}") echo "labels=$LABEL_STRING" >> $GITHUB_OUTPUT - name: Select reviewers id: select_reviewers run: | ALL_REVIEWERS=("portlogics-mingyukwak" "portlogics-donghoon" "portlogics-leejiwon") ACTOR="${{ github.actor }}" SELECTED_REVIEWERS=() for REVIEWER in "${ALL_REVIEWERS[@]}"; do if [ "$REVIEWER" != "$ACTOR" ]; then SELECTED_REVIEWERS+=("$REVIEWER") fi done echo "reviewer1=${SELECTED_REVIEWERS[0]}" >> $GITHUB_OUTPUT echo "reviewer2=${SELECTED_REVIEWERS[1]}" >> $GITHUB_OUTPUT - name: Update PR title and body run: | gh pr edit ${{ github.event.pull_request.number }} \ --title "[${{ steps.get_branch_prefix.outputs.prefix }}]: ${{ github.event.pull_request.title }}" \ --body "${{ github.event.pull_request.body }}" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Add labels to PR run: | gh pr edit ${{ github.event.pull_request.number }} \ --add-label ${{ steps.get_label.outputs.labels }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Add assignees to PR run: | gh pr edit ${{ github.event.pull_request.number }} \ --add-assignee ${{ github.event.pull_request.user.login }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Add reviewers to PR run: | gh pr edit ${{ github.event.pull_request.number }} \ --add-reviewer ${{ steps.select_reviewers.outputs.reviewer1 }},${{ steps.select_reviewers.outputs.reviewer2 }} env: GH_TOKEN: ${{ secrets.KWAK_PAT }}