Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@BagToad
Copy link
Member

@BagToad BagToad commented Oct 19, 2024

Resolves #9773 by adding a friendly error message when gh release create fails and it may be due to a missing workflow OAuth scope.

Example leveraging a fork of the repo in #9773:

gh release create v0.1.0 --target a602187ebae72cc0e8101cc46fc116a51c9e9e39 --title foo --notes bar -R bagtoad/bevy-yoetz
HTTP 404: Failed to create release, "workflow" scope may be required
To request it, run gh auth refresh -h github.com -s workflow

@BagToad BagToad changed the title Handle missing "workflow" scope in createRelease Print friendly error when release create fails due to missing workflow OAuth scope Oct 19, 2024
@andyfeller
Copy link
Member

@BagToad : Is there anything you need to go from a draft to a full PR?

I wasn't sure if you created a draft for discussion or feedback purposes. Just making sure to understand what's needed here. πŸ‘

@BagToad BagToad force-pushed the kw/cli-9773-informative-message-for-workflow-scope branch from 4502498 to 68f3ef7 Compare November 17, 2024 02:33
@BagToad BagToad marked this pull request as ready for review November 17, 2024 02:36
@BagToad BagToad requested a review from a team as a code owner November 17, 2024 02:36
@BagToad BagToad requested a review from andyfeller November 17, 2024 02:36
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Nov 17, 2024
Copy link
Member

@andyfeller andyfeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid work! πŸ’ͺ Some random thoughts and concerns

@BagToad BagToad force-pushed the kw/cli-9773-informative-message-for-workflow-scope branch from f1b794b to 65a26ea Compare November 23, 2024 19:52
Refactor the logic for checking `workflow` scope checking in releases to be in the positive - check if the scope is there, not check if it isn't there. Then, when the function is called we invert it.

Also update comments to be more imperative.

This refactor also incorporates @andyfeller's suggestion to use `slices`.

Co-Authored-By: Andy Feller <[email protected]>
@BagToad BagToad force-pushed the kw/cli-9773-informative-message-for-workflow-scope branch from 65a26ea to a4f96d2 Compare November 23, 2024 20:18
Comment on lines 1185 to 1189
if tt.wantErr != "" {
require.EqualError(t, err, tt.wantErr)
return
} else {
require.NoError(t, err)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this return was here, it seems like it might have been a mistake.

I needed to remove it to get my test to initially fail since my test wants a SilentError while also wanting text on stderr 🧐

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this return would cause tests that wantErr to skip checking stdout and stderr. Some of the tests define empty wantStdout and wantStderr, so removing this return would still work for most:

From trunk:

wantStdout: ``,
wantStderr: ``,
wantErr: `a release with the same tag name already exists: v1.2.3`,

err := createRun(&tt.opts)
if tt.wantErr != "" {
require.EqualError(t, err, tt.wantErr)
return
} else {
require.NoError(t, err)
}
assert.Equal(t, tt.wantStdout, stdout.String())
assert.Equal(t, tt.wantStderr, stderr.String())

From #1552:

You can see the test used to check the resulting release information, too:

err := createRun(&tt.opts)
if tt.wantErr != "" {
require.EqualError(t, err, tt.wantErr)
return
} else {
require.NoError(t, err)
}
bb, err := ioutil.ReadAll(fakeHTTP.Requests[0].Body)
require.NoError(t, err)
var params interface{}
err = json.Unmarshal(bb, &params)
require.NoError(t, err)
assert.Equal(t, tt.wantParams, params)
assert.Equal(t, tt.wantStdout, stdout.String())
assert.Equal(t, tt.wantStderr, stderr.String())

Copy link
Member

@andyfeller andyfeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline and function documentation is icing on the cake!

@andyfeller andyfeller merged commit b133f9c into trunk Nov 26, 2024
@andyfeller andyfeller deleted the kw/cli-9773-informative-message-for-workflow-scope branch November 26, 2024 13:31
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Nov 28, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.62.0` -> `v2.63.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.63.0`](https://github.com/cli/cli/releases/tag/v2.63.0): GitHub CLI 2.63.0

[Compare Source](cli/cli@v2.62.0...v2.63.0)

#### What's Changed

-   Support bare repo creation by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#9905
-   Refactor the `getAttestations` functions by [@&#8203;malancas](https://github.com/malancas) in cli/cli#9892
-   Added a section on manual verification of the relases. by [@&#8203;kommendorkapten](https://github.com/kommendorkapten) in cli/cli#9936
-   Adding option to return `baseRefOid` in `pr view` by [@&#8203;daliusd](https://github.com/daliusd) in cli/cli#9938
-   Update verification results printing by [@&#8203;malancas](https://github.com/malancas) in cli/cli#9937
-   Fix some multiline command documentation to use `heredoc` strings by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#9948
-   Print friendly error when `release create` fails due to missing `workflow` OAuth scope by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#9791

**Full Changelog**: cli/cli@v2.62.0...v2.63.0

#### Security

-   A security vulnerability has been identified in the GitHub CLI that could leak authentication tokens when cloning repositories containing git submodules hosted outside of GitHub.com and ghe.com.

    For more information, see GHSA-jwcm-9g39-pmcw

#### New Contributors

-   [@&#8203;daliusd](https://github.com/daliusd) made their first contribution in cli/cli#9938

</details>

---

### Configuration

πŸ“… **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

β™» **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

πŸ”• **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh release create works for some commit hashes but gets weird 404 for others

4 participants