Skip to content

Instantly share code, notes, and snippets.

@enekofb

enekofb/output Secret

Last active December 28, 2022 22:09
Show Gist options
  • Save enekofb/a5dcebd056003028e55b34d50815d1a7 to your computer and use it in GitHub Desktop.
Save enekofb/a5dcebd056003028e55b34d50815d1a7 to your computer and use it in GitHub Desktop.
scenario 2: cannot get client dues to base url is not set
=== RUN ExampleOrgRepositoriesClientForGitlabEnterprise_Get
2022/12/28 23:08:23 repo domain: gitlab.git.xx
2022/12/28 23:08:23 Get "gitlab.git.xx/api/v4/projects/pipeline-controller%2Fpipeline-controller-e2e": unsupported protocol scheme ""
func ExampleOrgRepositoriesClientForGitlabEnterprise_Get() {
// Create a new client
ctx := context.Background()
clientOptions := []gitprovider.ClientOption{}
clientOptions = append(clientOptions, gitprovider.WithDomain("gitlab.git.xx"))
c, err := gitlab.NewClient(os.Getenv("GITLAB_ENTERPRISE_TOKEN"), "", clientOptions...)
checkErr(err)
//log.Printf("client supported domain: %s", c.SupportedDomain())
// Parse the URL into an OrgRepositoryRef
ref, err := gitprovider.ParseOrgRepositoryURL("https://gitlab.git.xx/pipeline-controller/pipeline-controller-e2e")
checkErr(err)
log.Printf("repo domain: %s", ref.GetDomain())
// Get public information about the flux repository.
repo, err := c.OrgRepositories().Get(ctx, *ref)
checkErr(err)
// Use .Get() to aquire a high-level gitprovider.OrganizationInfo struct
repoInfo := repo.Get()
// Cast the internal object to a *gogithub.Repository to access custom data
internalRepo := repo.APIObject().(*gogitlab.Project)
fmt.Printf("Description: %s. Homepage: %s", *repoInfo.Description, internalRepo.HTTPURLToRepo)
// Output: Description: GitLab FOSS is a read-only mirror of GitLab, with all proprietary code removed. This project was previously used to host GitLab Community Edition, but all development has now moved to https://gitlab.com/gitlab-org/gitlab.. Homepage: https://gitlab.com/gitlab-org/gitlab-foss.git
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment