Skip to content

Commit

Permalink
feat: bypass branch rules as default for create branch ops (#323)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
abhinav-harness authored Sep 18, 2024
1 parent 756f053 commit 607a215
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions scm/driver/harness/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,38 @@ type gitService struct {

func (s *gitService) CreateBranch(ctx context.Context, repo string, params *scm.ReferenceInput) (*scm.Response, error) {
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
if err != nil {
return nil, err
}
path := fmt.Sprintf("api/v1/repos/%s/branches?%s", repoId, queryParams)
path := fmt.Sprintf("api/v1/repos/%s/branches?%s", repoID, queryParams)
in := &branchInput{
Name: params.Name,
Target: params.Sha,
Name: params.Name,
Target: params.Sha,
BypassRules: true,
}
return s.client.do(ctx, "POST", path, in, nil)
}

func (s *gitService) FindBranch(ctx context.Context, repo, name string) (*scm.Reference, *scm.Response, error) {
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
if err != nil {
return nil, nil, err
}
path := fmt.Sprintf("api/v1/repos/%s/branches/%s?%s", repoId, name, queryParams)
path := fmt.Sprintf("api/v1/repos/%s/branches/%s?%s", repoID, name, queryParams)
out := new(branch)
res, err := s.client.do(ctx, "GET", path, nil, out)
return convertBranch(out), res, err
}

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

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

func (s *gitService) ListCommits(ctx context.Context, repo string, opts scm.CommitListOptions) ([]*scm.Commit, *scm.Response, error) {
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
if err != nil {
return nil, nil, err
}
path := fmt.Sprintf("api/v1/repos/%s/commits?%s&%s", repoId, encodeCommitListOptions(opts), queryParams)
path := fmt.Sprintf("api/v1/repos/%s/commits?%s&%s", repoID, encodeCommitListOptions(opts), queryParams)
out := new(commits)
res, err := s.client.do(ctx, "GET", path, nil, &out)
return convertCommitList(out), res, err
}

func (s *gitService) ListTags(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Reference, *scm.Response, error) {
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
if err != nil {
return nil, nil, err
}
path := fmt.Sprintf("api/v1/repos/%s/tags?%s&%s", repoId, encodeListOptions(opts), queryParams)
path := fmt.Sprintf("api/v1/repos/%s/tags?%s&%s", repoID, encodeListOptions(opts), queryParams)
out := []*branch{}
res, err := s.client.do(ctx, "GET", path, nil, &out)
return convertBranchList(out), res, err
}

func (s *gitService) ListChanges(ctx context.Context, repo, ref string, opts scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
if err != nil {
return nil, nil, err
}
path := fmt.Sprintf("api/v1/repos/%s/commits/%s/diff?%s&%s", repoId, ref, encodeListOptions(opts), queryParams)
path := fmt.Sprintf("api/v1/repos/%s/commits/%s/diff?%s&%s", repoID, ref, encodeListOptions(opts), queryParams)
out := []*fileDiff{}
res, err := s.client.do(ctx, "POST", path, nil, &out)
return convertFileDiffs(out), res, err
}

func (s *gitService) CompareChanges(ctx context.Context, repo, source, target string, _ scm.ListOptions) ([]*scm.Change, *scm.Response, error) {
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
repoId, queryParams, err := getRepoAndQueryParams(harnessURI)
repoID, queryParams, err := getRepoAndQueryParams(harnessURI)
if err != nil {
return nil, nil, err
}
path := fmt.Sprintf("api/v1/repos/%s/diff/%s...%s?%s", repoId, source, target, queryParams)
path := fmt.Sprintf("api/v1/repos/%s/diff/%s...%s?%s", repoID, source, target, queryParams)
out := []*fileDiff{}
res, err := s.client.do(ctx, "GET", path, nil, &out)
return convertChangeList(out), res, err
Expand Down Expand Up @@ -151,8 +152,9 @@ type (
Title string `json:"title"`
}
branchInput struct {
Name string `json:"name"`
Target string `json:"target"`
Name string `json:"name"`
Target string `json:"target"`
BypassRules bool `json:"bypass_rules"`
}
branch struct {
Commit struct {
Expand Down

0 comments on commit 607a215

Please sign in to comment.