-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Update Repo Pruner to create summary issues for inactive branc…
…hes instead of opening pull requests This update fundamentally changes the workflow of Repo Pruner: - The action now scans inactive branches and creates a GitHub issue summarizing their status instead of opening pull requests for review. - Added a summary issue that includes details like branch name, last commit date, creator, status (merged/unmerged), and associated pull request (if any). - Protected branches are ignored. - Updated logging for improved clarity and more informative messages. - Removed PR creation logic and associated input options (`base_branch` and reviewer assignments). BREAKING CHANGES: - Repo Pruner no longer creates pull requests for inactive branches. Instead, it creates a single summary issue listing all inactive branches. - Removed `base_branch` input option as it is no longer applicable to the updated workflow. - Removed PR assignment functionality. To use the new version, update your GitHub workflow to reflect these changes. Refer to the updated README for more details.
- Loading branch information
Showing
5 changed files
with
210 additions
and
85 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
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 |
---|---|---|
@@ -1,21 +1,17 @@ | ||
name: "Repo Pruner" | ||
description: "Scans for inactive branches, opens PRs for review, and assigns branch creators as reviewers to merge or delete branches." | ||
description: "Scans for inactive branches and creates a summary issue listing their status (merged, unmerged, or without an associated PR) for review." | ||
author: "Armin Broubakarian" | ||
|
||
inputs: | ||
inactive_days: | ||
description: "Number of days since the last commit before a branch is considered inactive (default 30)" | ||
description: "Number of days since the last commit before a branch is considered inactive. Branches that haven't had commits in this time frame will be listed in the summary issue. Default is 30." | ||
required: false | ||
default: "30" | ||
base_branch: | ||
description: "Base branch used for the pull request (default 'main')" | ||
required: false | ||
default: "main" | ||
|
||
runs: | ||
using: 'node20' | ||
main: 'dist/index.js' | ||
|
||
branding: | ||
icon: git-branch | ||
color: green | ||
color: green |
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
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,74 @@ | ||
import * as core from '@actions/core'; | ||
import * as github from '@actions/github'; | ||
import type { InactiveBranch } from './types'; | ||
|
||
export async function createOrUpdateSummaryIssue( | ||
owner: string, | ||
repo: string, | ||
inactiveBranches: InactiveBranch[] | ||
): Promise<void> { | ||
// Get token | ||
const token = process.env.GITHUB_TOKEN; | ||
|
||
if (!token) { | ||
throw new Error('GITHUB_TOKEN environment variable is not set.'); | ||
} | ||
|
||
const octokit = github.getOctokit(token); | ||
const issueTitle = 'Repo Pruner: Inactive Branches Summary'; | ||
|
||
// Construct the issue body | ||
const tableHeader = ` | ||
| Branch | Last Commit Date | Creator | Status | Pull Request | | ||
|--------|------------------|---------|------------|--------------|`; | ||
|
||
const tableRows = inactiveBranches.map((branch) => { | ||
const status = branch.isMerged ? 'Merged' : 'Unmerged'; | ||
const prLink = branch.prNumber | ||
? `[PR #${branch.prNumber}](https://github.com/${owner}/${repo}/pull/${branch.prNumber})` | ||
: 'None'; | ||
|
||
return `| ${branch.name} | ${branch.lastCommitDate} | @${branch.creator} | ${status} | ${prLink} |`; | ||
}); | ||
|
||
const issueBody = `### Inactive Branches | ||
This is a list of branches that have been inactive based on the specified threshold. | ||
${tableHeader} | ||
${tableRows.join('\n')}`; | ||
|
||
// Check if an existing summary issue is open | ||
const { data: issues } = await octokit.rest.issues.listForRepo({ | ||
owner, | ||
repo, | ||
state: 'open', | ||
labels: 'Repo Pruner Summary', | ||
}); | ||
|
||
if (issues.length > 0) { | ||
// Update the existing issue | ||
const issueNumber = issues[0].number; | ||
|
||
await octokit.rest.issues.update({ | ||
owner, | ||
repo, | ||
issue_number: issueNumber, | ||
body: issueBody, | ||
}); | ||
|
||
core.info(`Updated existing summary issue #${issueNumber}`); | ||
return; | ||
} | ||
|
||
// Create a new summary issue | ||
await octokit.rest.issues.create({ | ||
owner, | ||
repo, | ||
title: issueTitle, | ||
body: issueBody, | ||
labels: ['Repo Pruner Summary'], | ||
}); | ||
|
||
core.info('Created a new summary issue for inactive branches.'); | ||
} |
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,18 @@ | ||
/** | ||
* Represents a single inactive branch's details. | ||
*/ | ||
export interface InactiveBranch { | ||
name: string; // The branch name | ||
lastCommitDate: string; // Formatted date of the last commit | ||
creator: string; // GitHub username of the branch creator | ||
isMerged: boolean; // Whether the branch is fully merged into the base branch | ||
prNumber?: number; // Optional field for the PR number | ||
} | ||
|
||
/** | ||
* General repository information. | ||
*/ | ||
export interface RepositoryInfo { | ||
owner: string; // The repository owner | ||
repo: string; // The repository name | ||
} |