|
| 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