(ctx context.Context, primaryBranch string)
| 74 | } |
| 75 | |
| 76 | func (g *GitHelper) PushToNewManagedRepo(ctx context.Context, primaryBranch string) (*adminv1.CreateManagedGitRepoResponse, error) { |
| 77 | c, err := g.h.Client() |
| 78 | if err != nil { |
| 79 | return nil, err |
| 80 | } |
| 81 | |
| 82 | gitRepo, err := c.CreateManagedGitRepo(ctx, &adminv1.CreateManagedGitRepoRequest{ |
| 83 | Org: g.org, |
| 84 | Name: g.project, |
| 85 | }) |
| 86 | if err != nil { |
| 87 | return nil, err |
| 88 | } |
| 89 | // git does not allow setting default branch on repo on creation |
| 90 | // but there is no restriction to push to any branch so directly update default branch here |
| 91 | if primaryBranch != "" { |
| 92 | gitRepo.DefaultBranch = primaryBranch |
| 93 | } |
| 94 | author, err := g.h.GitSignature(ctx, g.localPath) |
| 95 | if err != nil { |
| 96 | return nil, err |
| 97 | } |
| 98 | config := &gitutil.Config{ |
| 99 | Remote: gitRepo.Remote, |
| 100 | Username: gitRepo.Username, |
| 101 | Password: gitRepo.Password, |
| 102 | PasswordExpiresAt: gitRepo.PasswordExpiresAt.AsTime(), |
| 103 | DefaultBranch: gitRepo.DefaultBranch, |
| 104 | ManagedRepo: true, |
| 105 | } |
| 106 | |
| 107 | err = gitutil.CommitAndPush(ctx, g.localPath, config, "", author) |
| 108 | if err != nil { |
| 109 | return nil, err |
| 110 | } |
| 111 | |
| 112 | err = g.setGitConfig(ctx, config) |
| 113 | if err != nil { |
| 114 | return nil, err |
| 115 | } |
| 116 | |
| 117 | return gitRepo, nil |
| 118 | } |
| 119 | |
| 120 | func (g *GitHelper) PushToManagedRepo(ctx context.Context) error { |
| 121 | gitConfig, err := g.GitConfig(ctx) |
no test coverage detected