45 Commits

Author SHA1 Message Date
Douglas Eichelberger
eb7c3e52a0 Require SystemInclude only where needed 2024-01-31 11:42:01 -08:00
Issy Long
f682147598
Fix RuboCop Style/RedundantFreeze offenses 2024-01-18 22:20:01 +00:00
Issy Long
149b0e4f31
Fix new Style/MutableConstant RuboCop offenses for Ruby 3.1
- A follow-up to de592af20bbff5bcb548d2474f0722e59ff1129a, resetting the previous disabled comments too.
2023-12-16 11:57:06 +00:00
Mike McQuaid
b7114651ac
utils/curl: include or use explicitly.
Include or use `Utils::Curl` explicitly everywhere it is used.
2023-09-04 22:17:57 -04:00
Mike McQuaid
d357607b2c
dev-cmd/contributions: usability/performance improvements.
- more sensible/performant defaults: default to primary repositories
  only for the last year rather than all repositories forever
- allow specifying more than one user at a time
- output the breakdown of contributions without needing `--csv`
- add a space before the `--csv` output
- consolidate some code
- avoid counting authored commits twice, to improve performance
- retry failed GitHub API calls (this happens often when querying all
  maintainers)
- stop counting after we find 1000 commits for a given user to avoid
  excessive API queries/pagination
2023-08-30 15:08:50 +01:00
Alexander Bayandin
45378f35e2 get_repo_license: ignore ip allowlist error 2023-08-26 17:16:43 +01:00
Bjorn Neergaard
a5554df6bb utils/github/api: fix credentials_type
The order is shared with self.credentials, but during the deprecation
cycle the need to adjust self.credentials_type to match was overlooked.
2023-07-19 14:58:12 -06:00
Mike McQuaid
7da934f7e2
Deprecate/disable/delete code.
The next release after this is merged will be 4.1.0.

Co-authored-by: Markus Reiter <me@reitermark.us>
2023-07-06 16:56:20 +01:00
Carlo Cabrera
faa58e6576
utils/github/api: avoid loading gh
This is causing errors in third-party taps after
Homebrew/homebrew-test-bot#934.

Fixes Homebrew/discussions#4546.
2023-05-31 23:43:24 +08:00
Carlo Cabrera
ff45c2822f
utils/github/api: fix nil implicit conversion error
Fixes

    Error: no implicit conversion of nil into String

https://github.com/Homebrew/homebrew-test-bot/actions/runs/5113802196/jobs/9193401244#step:11:11
2023-05-30 01:03:33 +08:00
Bjorn Neergaard
fc63aca46a utils/github/api: refactor keychain code to use system_command 2023-05-26 09:54:28 -06:00
Bjorn Neergaard
d634296109 utils/github/api: discover credentials stored by the GitHub CLI 2023-05-26 09:54:25 -06:00
Douglas Eichelberger
08af78a2a5 brew style --fix 2023-04-25 09:26:24 -07:00
Douglas Eichelberger
24cf6076e8 brew style --fix 2023-04-24 20:42:39 -07:00
Douglas Eichelberger
7fdd75ad41 brew style --fix 2023-04-17 11:00:55 -07:00
Douglas Eichelberger
09c679e75f Refactor module_function to reduce rbi need 2023-04-17 10:37:59 -07:00
Douglas Eichelberger
02fd0422aa Enable typing in a few more files 2023-03-09 13:42:06 -08:00
Issy Long
dd140ea717
utils/github/api: Smarter pagination in paginate_rest
- The `API_MAX_PAGES` value is 50, so for pages 1 to 50, the
  `paginate_rest` method was making an API call even if there was no
  data past, for example, page 8.
- This made `brew contributions --user=issyl0` take 11 minutes, since we
  made 50 API calls _per repo_ even if it was unnecessary, burning down
  our API allowance.
- Instead, stop looping if we detect that there's no data in `result`.
- This probably needs more testing for other parts of Homebrew that rely
  on `paginate_rest` and the different shapes of data it outputs.
2023-02-22 17:53:46 +00:00
Issy Long
c9e6b81b4b
utils/github: API.paginate_rest handles extra query params
- Functionally it doesn't matter that the URL will have an `&` at the
  end if `additional_query_params` is `nil`, because it doesn't affect
  the URL at all.
