Skip to content

Commit

Permalink
Merge pull request #1120 from wakmusic/1112-none-develop-branch-suppo…
Browse files Browse the repository at this point in the history
…rt-auto-close-linked-issue

🔀 :: (#1112) develop이 아닌 브랜치를 대상으로 PR 머지 시 연관된 이슈 자동으로 close
  • Loading branch information
baekteun authored Aug 14, 2024
2 parents 2a2adfb + 739f577 commit 9dc5169
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
## 💡 배경 및 개요

<!--
> PR을 하게 된 문제상황, 배경 등 개요에 대해서 작성해주세요!
>
> 퍼블리싱의 경우 스크린샷/동영상도 추가해주면 좋아요!
-->

<!-- resolved issue 넘버 표기 방식 변경 시 '.github/actions/Auto_close_associate_issue/main.js' 또한 변경 필요 -->

Resolves: #{이슈번호}

## 📃 작업내용

<!--
> PR에서 한 작업을 자세히 작성해주세요!
-->

## 🙋‍♂️ 리뷰노트

<!--
> 구현 시에 고민이었던 점들 혹은 특정 부분에 대한 의도가 있었다면 PR 리뷰의 이해를 돕기 위해 서술해주세요!
>
> 또한 리뷰어에게 특정 부분에 대한 집중 혹은 코멘트 혹은 질문을 요청하는 경우에 작성하면 좋아요!
>
> e.g. 작업을 끝내야할 시간이 얼마 없어 확장성보다는 동작을 위주로 만들었어요! 감안하고 리뷰해주세요!
-->

## ✅ PR 체크리스트

<!--
> 템플릿 체크리스트 말고도 추가적으로 필요한 체크리스트는 추가해주세요!
-->

- [ ] 이 작업으로 인해 변경이 필요한 문서가 변경되었나요? (e.g. `XCConfig`, `노션`, `README`)
- [ ] 이 작업을 하고나서 공유해야할 팀원들에게 공유되었나요? (e.g. `"API 개발 완료됐어요"`, `"XCConfig 값 추가되었어요"`)
Expand Down
5 changes: 5 additions & 0 deletions .github/actions/Auto_close_associate_issue/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:20.14

COPY . .

CMD [ "node", "/main.js"]
16 changes: 16 additions & 0 deletions .github/actions/Auto_close_associate_issue/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Auto_close_associate_issue"

description: "Auto close an issue which associate with a PR."

inputs:
prbody:
description: "The body of the PR to search for related issues"
required: true

outputs:
issurNumber:
description: "The issue number"

runs:
using: "docker"
image: "Dockerfile"
16 changes: 16 additions & 0 deletions .github/actions/Auto_close_associate_issue/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let body = process.env["INPUT_PRBODY"];

/*
PR Template의 resolved issue 넘버 표기 방식 변경 시 해당 코드 또한 변경 필요
*/
let pattern = /Resolves: #\d+/;

let issueNumber;

try {
issueNumber = body.match(pattern)[0].replace("Resolves: #", "");
} catch {
issueNumber = -1;
}

console.log(`::set-output name=issueNumber::${issueNumber}`);
32 changes: 32 additions & 0 deletions .github/workflows/AutoCloseIssueByPullRequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Auto close issue when PR is merged

on:
pull_request_target:
branches-ignore: ["develop"]
types: [closed]
paths:
- "**/*.swift"

jobs:
close-issue:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true || github.event.action != 'closed'
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Run Auto issue closer
uses: ./.github/actions/Auto_close_associate_issue/
id: Closer
with:
prbody: ${{ github.event.pull_request.body }}

- name: Close Issue
uses: peter-evans/close-issue@v2
if: ${{ github.event.pull_request.merged }}
with:
issue-number: ${{ steps.Closer.outputs.issueNumber }}
comment: The associated PR has been merged, this issue is automatically closed, you can reopend if necessary. \#${{ github.event.pull_request.number }}
env:
Github_Token: ${{ secrets.GITHUB_TOKEN }}
PRNUM: ${{ github.event.pull_request.number }}

0 comments on commit 9dc5169

Please sign in to comment.