105 Commits

Author SHA1 Message Date
Mike McQuaid
f2103c7138
utils/github/api: fix Sorbet types.
Let's not use `T.unsafe(nil)` but instead an empty hash.
2025-06-17 14:59:46 +01:00
Mike McQuaid
7345607ca0
a*.rb: move to strict Sorbet sigil.
Co-authored-by: Rylan Polster <rslpolster@gmail.com>
2025-06-17 08:18:33 +01:00
Bo Anderson
e35709cb43
utils/github/actions: fix frozen string handling 2025-05-02 01:35:04 +01:00
Douglas Eichelberger
1ca5299f40
refactor: Enable strict typing in download_strategy 2025-03-12 15:15:20 -07:00
zyoshoka
8aa22ea939
utils/github: fix GraphQL error log
The key `type` is not included in the response, making the log look weird.
2025-02-01 00:39:58 +09:00
Sam Ford
cf22382921
Curl: use typed: strict
This upgrades `utils/curl.rb` to `typed: strict`, which requires
a number of changes to pass `brew typecheck`. The most
straightforward are adding type signatures to methods, adding type
annotations (e.g., `T.let`) to variables that need them, and ensuring
that methods always use the expected return type.

I had to refactor areas where we call a `Utils::Curl` method and use
array destructuring on a `SystemCommand::Result` return value
(e.g., `output, errors, status = curl_output(...)`), as Sorbet
doesn't understand implicit array conversion. As suggested by Markus,
I've switched these areas to use `#stdout`, `#stderr`, and `#status`.
This requires the use of an intermediate variable (`result`) in some
cases but this was a fairly straightforward substitution.

I also had to refactor how `Cask::URL::BlockDSL::PageWithURL` works.
It currently uses `page.extend PageWithURL` to add a `url` attribute
but this reworks it to subclass `SimpleDelegator` and use an
`initialize` method instead. This achieves the same goal but in a way
that Sorbet can understand.
2025-01-14 08:14:39 -05:00
Bo Anderson
ccdf39ff4e
dev-cmd/tap-new: improve handling of multi-user setups 2024-12-10 05:24:10 +00:00
Carlo Cabrera
7a8f9fa489
extend/kernel: fix duplicate messages in GitHub Actions
Calls to `opoo` and `onoe` produce duplicate `Warning:` and `Error:`
messages in CI logs because we print something to stdout and print an
annotation. Annotations also produce `Error:` and `Warning:` lines in
the log.

Let's fix this by skipping printing the message if we've already printed
an annotation.
2024-10-14 12:15:24 +08:00
Patrick Linnane
c2e2b23c50
brew style --fix
Signed-off-by: Patrick Linnane <patrick@linnane.io>
2024-10-02 10:03:12 -07:00
Mike McQuaid
1c390093f8
Revert "Limit usage of GitHub Actions Annotations" 2024-09-16 16:52:03 +01:00
Carlo Cabrera
c6e2cd9037
Limit usage of GitHub Actions Annotations
- only use annotations for `opoo` and `onoe` if
  `HOMEBREW_GITHUB_ACTIONS` is set. This will make using `brew` less
  noisy in GitHub Actions for third parties. See
  Homebrew/discussions#5602.
- if we've already called `puts_annotation_if_env_set`, then we no
  longer need to print the message to `$stderr`. The message from the
  annotation already show up in the GitHub Actions log, so printing to
  `$stderr` just leads to duplicate messages in the log.

While we're here, let's make sure to forward the `file:` and `line:`
kwargs of `puts_annotation_if_env_set` to the `Annotation` constructor.
2024-09-15 11:31:54 +08:00
Carlo Cabrera
54383d1c5f
github/actions: fix annotation title handling
We currently generate invalid workflow commands when we create
annotations with a `title` but no `file`. Let's fix that.

While we're here, let's improve handling of `title`s with `:`s. We
cannot use `title`s with `::` since GitHub Actions uses this as a
separator for different fields between a workflow command.

Let's also make sure `metadata` never ends in a `:` to avoid confusing
the GitHub Actions command parser about where the `::` separator is
meant to be.
2024-09-08 17:56:04 +08:00
Carlo Cabrera
cabbb0b8e3
Remove GraphQL debug output
Let's get this ready to go since we don't want to accidentally leak
private information.
2024-08-30 10:45:19 +08:00
Carlo Cabrera
7645484ac3
utils/github/api: add debug output for open_graphql
Our updating sponsors/maintainers/etc workflow is broken.

