Skip to content

feat: bypass branch rules as default for create branch ops #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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