Skip to content

Fix: 게시글 및 프로필 파일 관련 로직 보완 (#308) #165

Fix: 게시글 및 프로필 파일 관련 로직 보완 (#308)

Fix: 게시글 및 프로필 파일 관련 로직 보완 (#308) #165

name: Auto Delete Branch
on:
pull_request:
types: [ closed ]
jobs:
delete-branch:
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'dev'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# PR과 연관된 이슈들 닫기
- name: Close linked issues
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = context.payload.pull_request;
const text = `${pr.title}\n${pr.body || ''}`;
// 🔍 (#123) 같은 패턴 찾기
const issueMatches = [...text.matchAll(/\(#(\d+)\)/g)].map(m => m[1]);
if (issueMatches.length === 0) {
console.log('ℹ️ No linked issues found in PR');
} else {
for (const issueNumber of issueMatches) {
console.log(`✅ Closing issue #${issueNumber}`);
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: "closed"
});
}
}
// 🗑️ 병합된 브랜치 삭제 (main, dev 보호)
const headBranch = pr.head.ref;
const protectedBranches = ['main', 'dev'];
if (!protectedBranches.includes(headBranch)) {
console.log(`🗑️ Deleting branch: ${headBranch}`);
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${headBranch}`
});
} else {
console.log(`⚠️ Skipping deletion of protected branch: ${headBranch}`);
}