47 Commits

Author SHA1 Message Date
Issy Long
c7b06df72e
dev-cmd/contributions: One --verbose sentence per user is enough 2023-02-22 23:05:02 +00:00
Issy Long
28a2a6ea43
utils/github: Add date filtering to the commit author API query
- I missed this off the original implementation - oops. This gives parity with
  the `git log` implementation.
2023-02-22 23:01:38 +00:00
Issy Long
1b3fa0bef7
Merge pull request #14768 from issyl0/contributions-fix-trailers-args
dev-cmd/contributions: Correctly order the trailers method args
2023-02-22 17:41:23 +00:00
Issy Long
0d345c4257
dev-cmd/contributions: Correctly order the trailers method args
- Was this a bad merge conflict resolution, or me not paying enough
  attention another time?
2023-02-22 17:24:13 +00:00
Issy Long
3d3369c542
dev-cmd/contributions.rb: odie
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2023-02-22 17:02:22 +00:00
Issy Long
d40bd0ae3e
dev-cmd/contributions: Fix single-user handling; be more verbose
- `brew contributions --user=issyl0` was taking forever because it went
  through all maintainers first, because the conditionals were in the
  wrong order.
- This was too quiet, far too quiet, for something that takes so long.
- Now verbose mode tells you what repos it's scanning for a user.
2023-02-22 16:48:31 +00:00
Issy Long
214110f665
dev-cmd/contributions: Stats for all maintainers
- With `brew contributions`, this will output a list of stats
  (across the specified time period, or all time) for people in the
  "maintainers" team on GitHub.
- Add a `--user` flag for getting stats for a specific user (either
  username, name or email address).
- This assumes that their Git committer details are the same as their name is
  set to on GitHub.
- Show an error message if trying to generate a CSV for the full maintainer
  list, since I haven't worked out how to best show all of that info yet (or
  even how best to show only the totals across everything for every user) in
  that format.
2023-02-22 16:05:58 +00:00
Issy Long
93ce211ebd
Merge pull request #14737 from issyl0/api-commits-for-person
dev-cmd/contributions: Use GitHub APIs for commit author info
2023-02-22 14:12:16 +00:00
Issy Long
0a6c59c0b3
dev-cmd/contributions: Less disgusting way to determine brew's NWO 2023-02-21 00:51:32 +00:00
Issy Long
d3827b12f2
dev-cmd/contributions: Use GitHub APIs for commit author info
- Using `git log` was brittle with name changes and email address changes for
  contributors over the years unless we made a Git `mailmap` file which brings
  with it its own updatedness overhead.
- Let's use the GitHub commits API (importantly _not_ the search API) so that
  we can give it a username and it will return contributions associated with
  every email address on that user's account:
  https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-commits--parameters.
- This is quite significantly slower, but it's worth it for correctness
  especially when we get to all maintainers' contributions (in a separate PR).
- The commits API does not (yet?) support trailers or commit "committer"s, just
  authors.
2023-02-20 23:24:54 +00:00
Mike McQuaid
37b4780037
dev-cmd/contributions: fix spacing.
Otherwise this fails the documentation lint.
2023-02-20 16:16:08 +00:00
Issy Long
04e476eb84
dev-cmd/contributions: Add --repositories=brew,core,cask shorthand
- For annual "has this person contributed enough", we focus on the main
  Homebrew repos: brew, core and cask. Let's make that easier than
  `--repositories=brew,core,cask`.
2023-02-19 18:36:13 +00:00
Issy Long
43a88cbd97
dev-cmd/contributions: Appease RuboCop 2023-02-15 14:04:05 +00:00
Issy Long
44edad85bc
dev-cmd/contributions: Add a grand total row to the CSV
```
$ brew contributions issyl0 --csv
The user issyl0 has made 1203 contributions in all time.
user,repo,commits,coauthorships,signoffs,total
issyl0,brew,333,13,0,346
issyl0,core,473,24,326,823
issyl0,cask,4,0,0,4
issyl0,aliases,0,0,0,0
issyl0,autoupdate,1,0,0,1
issyl0,bundle,14,2,0,16
issyl0,command-not-found,1,0,0,1
issyl0,test-bot,3,0,0,3
issyl0,services,9,0,0,9
issyl0,cask-drivers,0,0,0,0
issyl0,cask-fonts,0,0,0,0
issyl0,cask-versions,0,0,0,0
issyl0,*,*,*,*,1203
```
2023-02-15 14:00:05 +00:00
Issy Long
9aad9d011b
dev-cmd/contributions: Add a per-repo total column to the CSV
```
$ brew contributions issyl0 --csv
The user issyl0 has made 1202 contributions in all time.
user,repo,commits,coauthorships,signoffs,total
issyl0,brew,332,13,0,345
issyl0,core,473,24,326,823
issyl0,cask,4,0,0,4
issyl0,aliases,0,0,0,0
issyl0,autoupdate,1,0,0,1
issyl0,bundle,14,2,0,16
issyl0,command-not-found,1,0,0,1
issyl0,test-bot,3,0,0,3
issyl0,services,9,0,0,9
issyl0,cask-drivers,0,0,0,0
issyl0,cask-fonts,0,0,0,0
issyl0,cask-versions,0,0,0,0
```
2023-02-15 13:58:49 +00:00
Issy Long
2719c345ab
dev-cmd/contributions: CSV output of queried repos; shorter sentence
- This gives users of this command a `--csv` option to pass to... you guessed
  it, generate a CSV that's `pbcopy`able elsewhere, for more granular
  breakdowns of where a person contributed.
