Skip to content

Commit 9279add

Browse files
feat: add repository-elapsed-time action (#58)
1 parent 39d1365 commit 9279add

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Repository Elapsed Time :package:
2+
3+
A GitHub Action that checks the time since the repository was created and returns it in multiple formats.
4+
5+
## Outputs 📤
6+
7+
| Name | Description |
8+
| ---------------- | ------------------------------------------------------------------------------------------------------------------- |
9+
| `minutes` | Number of minutes since repository creation |
10+
| `human-readable` | Human readable time since repository creation (e.g., "5 days and 12 hours", "3 hours and 45 minutes", "30 minutes") |
11+
12+
## Usage 🚀
13+
14+
```yaml
15+
steps:
16+
- name: Check repository age
17+
id: repo-age
18+
uses: skills/exercise-toolkit/actions/repository-elapsed-time@<git-tag>
19+
20+
- name: Use the outputs
21+
run: |
22+
echo "Repository is ${{ steps.repo-age.outputs.human-readable }} old"
23+
echo "Minutes: ${{ steps.repo-age.outputs.minutes }}"
24+
25+
- name: Run step if repository is older than 1 hour
26+
if: steps.repo-age.outputs.minutes > 60
27+
run: |
28+
echo "This repository has been around for more than an hour!"
29+
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: "Repository Elapsed Time"
2+
description: "Checks the time since the repository was created and returns it in multiple formats"
3+
outputs:
4+
minutes:
5+
description: "Number of minutes since repository creation"
6+
value: ${{ steps.calculate-time.outputs.minutes }}
7+
human-readable:
8+
description: "Human readable time since repository creation"
9+
value: ${{ steps.calculate-time.outputs.human-readable }}
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Calculate repository elapsed time
14+
id: calculate-time
15+
uses: actions/github-script@v7
16+
with:
17+
script: |
18+
const { data: repo } = await github.rest.repos.get({
19+
owner: context.repo.owner,
20+
repo: context.repo.repo
21+
});
22+
23+
const createdAt = new Date(repo.created_at);
24+
const now = new Date();
25+
const diffMs = now - createdAt;
26+
27+
// Calculate different time units
28+
const minutes = Math.floor(diffMs / (1000 * 60));
29+
const hours = Math.floor(diffMs / (1000 * 60 * 60));
30+
const days = Math.floor(diffMs / (1000 * 60 * 60 * 24));
31+
32+
// Create human readable format
33+
let humanReadable;
34+
if (days > 0) {
35+
const remainingHours = hours % 24;
36+
humanReadable = `${days} day${days > 1 ? 's' : ''} and ${remainingHours} hour${remainingHours !== 1 ? 's' : ''}`;
37+
} else if (hours > 0) {
38+
const remainingMinutes = minutes % 60;
39+
humanReadable = `${hours} hour${hours > 1 ? 's' : ''} and ${remainingMinutes} minute${remainingMinutes !== 1 ? 's' : ''}`;
40+
} else {
41+
humanReadable = `${minutes} minutes`;
42+
}
43+
44+
// Set outputs
45+
core.setOutput('minutes', minutes.toString());
46+
core.setOutput('human-readable', humanReadable);
47+
48+
console.log(`✅ Repository created: ${repo.created_at}`);
49+
console.log(`✅ Elapsed time: ${humanReadable} (${minutes} minutes)`);

0 commit comments

Comments
 (0)