Skip to content

Commit

Permalink
✨ 自动关闭关联commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkioTomas committed Apr 10, 2024
1 parent be96002 commit 189eaf2
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/issue-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Close Issue on Commit

on:
push:
branches:
- master


jobs:
close-issue:
runs-on: ubuntu-latest
steps:
- name: Check commit messages for issue references
id: commit-check
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const commits = await github.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
ref: process.env.GITHUB_SHA
});
for (const commit of commits.data) {
const match = commit.commit.message.match(/#(\d+)/);
if (match) {
console.log(`Found issue reference in commit: ${match[0]}`);
const issueNumber = parseInt(match[1]);
console.log(`Issue number: ${issueNumber}`);
await github.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: "closed"
});
console.log(`Issue ${issueNumber} closed`);
}
}

0 comments on commit 189eaf2

Please sign in to comment.