- Inspiration was taken from the mockup in
  https://github.com/Homebrew/brew/issues/13642#issuecomment-1254535251
  but without the extra dependency of the TerminalTable gem.
- Always print a condensed "total contributions" sentence.

Output:

```
$ brew contributions issyl0
The user issyl0 has made 1201 contributions in all time.

$ brew contributions issyl0 --csv
user,repo,commits,coauthorships,signoffs
issyl0,brew,331,13,0
issyl0,core,473,24,326
issyl0,cask,4,0,0
issyl0,aliases,0,0,0
issyl0,autoupdate,1,0,0
issyl0,bundle,14,2,0
issyl0,command-not-found,1,0,0
issyl0,test-bot,3,0,0
issyl0,services,9,0,0
issyl0,cask-drivers,0,0,0
issyl0,cask-fonts,0,0,0
issyl0,cask-versions,0,0,0
```
2023-02-15 12:47:10 +00:00
Issy Long
abe23fb249
dev-cmd/contributions: Add up different contribution types for a total
❯ brew contributions mikemcquaid
mikemcquaid directly authored 23766 commits, co-authored 241 commits, and signed-off 6730 commits across all Homebrew repos in all time. Total: 30737.
2023-02-14 10:51:13 +00:00
Issy Long
14f9a2424d
dev-cmd/contributions: Count commit signoffs, too
- `BrewTestBot` adds `Signed-off-by` for who approved PRs (1cf53b4281/Library/Homebrew/dev-cmd/pr-pull.rb (L91-L93)).
- Let's count these too, at least until we can get PR approvals from the GitHub API.
2023-02-11 12:01:12 +00:00
Issy Long
11d661c497
dev-cmd/contributions: Friendlier --repositories help text 2022-08-03 18:26:30 +01:00
Issy Long
4874602f25
dev-cmd/contributions: Better usage string & named args numbering
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2022-08-03 17:43:24 +01:00
Issy Long
0bb8a06193
dev-cmd/contributions: Revert to --repositories flag
- This doesn't require "all" to be specified as part of the command,
  it's the default, so usage is now just:

```
$ brew contributions "Issy Long"
$ brew contributions "Issy Long" --repositories=brew,core
$ brew contributions me@issyl0.co.uk --repositories=cask,bundle
```

- As we discussed in the PR review before, `comma_array` doesn't allow
  two names, so we can't (yet) do `comma_array "--repositories",
  "--repos"` like we can with `flag`. That's an enhancement for the future
  if we want to make the flags here less verbose. But now that "all" is
  the default, maybe less necessary.
2022-08-03 17:12:11 +01:00
Issy Long
31331663e4
dev-cmd/contributions: Don't have cask in SUPPORTED_REPOS twice
- Also stop skipping a "versions" repo. Since
  023261038192a4f55c95a4d2486873ec1c9a728a the
  `Homebrew/homebrew-cask-versions` tap won't get mistaken for
  `Homebrew/homebrew-versions` tap.
2022-08-03 16:54:01 +01:00
Issy Long
8c762d9687
dev-cmd/contributions: Improve Sorbet typing
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2022-08-03 16:54:00 +01:00
Issy Long
a7effbdd35
dev-cmd/contributions: Remove named arg names, unused
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2022-08-03 16:53:59 +01:00
Issy Long
5ecdf10e27
dev-cmd/contributions: Start output with the name/email
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2022-08-03 16:53:58 +01:00
Issy Long
0c7825accd
dev-cmd/contributions: Make the first arg either a name or email
- This is easier than mapping GitHub usernames to email addresses, when
  folks don't have email addresses always public on their GitHub
  profiles. Also, the users of this command (PLC members, other
  interested parties) don't have to remember folks' email addresses.
- It also gives better data for people who've changed their name over
  the years, and who commit with multiple email addresses (personal and
  work).

```
❯ brew contributions "Issy Long" all
Person Issy Long directly authored 687 commits and co-authored 33 commits across all Homebrew repos in all time.

❯ brew contributions "Rylan Polster" all
Person Rylan Polster directly authored 1747 commits and co-authored 133 commits across all Homebrew repos in all time.

❯ brew contributions me@issyl0.co.uk all
Person me@issyl0.co.uk directly authored 711 commits and co-authored 25 commits across all Homebrew repos in all time.

