Skip to content

Print auth help message based on environment#5781

Merged
mislav merged 8 commits intocli:trunkfrom
spenserblack:bugfix/welcome-in-noninteractive-environments
Jun 14, 2022
Merged

Print auth help message based on environment#5781
mislav merged 8 commits intocli:trunkfrom
spenserblack:bugfix/welcome-in-noninteractive-environments

Conversation

@spenserblack
Copy link
Copy Markdown
Contributor

This will check if gh is running in a CI environment by checking the CI environment variable. If so, it will suggest using environment variables to set the auth token. Additionally, if the CI environment is detected to be GitHub Actions (GITHUB_ACTION!=""), it will provide some example code (#5387 (comment)).

If it is not a CI environment, it will print the standard help message.

Fixes #5387

This will check if `gh` is running in a CI environment. If so, it will
suggest using environment variables to set the auth token. Additionally,
if the CI environment is detected to be GitHub Actions, it will provide
some example code. If it is not a CI environment, it will print the
standard help message.
Instead of checking if the environment variable exists, checks if it has
a value. This makes it easier to test.
@spenserblack spenserblack requested a review from a team as a code owner June 9, 2022 15:42
@spenserblack spenserblack requested review from mislav and removed request for a team June 9, 2022 15:42
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Jun 9, 2022
Copy link
Copy Markdown
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Looking good so far!

Comment thread cmd/gh/main.go Outdated
Comment thread cmd/gh/main.go Outdated
Comment thread cmd/gh/main.go Outdated
Comment thread cmd/gh/main.go Outdated
Comment thread cmd/gh/main.go Outdated
spenserblack and others added 3 commits June 13, 2022 11:14
This environment variable is always set to `true` in a GitHub Action.

Co-authored-by: Mislav Marohnić <hi@mislav.net>
`GITHUB_TOKEN` and `GH_TOKEN` are competing options and may confuse the
user. This changes to only suggesting `GH_TOKEN` if not authorized in a
CI environment.

Co-authored-by: Mislav Marohnić <hi@mislav.net>
Instead of building the help message step-by-step, constructs the full
help message in a single heredoc function call to make the code more
readable.
@spenserblack
Copy link
Copy Markdown
Contributor Author

@mislav Thanks for the feedback!

Copy link
Copy Markdown
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thank you! I've additionally simplified a bit.

@mislav mislav enabled auto-merge (squash) June 14, 2022 12:16
@mislav mislav merged commit 5771fcb into cli:trunk Jun 14, 2022
@spenserblack spenserblack deleted the bugfix/welcome-in-noninteractive-environments branch June 14, 2022 16:36
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 repo view shouldn't unconditionally say Welcome

3 participants