Skip to content

Commit

Permalink
fix: add days old next to Last Commit Date
Browse files Browse the repository at this point in the history
  • Loading branch information
arminbro committed Nov 18, 2024
1 parent 632c82c commit abec4ea
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 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@v2.1.18
uses: arminbro/repo-pruner@v2.1.19
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Run Repo Pruner
uses: arminbro/repo-pruner@v2.1.18
uses: arminbro/repo-pruner@v2.1.19
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as core from '@actions/core';
import * as github from '@actions/github';
import { createOrUpdateSummaryIssue } from './utils/issueUtils';
import type { InactiveBranch } from './utils/types';
import { calculateThresholdDate } from './utils/dateUtils';
import type { InactiveBranch } from './types';

async function run() {
try {
Expand All @@ -23,8 +24,7 @@ async function run() {
const { owner, repo } = github.context.repo;

// Calculate the threshold date for inactivity
const thresholdDate = new Date();
thresholdDate.setDate(thresholdDate.getDate() - inactiveDays);
const thresholdDate = calculateThresholdDate(inactiveDays);

// List branches in the repository
const { data: branches } = await octokit.rest.repos.listBranches({
Expand Down Expand Up @@ -118,7 +118,7 @@ async function run() {
}

if (inactiveBranches.length > 0) {
await createOrUpdateSummaryIssue(owner, repo, inactiveBranches);
await createOrUpdateSummaryIssue(owner, repo, inactiveBranches, inactiveDays);
return;
}

Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions src/utils/dateUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function calculateDaysOld(lastCommitDate: string): number {
const now = new Date();
const lastCommit = new Date(lastCommitDate);
const diffTime = now.getTime() - lastCommit.getTime();
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24)); // Convert milliseconds to days

return diffDays;
}

export function calculateThresholdDate(inactiveDays: number) {
const thresholdDate = new Date();
thresholdDate.setDate(thresholdDate.getDate() - inactiveDays);

return thresholdDate;
}
10 changes: 6 additions & 4 deletions src/utils/issueUtils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as core from '@actions/core';
import * as github from '@actions/github';
import type { InactiveBranch } from './types';
import { calculateDaysOld } from './dateUtils';
import type { InactiveBranch } from '../types';

export async function createOrUpdateSummaryIssue(
owner: string,
repo: string,
inactiveBranches: InactiveBranch[]
inactiveBranches: InactiveBranch[],
inactiveDays: number
): Promise<void> {
// Get token
const token = process.env.GITHUB_TOKEN;
Expand All @@ -19,7 +21,7 @@ export async function createOrUpdateSummaryIssue(
// Create the new issue body
const issueBody = `### ${inactiveBranches.length} Inactive Branches
This is a list of branches that have been inactive beyond the specified threshold. If you are the creator of a branch, please review it and delete it if it is no longer needed.
This is a list of branches that have been inactive beyond the specified threshold (${inactiveDays} days). If you are the creator of a branch, please review it and delete it if it is no longer needed.
After reviewing and taking action, return to this page and check off either **Keep** or **Delete** for each branch to notify your team of your decision.
Expand All @@ -30,7 +32,7 @@ ${inactiveBranches
.map(
(branch) => `
#### Branch: [${branch.name}](https://github.com/${owner}/${repo}/branches/all?query=${branch.name})
_Last Commit Date:_ ${branch.lastCommitDate}
_Last Commit Date:_ ${branch.lastCommitDate} (${calculateDaysOld(branch.lastCommitDate)} days old)
_Creator:_ ${branch.creator === 'unknown' ? 'unknown' : `@${branch.creator}`}
_Status:_ ${branch.isMerged ? 'Merged' : 'Unmerged'}
_Pull Request:_ ${
Expand Down

0 comments on commit abec4ea

Please sign in to comment.