Skip to content

leadtime - caluculate GitHub PR lead time statistics

License

Notifications You must be signed in to change notification settings

nao1215/leadtime

Repository files navigation

Coverage Test Execution Time Go Report Card reviewdog LinuxUnitTest MacUnitTest WindowsUnitTest

leadtime - calculate GitHub PR lead time statistics

|------------- lead time -------------|
|               |--- time to merge ---|
---------------------------------------
^               ^                     ^
first commit    create PR          merge PR

leedtime is a command that outputs statistics about the time it takes for a GitHub Pull Request to be merged. The leadtime command was developed under the influence of the following books.

The motivation for developing the leadtime command is to measure lead time for changes. I previously used unit test coverage as a measure of software quality. However, I felt that unless we wrote creative tests and rewrote the code, test coverage would increase but quality would not improve.

Therefore, I considered measuring lead time, one of the indicators presented in the above book.

How to install

Use "go install"

If you does not have the golang development environment installed on your system, please install golang from the golang official website.

 go install github.com/nao1215/leadtime@latest

Use homebrew (aarch64)

$ brew tap nao1215/tap
$ brew install nao1215/tap/leadtime

How to use

Usage

Usage:
  leadtime stat [flags]

Examples:
  LT_GITHUB_ACCESS_TOKEN=XXX leadtime stat --owner=nao1215 --repo=sqly

Flags:
  -a, --all                    Print all data used for statistics
  -B, --exclude-bot            Exclude Pull Requests created by bots
  -P, --exclude-pr ints        Exclude specified Pull Requests (e.g. '-P 1,3,19')
  -U, --exclude-user strings   Exclude Pull Requests created by specified user (e.g. '-U nao,alice')
  -h, --help                   help for stat
  -j, --json                   Output json
  -m, --markdown               Output markdown
  -o, --owner string           Specify GitHub owner name
  -r, --repo string            Specify GitHub repository name

Execution example

You need to set GitHub access token in environment variable "LT_GITHUB_ACCESS_TOKEN". If you want to check github.com/nao1215/sqly repository, you execute bellow.

$ leadtime stat --owner=nao1215 --repo=sqly
[statistics]
 Total PR       = 28
 Lead Time(Max) = 21144[min]
 Lead Time(Min) = 1[min]
 Lead Time(Sum) = 35310[min]
 Lead Time(Ave) = 1261.07[min]
 Lead Time(Median) = 66.50[min]

json format output

If you change output format to json, you use --json option.

$ leadtime stat --owner=nao1215 --repo=sqly --json | jq .
{
  "total_pr": 28,
  "lead_time_maximum": 21144,
  "lead_time_minimum": 1,
  "lead_time_summation": 35310,
  "lead_time_average": 1261.0714285714287,
  "lead_time_median": 66.5
}

markdown format output

If you change output format to markdown, you use --markdown option. Markdown output sample is here.

$ leadtime stat --owner=nao1215 --repo=gup --markdown

If you use --markdown, leadtime command output lead time line graph, like this. PR Lead Time

PR information used in statistics

If you want to check PR information used in statistics, you use --all option. The --all option is available for all output formats (json, markdown, default).

$ leadtime stat --owner=nao1215 --repo=sqly --json --all | jq .
{
  "lead_time_statistics": {
    "total_pr": 28,
    "lead_time_maximum": 21144,
    "lead_time_minimum": 1,
    "lead_time_summation": 35310,
    "lead_time_average": 1261.0714285714287,
    "lead_time_median": 66.5
  },
  "pull_requests": [
    {
      "number": 29,
      "state": "closed",
      "title": "Bump github.com/fatih/color from 1.13.0 to 1.14.1",
      "first_commit_at": "2023-01-23T20:21:58Z",
      "created_at": "2023-02-07T12:46:37Z",
      "closed_at": "2023-02-07T12:46:37Z",
      "merged_at": "2023-02-07T12:46:37Z",
      "user": {
        "name": "dependabot[bot]",
        "Bot": true
      },
      "merge_time_minutes": 21144
    },
    {
      "number": 28,
      "state": "closed",
      "title": "Change golden pacakge import path",
      "first_commit_at": "2022-12-03T09:48:37Z",
      "created_at": "2022-12-03T10:01:18Z",
      "closed_at": "2022-12-03T10:01:18Z",
      "merged_at": "2022-12-03T10:01:18Z",
      "user": {
        "name": "nao1215",
        "Bot": false
      },
      "merge_time_minutes": 12
    },
    ~~
    ~~

Exclude PRs

  • --exclude-bot option: Exclude Pull Requests created by bots

    leadtime stat --owner=nao1215 --repo=gup --exclude-bot
    
  • --exclude-pr option: Exclude specified Pull Requests

    leadtime stat --owner=nao1215 --repo=gup --exclude-pr=1,3,11
    
  • --exclude-user option: Exclude Pull Requests created by specified user

    leadtime stat --owner=nao1215 --repo=gup --exclude-user=nao,mio
    

Features to be added

The leadtime command is targeted to be combined with a GitHub action to be able to look back at statistical data on GitHub. I also plan to make it possible to output the information necessary to shorten leadtime.

  • CSV output format
  • JSON output format
  • Markdown file output
  • Output to file
  • Supports GitHub Actions
  • Exclude the bot's PR
  • faster by goroutine

Contributing / Contact

First off, thanks for taking the time to contribute! heart Contributions are not only related to development. For example, GitHub Star motivates me to develop!

Star History Chart

If you would like to send comments such as "find a bug" or "request for additional features" to the developer, please use one of the following contacts.

Other project

LICENSE

The leadtime project is licensed under the terms of MIT LICENSE.