Skip to content

Commit

Permalink
fix: createOrUpdateSummaryIssue by correctly using checkboxes in the …
Browse files Browse the repository at this point in the history
…table
  • Loading branch information
arminbro committed Nov 17, 2024
1 parent 6f0b350 commit bc6b589
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/repo-pruner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Run Repo Pruner
uses: arminbro/repo-pruner@v1.0.4
uses: arminbro/repo-pruner@v2.1.5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- Displays the status of each branch (e.g., merged, unmerged).
- Includes links to associated pull requests or marks branches without PRs as "None."
- Provides a customizable inactivity threshold.
- Allows developers to mark branches as "Handled" or "Keep" via checkboxes for clear communication.
- Allows developers to mark branches as "Keep" or "Deleted" via checkboxes for clear communication.

## Usage
To use **Repo Pruner**, add it to your workflow file:
Expand All @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Run Repo Pruner
uses: arminbro/repo-pruner@v1.0.4
uses: arminbro/repo-pruner@v2.1.5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand All @@ -45,16 +45,16 @@ The action generates a GitHub issue summarizing all inactive branches. Each bran
- **Creator**: The username of the branch creator.
- **Status**: Indicates whether the branch has been merged into another branch or remains unmerged.
- **Pull Request**: A link to the associated pull request (if any) or "None" if no PR exists.
- **Handled or Keep**: Developers can mark a branch as either "Handled" (merged or deleted) or "Keep" (branch should not be deleted).
- **Keep or Deleted**: Developers can mark a branch as either "Keep" (branch should not be deleted) or "Deleted" (branch they have already deleted).

### Example Issue

```md
### Inactive Branches
This is a list of branches that have been inactive based on the specified threshold. Please check off either "Handled" or "Keep" for each branch.
This is a list of branches that have been inactive based on the specified threshold. Please check off either "Keep" or "Deleted" for each branch.
| Branch | Last Commit Date | Creator | Status | Pull Request | Handled | Keep |
| Branch | Last Commit Date | Creator | Status | Pull Request | Keep | Deleted |
|---------|-------------------|----------|---------|---------------|----------|-------|
| `feature-1` | 11/01/2024 | @johndoe | Merged | [PR #42](#) | [ ] | [ ] |
| `hotfix-123` | 10/15/2024 | @janedoe | Unmerged | None | [ ] | [ ] |
Expand Down
22 changes: 11 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30099,8 +30099,8 @@ async function createOrUpdateSummaryIssue(owner, repo, inactiveBranches) {
state: 'open',
labels: 'Repo Pruner Summary',
});
let handledBranches = new Set();
let keepBranches = new Set();
let deletedBranches = new Set();
if (issues.length > 0) {
// Retrieve the existing issue details
const issueNumber = issues[0].number;
Expand All @@ -30121,35 +30121,35 @@ async function createOrUpdateSummaryIssue(owner, repo, inactiveBranches) {
if (columns.length >= 7) {
// Extract the branch name from the second column (index 1)
const branchName = columns[1].replace(/`/g, ''); // Remove backticks
// Check the "Handled" and "Keep" columns for checkboxes
const handledChecked = columns[5] === '[x]';
const keepChecked = columns[6] === '[x]';
// Check the "Keep" and "Deleted" columns for checkboxes
const keepChecked = columns[5] === '[x]';
const deletedChecked = columns[6] === '[x]';
// Add the branch to the appropriate set
if (handledChecked) {
handledBranches.add(branchName);
}
if (keepChecked) {
keepBranches.add(branchName);
}
if (deletedChecked) {
deletedBranches.add(branchName);
}
}
}
}
core.info(`Found existing summary issue #${issueNumber} with previous branch statuses.`);
}
// Create the new issue body in table format with preserved check states
const tableHeader = `
| Branch | Last Commit Date | Creator | Status | Pull Request | Handled | Keep |
|--------|------------------|---------|--------|--------------|---------|------|`;
| Branch | Last Commit Date | Creator | Status | Pull Request | Keep | Deleted |
|--------|------------------|---------|--------|--------------|------|---------|`;
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} | [${handledBranches.has(branch.name) ? 'x' : ' '}] | [${keepBranches.has(branch.name) ? 'x' : ' '}] |`;
return `| \`${branch.name}\` | ${branch.lastCommitDate} | @${branch.creator} | ${status} | ${prLink} | <li>- [${keepBranches.has(branch.name) ? 'x' : ' '}]</li> | <li>- [${deletedBranches.has(branch.name) ? 'x' : ' '}]</li> |`;
});
const issueBody = `### Inactive Branches

This is a list of branches that have been inactive based on the specified threshold. Please check off either "Handled" or "Keep" for each branch.
This is a list of branches that have been inactive based on the specified threshold. Please check off either "Keep" or "Deleted" for each branch.

${tableHeader}
${tableRows.join('\n')}`;
Expand Down
22 changes: 11 additions & 11 deletions src/utils/issueUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export async function createOrUpdateSummaryIssue(
labels: 'Repo Pruner Summary',
});

let handledBranches = new Set<string>();
let keepBranches = new Set<string>();
let deletedBranches = new Set<string>();

if (issues.length > 0) {
// Retrieve the existing issue details
Expand All @@ -52,17 +52,17 @@ export async function createOrUpdateSummaryIssue(
// Extract the branch name from the second column (index 1)
const branchName = columns[1].replace(/`/g, ''); // Remove backticks

// Check the "Handled" and "Keep" columns for checkboxes
const handledChecked = columns[5] === '[x]';
const keepChecked = columns[6] === '[x]';
// Check the "Keep" and "Deleted" columns for checkboxes
const keepChecked = columns[5] === '[x]';
const deletedChecked = columns[6] === '[x]';

// Add the branch to the appropriate set
if (handledChecked) {
handledBranches.add(branchName);
}
if (keepChecked) {
keepBranches.add(branchName);
}
if (deletedChecked) {
deletedBranches.add(branchName);
}
}
}
}
Expand All @@ -72,21 +72,21 @@ export async function createOrUpdateSummaryIssue(

// Create the new issue body in table format with preserved check states
const tableHeader = `
| Branch | Last Commit Date | Creator | Status | Pull Request | Handled | Keep |
|--------|------------------|---------|--------|--------------|---------|------|`;
| Branch | Last Commit Date | Creator | Status | Pull Request | Keep | Deleted |
|--------|------------------|---------|--------|--------------|------|---------|`;

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} | [${handledBranches.has(branch.name) ? 'x' : ' '}] | [${keepBranches.has(branch.name) ? 'x' : ' '}] |`;
return `| \`${branch.name}\` | ${branch.lastCommitDate} | @${branch.creator} | ${status} | ${prLink} | <li>- [${keepBranches.has(branch.name) ? 'x' : ' '}]</li> | <li>- [${deletedBranches.has(branch.name) ? 'x' : ' '}]</li> |`;
});

const issueBody = `### Inactive Branches
This is a list of branches that have been inactive based on the specified threshold. Please check off either "Handled" or "Keep" for each branch.
This is a list of branches that have been inactive based on the specified threshold. Please check off either "Keep" or "Deleted" for each branch.
${tableHeader}
${tableRows.join('\n')}`;
Expand Down

0 comments on commit bc6b589

Please sign in to comment.