| 37 | } |
| 38 | |
| 39 | func (g *GitHelper) GitConfig(ctx context.Context) (*gitutil.Config, error) { |
| 40 | err := g.gitConfigMu.Acquire(ctx, 1) |
| 41 | if err != nil { |
| 42 | return nil, err |
| 43 | } |
| 44 | defer g.gitConfigMu.Release(1) |
| 45 | if g.gitConfig != nil && !g.gitConfig.IsExpired() { |
| 46 | return g.gitConfig, nil |
| 47 | } |
| 48 | |
| 49 | c, err := g.h.Client() |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | |
| 54 | resp, err := c.GetCloneCredentials(ctx, &adminv1.GetCloneCredentialsRequest{ |
| 55 | Org: g.org, |
| 56 | Project: g.project, |
| 57 | }) |
| 58 | if err != nil { |
| 59 | return nil, err |
| 60 | } |
| 61 | if resp.GitRepoUrl == "" { |
| 62 | return nil, fmt.Errorf("project %q is not connected to a git repository", g.project) |
| 63 | } |
| 64 | g.gitConfig = &gitutil.Config{ |
| 65 | Remote: resp.GitRepoUrl, |
| 66 | Username: resp.GitUsername, |
| 67 | Password: resp.GitPassword, |
| 68 | PasswordExpiresAt: resp.GitPasswordExpiresAt.AsTime(), |
| 69 | DefaultBranch: resp.GitPrimaryBranch, |
| 70 | Subpath: resp.GitSubpath, |
| 71 | ManagedRepo: resp.GitManagedRepo, |
| 72 | } |
| 73 | return g.gitConfig, nil |
| 74 | } |
| 75 | |
| 76 | func (g *GitHelper) PushToNewManagedRepo(ctx context.Context, primaryBranch string) (*adminv1.CreateManagedGitRepoResponse, error) { |
| 77 | c, err := g.h.Client() |