-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67d73b7
commit 5c906d0
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Close PRs Without Linked Issues | ||
|
||
on: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
close_prs_without_issue: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check and Close PRs Without Linked Issues | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # This ensures that git history is fully fetched for proper processing | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Close PRs Without Linked Issues | ||
run: | | ||
const daysThreshold = 30; | ||
const github = require('@actions/github'); | ||
const octokit = new github.GitHub(process.env.GITHUB_TOKEN); | ||
const owner = github.context.repo.owner; | ||
const repo = github.context.repo.repo; | ||
const { data: pullRequests } = await octokit.pulls.list({ owner, repo, state: 'open' }); | ||
for (const pr of pullRequests) { | ||
const { data: issues } = await octokit.issues.listForRepo({ owner, repo, per_page: 100 }); | ||
const linkedIssue = issues.find(issue => | ||
issue.pull_request && issue.pull_request.url === pr.url | ||
); | ||
if (!linkedIssue) { | ||
await octokit.pulls.update({ owner, repo, pull_number: pr.number, state: 'closed' }); | ||
await octokit.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number: pr.number, | ||
body: "This pull request has been closed because it does not mention the issue that it solves. Please refer to the [Contributing files](https://github.com/Akshat111111/Hedging-of-Financial-Derivatives/blob/main/contributing.md) to help you add this information. Then, tag the maintainers so your PR can be reopened." | ||
}); | ||
} | ||
} |