-
-
Save enekofb/42cdc1f2fe278affb7fbaec08771c9a0 to your computer and use it in GitHub Desktop.
scenario 1: cannot get repo with error domain not supported by this client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=== RUN ExampleOrgRepositoriesClientForGitlabEnterprise_Get | |
2022/12/28 22:44:08 client supported domain: https://gitlab.git.xx | |
2022/12/28 22:44:08 repo domain: gitlab.git.xx | |
2022/12/28 22:44:08 domain "gitlab.git.xx" not supported by this client: the client doesn't support handling requests for this domain | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gitlab_test | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"os" | |
"github.com/fluxcd/go-git-providers/gitlab" | |
"github.com/fluxcd/go-git-providers/gitprovider" | |
gogitlab "github.com/xanzy/go-gitlab" | |
) | |
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