Get Repo Metrics #43
This file contains hidden or 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
| name: Get Repo Metrics | |
| on: workflow_dispatch | |
| jobs: | |
| Repo-Metrics-Report: | |
| runs-on: ubuntu-latest | |
| environment: metrics | |
| if: github.actor != 'dependabot[bot]' | |
| permissions: | |
| pull-requests: read | |
| env: | |
| OWNER: ${{ github.repository_owner }} | |
| REPO: ${{ github.event.repository.name }} | |
| steps: | |
| - name: Check out the repository to the runner | |
| uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install Dependencies | |
| run: yarn install --immutable | |
| - name: Run Code Coverage Report | |
| run: yarn test:coverage | |
| - name: Get Merged PRs from the last two weeks | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh api graphql -f query=' | |
| query($owner: String!, $repo: String!) { | |
| repository(owner: $owner, name: $repo) { | |
| pullRequests( | |
| states: [MERGED], | |
| first: 25, | |
| orderBy: {field: UPDATED_AT, direction: DESC} | |
| ) { | |
| nodes { | |
| createdAt | |
| mergedAt | |
| } | |
| } | |
| } | |
| }' \ | |
| -f owner=$OWNER \ | |
| -f repo=$REPO > prs.json | |
| - name: Calculate Mean Time To Merge | |
| run: | | |
| jq -r ' | |
| .data.repository.pullRequests.nodes | | |
| reduce .[] as $pr ( | |
| {"total_prs": 0, "total_hours": 0}; | |
| . + { | |
| "total_prs": (.total_prs + 1), | |
| "total_hours": (.total_hours + (($pr.mergedAt | fromdateiso8601) - ($pr.createdAt | fromdateiso8601)) / 3600) | |
| } | |
| ) | | |
| { | |
| total_prs: .total_prs, | |
| average_hours: (if .total_prs > 0 then (.total_hours / .total_prs) else "N/A - No PRs found" end) | |
| } | | |
| "PR Metrics Summary: | |
| Total PRs: \(.total_prs) | |
| Average Time to Merge: \(.average_hours) hours" | |
| ' prs.json > metrics.txt | |
| - name: Format Coverage Report | |
| run: | | |
| echo "Code Coverage Report:" >> metrics.txt | |
| jq -r ' | |
| (.total | to_entries[] | "\(.key): \(.value)") | |
| ' coverage/coverage-final.json >> metrics.txt | |
| - name: Print Repo Metrics Report | |
| run: | | |
| echo "$OWNER $REPO Repo Metrics" | |
| cat metrics.txt |