Skip to content

fix: Enable to use glab on staging.gitlab.com

Mikel requested to merge mikelolasagasti/glab-cli:fix-7426 into main
  • Please check this box if this contribution uses AI-generated content as outlined in the GitLab DCO & CLA

Description

This commit introduces the IsStaging function to determine whether the input hostname matches the default staging hostname. Additionally, NormalizeHostname is adjusted to correctly handle staging instances by checking if the input hostname matches the default staging hostname.

Test cases are added to verify the correctness of the IsStaging and NormalizeHostname functions.

Related Issues

Resolves #7426

How has this been tested?

$ go test  ./pkg/glinstance/
ok  	gitlab.com/gitlab-org/cli/pkg/glinstance	(cached)

$ make build                                                                                                                                                                            
go build -trimpath -ldflags "-X main.buildDate=2024-04-22  -X main.version=v1.39.0-4-g0c570279 -X main.debugMode=false" -o ./bin/glab gitlab.com/gitlab-org/cli/cmd/glab

$ ./bin/glab auth login                                                                                                                                                                          
? What GitLab instance do you want to log into? GitLab Self-hosted Instance
? GitLab hostname: staging.gitlab.com
? API hostname: staging.gitlab.com
- Logging into staging.gitlab.com
? How would you like to login? Token

Tip: you can generate a Personal Access Token here https://staging.gitlab.com/-/profile/personal_access_tokens?scopes=api,write_repository
The minimum required scopes are 'api' and 'write_repository'.
? Paste your authentication token: **********
? Choose default git protocol HTTPS
? Authenticate Git with your GitLab credentials? Yes
? Choose host API protocol HTTPS
- glab config set -h staging.gitlab.com git_protocol https
✓ Configured git protocol
- glab config set -h staging.gitlab.com api_protocol https
✓ Configured API protocol
error using api: GET https://staging.gitlab.com/api/v4/user: 401 {message: 401 Unauthorized}

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation
  • Chore (Related to CI or Packaging to platforms)
  • Test gap
Edited by 🤖 GitLab Bot 🤖

Merge request reports