Skip to content

ci: add assign-reviewer job #529

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

Merged
merged 7 commits into from
Nov 10, 2024
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
25 changes: 25 additions & 0 deletions .github/workflows/automation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,28 @@ jobs:
- uses: actions/labeler@v5
with:
repo-token: ${{ github.token }}

assign-reviewer:
runs-on: ubuntu-latest
steps:
- name: Get previous PR author and assign as reviewer
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
current_repo=${{ github.repository }}
current_pr_num=${{ github.event.number }}

# 이전 PR 중에서 현재 PR 작성자와 다른 작성자 찾기
previous_pr_author=$(gh pr list --repo $current_repo \
--state all \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state 기본값"open" 이라 all 로 설정하였습니다
image

--search "created:<${{ github.event.pull_request.created_at }} sort:created-desc -author:${{ github.actor }}" \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 PR 이전에 생성된 PR 이어야 하므로, created: 조건을 추가하였습니다.
${{ github.event.created_at }} 는 따로 제공하는 변수가 아니라서 ${{ github.event.pull_request.created_at }} 를 사용했습니다.

--limit 3 \
--json number,author \
--jq "map(select(.number < $current_pr_num))[0].author.login")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$current_pr_num 를 ' 로 감싸면 문자열로 인식하여 '를 제거하였습니다.


if [ -n "$previous_pr_author" ]; then
gh pr edit $current_pr_num --repo $current_repo --add-reviewer $previous_pr_author
else
echo "❌ No previous PR author found to assign as reviewer"
exit 1
fi