Skip to content

Commit 607a215

Browse files
feat: bypass branch rules as default for create branch ops (#323)
* feat: bypass branch rules as default for file ops * feat: bypass branch rules as default for create branch * feat: bypass branch rules as default for create branch
1 parent 756f053 commit 607a215

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

scm/driver/harness/git.go

+22-20
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,38 @@ type gitService struct {
1919

2020
func (s *gitService) CreateBranch(ctx context.Context, repo string, params *scm.ReferenceInput) (*scm.Response, error) {
2121
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
22-
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
22+
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
2323
if err != nil {
2424
return nil, err
2525
}
26-
path := fmt.Sprintf("api/v1/repos/%s/branches?%s", repoId, queryParams)
26+
path := fmt.Sprintf("api/v1/repos/%s/branches?%s", repoID, queryParams)
2727
in := &branchInput{
28-
Name: params.Name,
29-
Target: params.Sha,
28+
Name: params.Name,
29+
Target: params.Sha,
30+
BypassRules: true,
3031
}
3132
return s.client.do(ctx, "POST", path, in, nil)
3233
}
3334

3435
func (s *gitService) FindBranch(ctx context.Context, repo, name string) (*scm.Reference, *scm.Response, error) {
3536
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
36-
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
37+
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
3738
if err != nil {
3839
return nil, nil, err
3940
}
40-
path := fmt.Sprintf("api/v1/repos/%s/branches/%s?%s", repoId, name, queryParams)
41+
path := fmt.Sprintf("api/v1/repos/%s/branches/%s?%s", repoID, name, queryParams)
4142
out := new(branch)
4243
res, err := s.client.do(ctx, "GET", path, nil, out)
4344
return convertBranch(out), res, err
4445
}
4546

4647
func (s *gitService) FindCommit(ctx context.Context, repo, ref string) (*scm.Commit, *scm.Response, error) {
4748
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
48-
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
49+
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
4950
if err != nil {
5051
return nil, nil, err
5152
}
52-
path := fmt.Sprintf("api/v1/repos/%s/commits/%s?%s", repoId, ref, queryParams)
53+
path := fmt.Sprintf("api/v1/repos/%s/commits/%s?%s", repoID, ref, queryParams)
5354
out := new(commitInfo)
5455
res, err := s.client.do(ctx, "GET", path, nil, out)
5556
return convertCommitInfo(out), res, err
@@ -61,11 +62,11 @@ func (s *gitService) FindTag(ctx context.Context, repo, name string) (*scm.Refer
6162

6263
func (s *gitService) ListBranches(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Reference, *scm.Response, error) {
6364
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
64-
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
65+
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
6566
if err != nil {
6667
return nil, nil, err
6768
}
68-
path := fmt.Sprintf("api/v1/repos/%s/branches?%s&%s", repoId, encodeListOptions(opts), queryParams)
69+
path := fmt.Sprintf("api/v1/repos/%s/branches?%s&%s", repoID, encodeListOptions(opts), queryParams)
6970
out := []*branch{}
7071
res, err := s.client.do(ctx, "GET", path, nil, &out)
7172
return convertBranchList(out), res, err
@@ -79,47 +80,47 @@ func (s *gitService) ListBranchesV2(ctx context.Context, repo string, opts scm.B
7980

8081
func (s *gitService) ListCommits(ctx context.Context, repo string, opts scm.CommitListOptions) ([]*scm.Commit, *scm.Response, error) {
8182
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
82-
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
83+
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
8384
if err != nil {
8485
return nil, nil, err
8586
}
86-
path := fmt.Sprintf("api/v1/repos/%s/commits?%s&%s", repoId, encodeCommitListOptions(opts), queryParams)
87+
path := fmt.Sprintf("api/v1/repos/%s/commits?%s&%s", repoID, encodeCommitListOptions(opts), queryParams)
8788
out := new(commits)
8889
res, err := s.client.do(ctx, "GET", path, nil, &out)
8990
return convertCommitList(out), res, err
9091
}
9192

9293
func (s *gitService) ListTags(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Reference, *scm.Response, error) {
9394
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
94-
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
95+
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
9596
if err != nil {
9697
return nil, nil, err
9798
}
98-
path := fmt.Sprintf("api/v1/repos/%s/tags?%s&%s", repoId, encodeListOptions(opts), queryParams)
99+
path := fmt.Sprintf("api/v1/repos/%s/tags?%s&%s", repoID, encodeListOptions(opts), queryParams)
99100
out := []*branch{}
100101
res, err := s.client.do(ctx, "GET", path, nil, &out)
101102
return convertBranchList(out), res, err
102103
}
103104

104105
func (s *gitService) ListChanges(ctx context.Context, repo, ref string, opts scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
105106
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
106-
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
107+
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
107108
if err != nil {
108109
return nil, nil, err
109110
}
110-
path := fmt.Sprintf("api/v1/repos/%s/commits/%s/diff?%s&%s", repoId, ref, encodeListOptions(opts), queryParams)
111+
path := fmt.Sprintf("api/v1/repos/%s/commits/%s/diff?%s&%s", repoID, ref, encodeListOptions(opts), queryParams)
111112
out := []*fileDiff{}
112113
res, err := s.client.do(ctx, "POST", path, nil, &out)
113114
return convertFileDiffs(out), res, err
114115
}
115116

116117
func (s *gitService) CompareChanges(ctx context.Context, repo, source, target string, _ scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
117118
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
118-
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
119+
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
119120
if err != nil {
120121
return nil, nil, err
121122
}
122-
path := fmt.Sprintf("api/v1/repos/%s/diff/%s...%s?%s", repoId, source, target, queryParams)
123+
path := fmt.Sprintf("api/v1/repos/%s/diff/%s...%s?%s", repoID, source, target, queryParams)
123124
out := []*fileDiff{}
124125
res, err := s.client.do(ctx, "GET", path, nil, &out)
125126
return convertChangeList(out), res, err
@@ -151,8 +152,9 @@ type (
151152
Title string `json:"title"`
152153
}
153154
branchInput struct {
154-
Name string `json:"name"`
155-
Target string `json:"target"`
155+
Name string `json:"name"`
156+
Target string `json:"target"`
157+
BypassRules bool `json:"bypass_rules"`
156158
}
157159
branch struct {
158160
Commit struct {

0 commit comments

Comments
 (0)