Let's add some debug output to help me fix it.
2024-08-30 10:15:56 +08:00
Carlo Cabrera
4a7579c693
utils/github: use paginate_graphql in sponsorships
`sponsorships` has its own implementation of GraphQL pagination. We can
simplify this by using `paginate_graphql` instead.
2024-08-25 01:34:36 +08:00
Issy Long
45978435e7
rubocop: Use Sorbet/StrictSigil as it's better than comments
- Previously I thought that comments were fine to discourage people from
  wasting their time trying to bump things that used `undef` that Sorbet
  didn't support. But RuboCop is better at this since it'll complain if
  the comments are unnecessary.

- Suggested in https://github.com/Homebrew/brew/pull/18018#issuecomment-2283369501.

- I've gone for a mixture of `rubocop:disable` for the files that can't
  be `typed: strict` (use of undef, required before everything else, etc)
  and `rubocop:todo` for everything else that should be tried to make
  strictly typed. There's no functional difference between the two as
  `rubocop:todo` is `rubocop:disable` with a different name.

- And I entirely disabled the cop for the docs/ directory since
  `typed: strict` isn't going to gain us anything for some Markdown
  linting config files.

- This means that now it's easier to track what needs to be done rather
  than relying on checklists of files in our big Sorbet issue:

```shell
$ git grep 'typed: true # rubocop:todo Sorbet/StrictSigil' | wc -l
    268
```

- And this is confirmed working for new files:

```shell
$ git status
On branch use-rubocop-for-sorbet-strict-sigils
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        Library/Homebrew/bad.rb
        Library/Homebrew/good.rb

nothing added to commit but untracked files present (use "git add" to track)

$ brew style
Offenses:

bad.rb:1:1: C: Sorbet/StrictSigil: Sorbet sigil should be at least strict got true.
^^^^^^^^^^^^^

1340 files inspected, 1 offense detected
```
2024-08-12 15:24:27 +01:00
Bo Anderson
a0a3333ee4
utils/github/api: fix encoding errors when reading from keychain 2024-07-30 04:51:00 +01:00
Issy Long
0af1ce866c
utils/github/api: Fix uninitialized constant Etc
- I saw this in:

```
Error: uninitialized constant GitHub::API::Etc
Warning: Removed Sorbet lines from backtrace!
Rerun with `--verbose` to see the original backtrace
/opt/homebrew/Library/Homebrew/utils/github/api.rb:140:in `uid_home'
/opt/homebrew/Library/Homebrew/utils/github/api.rb:154:in `block in github_cli_token'
/opt/homebrew/Library/Homebrew/utils/uid.rb:8:in `drop_euid'
/opt/homebrew/Library/Homebrew/utils/github/api.rb:150:in `github_cli_token'
/opt/homebrew/Library/Homebrew/utils/github/api.rb:194:in `credentials'
/opt/homebrew/Library/Homebrew/utils/github/api.rb:251:in `open_rest'
/opt/homebrew/Library/Homebrew/utils/github/api.rb:334:in `open_graphql'
/opt/homebrew/Library/Homebrew/utils/github.rb:414:in `members_by_team'
/opt/homebrew/Library/Homebrew/dev-cmd/contributions.rb:71:in `run'
/opt/homebrew/Library/Homebrew/brew.rb:95:in `<main>'
```
2024-07-27 23:45:16 +01:00
Sam Ford
a6e61fd664
contributions, github: reorder requires
Per feedback to https://github.com/Homebrew/brew/pull/17806, this
moves some `require` statements in `dev-cmd/contributions.rb` and
`Utils::GitHub` into the methods that need them.
2024-07-25 10:02:18 -04:00
Bo Anderson
e6348b186f
Merge pull request #17851 from Homebrew/misconfigured-nss-fix
utils/github/api: handle systems with misconfigured NSS
2024-07-25 04:47:43 +01:00
Bo Anderson
d39a3a3030
Merge pull request #17788 from Homebrew/more-sorbet-strict
sorbet: Bump more files to `typed: strict`
2024-07-25 02:23:23 +01:00
Bo Anderson
40ca1de617
utils/github/api: handle systems with misconfigured NSS 2024-07-25 01:57:06 +01:00
Sam Ford
a9f7da36e0
contributions, github: add missing requires
This resolves `unitialized constant` errors in `brew contributions`
(`Tap`, `GitHub`) and `Utils::GitHub` (`Utils::Curl`).

