Skip to content

Commit

Permalink
chore: dn-rule 워크플로우 스크립트 작성 (#237)
Browse files Browse the repository at this point in the history
* chore: dn-rule 워크플로우 스크립트 작성

* chore: dn-rule 워크플로우 스크립트 수정

* chore: dn-rule 워크플로우 스크립트 수정

* chore: dn-rule 워크플로우 스크립트 수정

* chore: dn-rule 워크플로우 pull_request 적용 타입 수정
  • Loading branch information
5uhwann authored Jan 22, 2024
1 parent 742257d commit 2b7fdcb
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/dn-rule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: PR Label Automation
on:
pull_request:
types: [ opened ]
schedule:
- cron: '0 0 * * *' # 매일 자정에 실행

jobs:
update-labels:
runs-on: ubuntu-latest
steps:
- name: Check and Update PR Labels
uses: actions/github-script@v5
with:
script: |
const repo = context.repo;
const prNumber = context.payload.pull_request ? context.payload.pull_request.number : context.issue.number;
// PR 레이블 가져오기
const { data: pr } = await github.rest.pulls.get({
owner: repo.owner,
repo: repo.repo,
pull_number: prNumber,
});
let labels = pr.labels.map(label => label.name);
const hasDLabel = labels.some(label => label.startsWith("D-"));
// 'D-' 레이블이 없는 경우 'D-5' 레이블 추가
if (!hasDLabel) {
await github.rest.issues.addLabels({
owner: repo.owner,
repo: repo.repo,
issue_number: prNumber,
labels: ['D-5'],
});
console.log("Added D-5 label to PR");
}
// 'D-x' 레이블 확인 및 업데이트
for (let label of labels) {
if (label.startsWith("D-") && label !== "D-0") {
let day = parseInt(label.split("-")[1]);
if (day > 0) {
let newLabel = `D-${day - 1}`;
// 먼저 기존 레이블을 제거
await github.rest.issues.removeLabel({
owner: repo.owner,
repo: repo.repo,
issue_number: prNumber,
name: label,
});
// 새 레이블 추가
await github.rest.issues.addLabels({
owner: repo.owner,
repo: repo.repo,
issue_number: prNumber,
labels: [newLabel],
});
console.log(`Updated label from ${label} to ${newLabel}`);
}
if (day === 1) {
// 'D-0' 처리 로직
}
break;
}
}

0 comments on commit 2b7fdcb

Please sign in to comment.