❯ brew contributions "Mike McQuaid" all
Person Mike McQuaid directly authored 26879 commits and co-authored 204 commits across all Homebrew repos in all time.
```
2022-08-03 16:53:57 +01:00
Issy Long
ae73f28d0f
dev-cmd/contributions: Use a named arg for required repositories
- This is apparently "more in-keeping with how we do required arguments
  (never requiring flags)" across Homebrew.
- New usage: `brew contributions me@issyl0.co.uk all`, `brew
  contributions me@issyl0.co.uk brew,core`
2022-08-03 16:53:56 +01:00
Issy Long
c02e03a179
dev-cmd/contributions: Use methods to get arguments
- I got these with hash syntax because I couldn't figure out Sorbet, but
  there's `args.rbi` to add the CLI args methods to. Nice!
- In doing this I realised that `--repositories` is required again, we
  no longer infer `--repositories=all` from no `--repositories` passed
  as we did in a previous version of this.
2022-08-03 16:53:55 +01:00
Issy Long
5d312d25d0
dev-cmd/contributions: Properly auto-tap 2022-08-03 16:53:54 +01:00
Issy Long
63a1a078b9
dev-cmd/contributions: Improve SUPPORTED_REPOS array syntax
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2022-08-03 16:53:53 +01:00
Issy Long
f5d5778186
dev-cmd/contributions: Use --repositories not --repos
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2022-08-03 16:53:52 +01:00
Issy Long
1ac1097203
dev-cmd/contributions: Better usage banner
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2022-08-03 16:53:51 +01:00
Issy Long
dd986f7705
dev-cmd/contributions: Use .to_sentence not .join(", ")
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2022-08-03 16:53:50 +01:00
Issy Long
6974faa29b
dev-cmd/contributions: Appease brew style 2022-08-03 16:53:49 +01:00
Issy Long
5fa192c261
dev-cmd/contributions: Use --repos=all not a separate --all flag 2022-08-03 16:53:48 +01:00
Issy Long
be08b773f1
dev-cmd/contributions: Add --all to scan everything, plus auto-tapping 2022-08-03 16:53:47 +01:00
Issy Long
8e5a5672fb
dev-cmd/contributions: Better shell argument handling, plus stop piping to grep 2022-08-03 16:53:46 +01:00
Issy Long
5a34bc86c4
dev-cmd/contributions: RuboCop has opinions on where spaces should go 2022-08-03 16:53:45 +01:00
Issy Long
70c300daf2
dev-cmd/contributions: Use Utils.safe_popen_read not backticks 2022-08-03 16:53:45 +01:00
Issy Long
f6b2fe5093
dev-cmd/contributions: Improve sentence string line wrapping
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2022-08-03 16:53:44 +01:00
Issy Long
33d3aef295
dev-cmd/contributions: Only one email is allowed currently
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2022-08-03 16:53:43 +01:00
Issy Long
8a67ce76b5
dev-cmd/contributions: Appease brew typecheck 2022-08-03 16:53:42 +01:00
Issy Long
441df3d866
dev-cmd/contributions: Switch --email to be a named arg
- This way we can do the more intuitive:

```
$ brew contributions --repos=brew,core rslpolster@gmail.com
Person rslpolster@gmail.com directly authored 1580 commits and co-authored 125 commits to brew, core in all time.
```
2022-08-03 16:53:41 +01:00
Issy Long
c330ea4e3b
dev-cmd/contributions: Split git_log_cmd into two methods
- Otherwise it's quite involved and a bit hard to read.
2022-08-03 16:53:40 +01:00
Issy Long
fef9a286fe
dev-cmd/contributions: Simplify find_repo_path_for_repo
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2022-08-03 16:53:39 +01:00
Issy Long
503b51c54f
dev-cmd/contributions: Better error messages for bad --repos
```
$ brew contributions --email=me@issyl0.co.uk --repos=coreeeee
Error: Unsupported repo: coreeeee. Try one of brew, core, cask, bundle.

$ brew untap homebrew/bundle
$ brew contributions --email=me@issyl0.co.uk --repos=bundle
Error: Couldn't find repo bundle locally. Do you have it tapped?
```
2022-08-03 16:53:38 +01:00
Issy Long
0355c60787
dev-cmd/contributions: Retrieve a user's repo contributions over time
- Before each AGM it's currently a manual process for a PLC member to
  search commit logs and GitHub to figure out who contributed to
  Homebrew, so who should remain a member.
- I noticed that [looking at commits for a
  user](https://github.com/Homebrew/homebrew-core/commits?author=issyl0&since=2022-01-01&until=2023-01-01)
  would not count `Co-Authored-By`, which happens a lot now there's an
  autosquash action on PRs in `Homebrew/homebrew-core`, say if someone
  fixed a formula's build or tests or whatever and then the PR got
  auto-merged.
- Here's `brew contributions` that uses `git log` to be able to go back
  through all time or a specific time period (`--from`, `--to`). It's up
  to individual PLC discretion for "activity", but it does at least go
  some way to automating the data retrieval.
- Example (I can use my username as `--email` because my username is in
  all of the email addresses that I use for committing to Homebrew):

```
$ brew contributions --email=issyl0 --repos=brew,core
Person issyl0 directly authored 732 commits and co-authored 31 commits to brew, core in all time.
```
2022-08-03 16:53:37 +01:00