This also preemptively adds some requires to `Utils::GitHub` and
`GitHub::API`, to avoid similar errors.
2024-07-18 12:55:41 -04:00
Issy Long
b033119523
utils/github/actions: Bump to Sorbet typed: strict 2024-07-17 18:00:20 -04:00
Issy Long
07f9f3f8e0
utils/github/artifacts: Bump to Sorbet typed: strict 2024-07-17 18:00:20 -04:00
Markus Reiter
988c44ce20
Merge pull request #17722 from reitermarkus/ignore-interrupts
Make `ignore_interrupts` thread-safe.
2024-07-14 15:25:34 -04:00
Markus Reiter
6f58bffc5c
Remove useless ignore_interrupts. 2024-07-14 13:48:23 -04:00
Mike McQuaid
b8ff4b3d23
Widen attestation verification rollout
Take 2 of https://github.com/Homebrew/brew/pull/17692 but with:

- provide and document `HOMEBREW_NO_VERIFY_ATTESTATIONS`
- don't try to run unless there's GitHub credentials
- don't try to run unless `gh` is installed
- don't try to run in CI

While we're here:
- split out a `Homebrew::EnvConfig.devcmdrun?` helper method
- add some missing `Homebrew::EnvConfig.github_api_token` presence
  checks
2024-07-14 11:50:57 -04:00
Mike McQuaid
e573a53868
Output GitHub warning/error annotations to stderr
This will mean e.g. `opoo` etc. will output to stdout and not end up
being in the stdout of `brew deps` etc.

While we're here, remove a duplicate annotation output I noticed in
`extend/kernel.rb`.

Inspired by conversation in:
https://github.com/Homebrew/homebrew-test-bot/issues/1082
2024-05-31 09:31:44 +01:00
Mike McQuaid
16901a674f
extend/kernel: make opoo/odie/etc. print GitHub Actions notes.
We already do this for deprecations but these may make warnings
and errors from Homebrew easier to spot in GitHub Actions logs.

While we're here, cleanup other cases that should have used
`GitHub::Actions::Annotation` but didn't and provide some helpers and
tweaks there necessary for our use case here.
2024-05-09 14:43:53 +01:00
Bo Anderson
b790c7fe8c
utils/github/api: use real UID for auth fetching 2024-05-09 11:55:14 +01:00
Markus Reiter
caf87c0336
Warn about undocumented non-private APIs. 2024-05-01 11:35:20 +02:00
Markus Reiter
0f0055ede4
Make documentation @api private by default. 2024-04-26 19:04:20 +02:00
Markus Reiter
c76170a456
Hide #to_s in docs. 2024-04-26 14:04:55 +02:00
Ruoyu Zhong
f4f8a12509
utils/github/api: support passing scopes in paginate_rest 2024-04-24 04:06:08 +08:00
PikachuEXE
5f6cd3ed77
make more token types work as $HOMEBREW_GITHUB_API_TOKEN
Tokens of different token type(s) can be generated in GitHub Workflows by GitHub Apps

See doc & blog about token types
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/about-authentication-to-github#githubs-token-formats
https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/
2024-04-02 16:18:59 +08:00
Bartek Pacia
1aa2565cd0
make fine-grained PATs work as $HOMEBREW_GITHUB_API_TOKEN 2024-03-30 22:56:48 +01:00
Bo Anderson
7b0c3d54f1
utils/github: use GraphQL PR searching 2024-03-15 21:27:05 +00:00
Mike McQuaid
ea2892f8ee
brew.rb: handle missing args. 2024-03-07 16:20:20 +00:00
Markus Reiter
94afce5b13
Remove empty line. 2024-02-10 12:10:55 +01:00
Sohan Honavar
3dc104167e Update Library/Homebrew/utils/github/api.rb 2024-02-10 11:35:53 +05:30
Sohan Honavar
ca85c5355f Reused the variable as per the review suggestion 2024-02-10 03:50:08 +05:30
Sohan Honavar
57b7999843 Improved the GitHub link that is generated when the required scope of the token has mismatched with the present scope 2024-02-10 02:41:11 +05:30
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
e02ec5e07a
Merge pull request #15961 from MikeMcQuaid/fix_missing_curl
utils/github/artifacts: fix missing Utils::Curl reference.
2023-09-05 08:07:09 -04:00
Mike McQuaid
84973da037
utils/github/artifacts: fix missing Utils::Curl reference.
Needed after https://github.com/Homebrew/brew/pull/15940
2023-09-05 07:52:39 -04: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