Skip to content

Commit

Permalink
Merge pull request #9 from nao1215/output-jsonformat
Browse files Browse the repository at this point in the history
Add --json option and completion sub command
  • Loading branch information
nao1215 authored Mar 5, 2023
2 parents f33ce30 + e6d112d commit 86e9756
Show file tree
Hide file tree
Showing 8 changed files with 674 additions and 241 deletions.
130 changes: 89 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
[![MacUnitTest](https://github.com/nao1215/leadtime/actions/workflows/mac_test.yml/badge.svg)](https://github.com/nao1215/leadtime/actions/workflows/mac_test.yml)
[![WindowsUnitTest](https://github.com/nao1215/leadtime/actions/workflows/windows_test.yml/badge.svg)](https://github.com/nao1215/leadtime/actions/workflows/windows_test.yml)
# leadtime - calculate PR lead time statistics on GitHub
```
|------------- 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.
- Eng: [Accelerate: The Science of Lean Software and DevOps: Building and Scaling High Performing Technology Organizations](https://www.amazon.com/dp/1942788339/ref=cm_sw_r_cp_ep_dp_sBN8BbGC11MBS)
- JP: [LeanとDevOpsの科学[Accelerate]](https://www.amazon.co.jp/Lean%E3%81%A8DevOps%E3%81%AE%E7%A7%91%E5%AD%A6%EF%BC%BBAccelerate%EF%BC%BD-%E3%83%86%E3%82%AF%E3%83%8E%E3%83%AD%E3%82%B8%E3%83%BC%E3%81%AE%E6%88%A6%E7%95%A5%E7%9A%84%E6%B4%BB%E7%94%A8%E3%81%8C%E7%B5%84%E7%B9%94%E5%A4%89%E9%9D%A9%E3%82%92%E5%8A%A0%E9%80%9F%E3%81%99%E3%82%8B-impress-top-gear%E3%82%B7%E3%83%AA%E3%83%BC%E3%82%BA-ebook/dp/B07L2R3LTN)

The motivation for developing the leadtime command is to measure lead time for changes. I used unit test coverage as a measure of software quality. However, as the number of unit tests increased but the code was not rewritten, I questioned whether the quality was improving.
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.

Expand All @@ -37,10 +44,12 @@ 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
Expand All @@ -50,36 +59,6 @@ Flags:
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
PR Author Bot LeadTime[min] Title
#29 dependabot[bot] yes 21144 Bump github.com/fatih/color from 1.13.0 to 1.14.1
#28 nao1215 no 12 Change golden pacakge import path
#27 nao1215 no 17 add unit test for infra package
#26 nao1215 no 686 Add basic unit test for shell
#25 dependabot[bot] yes 1850 Bump github.com/google/go-cmp from 0.2.0 to 0.5.9
#24 nao1215 no 6458 Add unit test for model package
#23 nao1215 no 187 Change golden test package from goldie to golden and more
#22 nao1215 no 1 Add sqlite3 syntax completion
#21 nao1215 no 1769 Add unit test for argument paser
#20 nao1215 no 53 Feat dump tsv ltsv json
#19 nao1215 no 6 Add featuer thar print date by markdown table format
#18 nao1215 no 10 Feat import ltsv
#17 nao1215 no 117 Feat import tsv
#15 nao1215 no 57 Fix panic bug when import file that is without extension
#14 nao1215 no 42 Feat import json
#13 nao1215 no 139 Fix input delays when increasing records
#12 nao1215 no 18 Add header command
#11 nao1215 no 1552 Fixed a display collapse problem when multiple lines are entered
#10 nao1215 no 4 Fixed a bug that caused SQL to fail if there was a trailing semicolon
#9 nao1215 no 29 Add move cursor function in intaractive shell
#8 nao1215 no 3 Fixed a bug in which the wrong arguments were used
#7 nao1215 no 76 Added CSV output mode
#6 nao1215 no 222 Improve execute query
#5 nao1215 no 498 Add history usecase, repository, infra. sqly manage history by sqlite3
#4 nao1215 no 139 Add function that execute select query
#3 nao1215 no 37 Add import command
#2 nao1215 no 57 Add .tables command
#1 nao1215 no 127 Add .exit/.help command and history manager
[statistics]
Total PR = 28
Lead Time(Max) = 21144[min]
Expand All @@ -89,6 +68,76 @@ PR Author Bot LeadTime[min] Title
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](doc/sample_leadtime.md).
```
$ leadtime stat --owner=nao1215 --repo=gup --markdown
```

If you use --markdown, leadtime command output lead time line graph, like this.
![PR Lead Time](./doc/leadtime.png)

### 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
```
Expand All @@ -105,18 +154,10 @@ PR Author Bot LeadTime[min] Title
leadtime stat --owner=nao1215 --repo=gup --exclude-user=nao,mio
```

### markdown format output
If you change output format to markdown, you use --markdown option. Markdown output sample is [here](doc/sample_leadtime.md).
```
$ leadtime stat --owner=nao1215 --repo=gup --markdown
```

If you use --markdown, leadtime command output lead time line graph, like this.
![PR Lead Time](./doc/leadtime.png)

## 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
- [x] JSON output format
- [ ] Markdown file output
- [ ] Output to file
- [ ] Supports GitHub Actions
Expand All @@ -132,5 +173,12 @@ First off, thanks for taking the time to contribute! heart Contributions are not
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.
- [GitHub Issue](https://github.com/nao1215/leadtime/issues)

## Other project
- [shibayu36/merged-pr-stat](https://github.com/shibayu36/merged-pr-stat)
- [isanasan/dmps](https://github.com/isanasan/dmps)
- [Trendyol/four-key](https://github.com/Trendyol/four-key)
- [hmiyado/four-keys](https://github.com/hmiyado/four-keys)


## LICENSE
The leadtime project is licensed under the terms of [MIT LICENSE](./LICENSE).
Loading

0 comments on commit 86e9756

Please # to comment.