2023-02-21 11:06:30 +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
Issy Long
87348dc179
Apply suggestions from code review
Co-authored-by: Bo Anderson <mail@boanderson.me>
2023-02-07 02:05:46 +01:00
Issy Long
41b143deec
cmd/gist-logs: On 404, the PAT probably needs more permissions
- This 404 error is from GitHub, and GitHub doesn't give us any more
  informations about scopes for the gist endpoint (for some reason). But we can
  safely assume, as it happens a lot, that "Error: Not Found" (404) is because
  the user hasn't granted their `HOMEBREW_GITHUB_API_TOKEN` the `gist` scope.

Before:

```shell
$ HOMEBREW_GITHUB_API_TOKEN=<token_without_gist_scope> brew gist-logs -p logrotate
Error: Not Found
```

After:

```shell
❯ HOMEBREW_GITHUB_API_TOKEN=<token_without_gist_scope> brew gist-logs logrotate
Error: Your GitHub API token likely doesn't have the `gist` scope.
Create a GitHub personal access token:
https://github.com/settings/tokens/new?scopes=gist&description=Homebrew
echo 'export HOMEBREW_GITHUB_API_TOKEN=your_token_here' >> ~/.zshrc
```
2023-02-06 17:00:02 +01:00
Dustin Rodrigues
5e9223d059
add explicit version for GitHub API 2022-12-19 12:00:12 -05:00
Mike McQuaid
4e03afeeb6
utils/github/api: curl format token, not a ruby one. 2022-12-13 11:37:05 +00:00
hyuraku
43eca95ce4 reset require-utils/github location 2022-11-07 23:12:27 +09:00
Mike McQuaid
bc295f7947
update-sponsors: don't require admin token.
Instead, use a different API to query these with a lower scope.

This should be usable by GitHub Actions.
2022-09-07 16:49:41 +01:00
Alexander Bayandin
4e8cc524c5 Clean up GitHub headers 2022-07-24 11:44:16 +00:00
Bo Anderson
3e75b165ae
utils/github: rewrite get_workflow_run using GraphQL 2022-04-11 20:35:03 +01:00
Adrian Ho
f5f4d5b082 github_api: fix recommended PAT URL
Closes #13030.
2022-03-24 10:18:02 +08:00
Logicer
7beb1f227c
Update Library/Homebrew/utils/github/api.rb
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2021-07-20 12:06:04 +10:00
Logicer
ed4f840a67
Fix style 2021-07-20 09:22:34 +10:00
Logicer
0c6f5ab233
Put API.credentials bit into separate variable 2021-07-20 09:18:16 +10:00
Logicer
71b61d28d1 Fix Style 2021-07-19 12:09:23 +10:00
Logicer
06f415e819 Dont ask to create PAT if one already exists 2021-07-19 10:28:11 +10:00
Logicer
5b7921ff68 Add support for GitHub Oauth tokens from keychain 2021-07-18 21:47:11 +10:00
hyuraku
90c02f7b5a change https://api.github.com to API_URL 2021-06-02 21:13:53 +09:00
Mike McQuaid
6f071a06f8
Use JSON.pretty_generate
It's dramatically more human readable for very little difference in
space.
2021-04-09 15:44:37 +01:00
Rylan Polster
95a5c58eee
Merge pull request #10847 from jonchang/github-pat-update
github/api: update personal access token format.
2021-04-05 19:43:43 -04:00
Rylan Polster
229e035a3d
Update PAT regex 2021-04-05 19:23:18 -04:00
Bo Anderson
ec20eb604d
utils/gitub/api: fix incorrect error when unauthenticated 2021-04-02 15:36:14 +01:00
Bo Anderson
450bc4ab33
Fix brew style 2021-03-26 14:11:03 +00:00
Jonathan Chang
cd280ee52a github/api: update personal access token format.
https://github.blog/changelog/2021-03-04-authentication-token-format-updates/
2021-03-14 18:25:38 +11:00
nandahkrishna
7b0352f167
utils/github/api: simplify pagination 2021-03-11 14:50:19 +05:30
nandahkrishna
f7c8810214
utils/github/api: remove 'api' from method names 2021-02-17 23:47:05 +05:30
nandahkrishna
9d8a5827a3
utils/github: split module 2021-02-15 21:08:10 +05:30