Replies: 3 comments
-
Full code here: name: Close Inactive PRs
on:
schedule:
# Define the schedule for running the workflow (e.g., daily).
- cron: '0 0 * * *'
jobs:
close_inactive_prs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 14
- name: Install Dependencies
run: npm install github-api
- name: Close Inactive PRs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DAYS_INACTIVE: ${{ inputs.days_inactive }}
run: |
const { Octokit } = require("octokit");
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
// Calculate the date threshold.
const thresholdDate = new Date();
thresholdDate.setDate(thresholdDate.getDate() - process.env.DAYS_INACTIVE);
const owner = process.env.GITHUB_REPOSITORY.split("/")[0];
const repo = process.env.GITHUB_REPOSITORY.split("/")[1];
// Get the list of open PRs.
const response = await octokit.rest.pulls.list({
owner,
repo,
state: "open",
});
for (const pr of response.data) {
const prCreatedAt = new Date(pr.created_at);
if (prCreatedAt < thresholdDate) {
// Add a comment before closing the PR.
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: pr.number,
body: "This PR has been closed due to inactivity. Feel free to reopen if needed.",
});
// Close the PR.
await octokit.rest.pulls.update({
owner,
repo,
pull_number: pr.number,
state: "closed",
});
console.log(`Closed PR #${pr.number}: ${pr.title}`);
}
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
inputs:
days_inactive:
description: 'Number of days of inactivity before closing PRs'
required: true
default: 30 # You can adjust this default value.
|
Beta Was this translation helpful? Give feedback.
0 replies
-
name: Auto-close Inactive Pull Requests
on:
schedule:
- cron: '0 0 * * *' # Schedule the Action to run daily
jobs:
close_inactive_prs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 14
- name: Close Inactive PRs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ inputs.owner }}
REPO: ${{ inputs.repo }}
run: |
const { Octokit } = require("octokit");
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
// Calculate the date threshold.
const thresholdDate = new Date();
thresholdDate.setDate(thresholdDate.getDate() - parseInt(process.env.DAYS_INACTIVE, 10));
const owner = process.env.OWNER;
const repo = process.env.REPO;
// Get the list of open PRs.
const response = await octokit.rest.pulls.list({
owner,
repo,
state: "open",
});
for (const pr of response.data) {
const prCreatedAt = new Date(pr.created_at);
if (prCreatedAt < thresholdDate) {
// Add a comment before closing the PR.
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: pr.number,
body: "This PR has been closed due to inactivity. Feel free to reopen if needed.",
});
// Close the PR.
await octokit.rest.pulls.update({
owner,
repo,
pull_number: pr.number,
state: "closed",
});
console.log(`Closed PR #${pr.number}: ${pr.title}`);
}
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
inputs:
DAYS_INACTIVE:
description: 'Inactivity threshold (days)'
required: true
default: 30 # You can adjust this value.
owner:
description: 'Owner of the repository'
required: true
repo:
description: 'Name of the repository'
required: true
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Is this to much? or is auto closing okey? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Objective
The goal of this proposed GitHub Action is to simplify the process of managing open pull requests by automatically closing those that have been inactive for a specified number of days. The Action will also add a comment to inform contributors of the closure due to inactivity.
Implementation
Scheduled Automation: This Action will run on a schedule, such as daily, making it easy for maintainers to maintain a clean repository without manual intervention.
Customizable Inactivity Period: By using the
DAYS_INACTIVE
input parameter, maintainers can set the desired number of days of inactivity before a pull request is closed. This parameter is flexible and can be adjusted to match the repository's needs.Transparency: The Action will add a comment to the pull request just before closing it. This comment informs contributors that the pull request is being closed due to inactivity, giving them the opportunity to reopen it if necessary.
Example Usage
Create a workflow file (e.g.,
.github/workflows/close_inactive_prs.yml
) in your repository.Configure the workflow to use the proposed Action.
GITHUB_TOKEN
as a repository secret. This token is required for accessing the GitHub API within the workflow.With this Action, repository maintainers can effortlessly keep their repositories organized by automatically closing inactive pull requests, while also maintaining transparency through comment notifications. The customizable inactivity period ensures adaptability to project-specific needs.
Beta Was this translation helpful? Give feedback.
All reactions