Show full permissions URL in gh cs create (#7983)
* Show full permissions URL in `gh cs create` * Validate that full permissions URL is displayed
This commit is contained in:
parent
4cd0b738d6
commit
c5f88bb551
2 changed files with 34 additions and 4 deletions
|
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/cli/cli/v2/internal/codespaces"
|
||||
"github.com/cli/cli/v2/internal/codespaces/api"
|
||||
"github.com/cli/cli/v2/internal/ghrepo"
|
||||
"github.com/cli/cli/v2/internal/text"
|
||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
@ -336,13 +335,12 @@ func (a *App) handleAdditionalPermissions(ctx context.Context, createParams *api
|
|||
var (
|
||||
isInteractive = a.io.CanPrompt()
|
||||
cs = a.io.ColorScheme()
|
||||
displayURL = text.DisplayURL(allowPermissionsURL)
|
||||
)
|
||||
|
||||
fmt.Fprintf(a.io.ErrOut, "You must authorize or deny additional permissions requested by this codespace before continuing.\n")
|
||||
|
||||
if !isInteractive {
|
||||
fmt.Fprintf(a.io.ErrOut, "%s in your browser to review and authorize additional permissions: %s\n", cs.Bold("Open this URL"), displayURL)
|
||||
fmt.Fprintf(a.io.ErrOut, "%s in your browser to review and authorize additional permissions: %s\n", cs.Bold("Open this URL"), allowPermissionsURL)
|
||||
fmt.Fprintf(a.io.ErrOut, "Alternatively, you can run %q with the %q option to continue without authorizing additional permissions.\n", a.io.ColorScheme().Bold("create"), cs.Bold("--default-permissions"))
|
||||
return nil, cmdutil.SilentError
|
||||
}
|
||||
|
|
|
|||
|
|
@ -356,7 +356,39 @@ func TestApp_Create(t *testing.T) {
|
|||
wantErr: cmdutil.SilentError,
|
||||
wantStderr: ` ✓ Codespaces usage for this repository is paid for by monalisa
|
||||
You must authorize or deny additional permissions requested by this codespace before continuing.
|
||||
Open this URL in your browser to review and authorize additional permissions: example.com/permissions
|
||||
Open this URL in your browser to review and authorize additional permissions: https://example.com/permissions
|
||||
Alternatively, you can run "create" with the "--default-permissions" option to continue without authorizing additional permissions.
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "create codespace that requires accepting additional permissions for devcontainer path",
|
||||
fields: fields{
|
||||
apiClient: apiCreateDefaults(&apiClientMock{
|
||||
CreateCodespaceFunc: func(ctx context.Context, params *api.CreateCodespaceParams) (*api.Codespace, error) {
|
||||
if params.Branch != "feature-branch" {
|
||||
return nil, fmt.Errorf("got branch %q, want %q", params.Branch, "main")
|
||||
}
|
||||
if params.IdleTimeoutMinutes != 30 {
|
||||
return nil, fmt.Errorf("idle timeout minutes was %v", params.IdleTimeoutMinutes)
|
||||
}
|
||||
return &api.Codespace{}, api.AcceptPermissionsRequiredError{
|
||||
AllowPermissionsURL: "https://example.com/permissions?ref=feature-branch&devcontainer_path=.devcontainer/actions/devcontainer.json",
|
||||
}
|
||||
},
|
||||
}),
|
||||
},
|
||||
opts: createOptions{
|
||||
repo: "monalisa/dotfiles",
|
||||
branch: "feature-branch",
|
||||
devContainerPath: ".devcontainer/actions/devcontainer.json",
|
||||
machine: "GIGA",
|
||||
showStatus: false,
|
||||
idleTimeout: 30 * time.Minute,
|
||||
},
|
||||
wantErr: cmdutil.SilentError,
|
||||
wantStderr: ` ✓ Codespaces usage for this repository is paid for by monalisa
|
||||
You must authorize or deny additional permissions requested by this codespace before continuing.
|
||||
Open this URL in your browser to review and authorize additional permissions: https://example.com/permissions?ref=feature-branch&devcontainer_path=.devcontainer/actions/devcontainer.json
|
||||
Alternatively, you can run "create" with the "--default-permissions" option to continue without authorizing additional permissions.
|
||||
`,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue