From d6dfcdedb6d0df531479cc31168266766dcb5902 Mon Sep 17 00:00:00 2001
From: Abhinav Singh <abhinav.singh@harness.io>
Date: Thu, 29 Aug 2024 00:46:35 -0700
Subject: [PATCH 1/3] feat: bypass branch rules as default for file ops

---
 scm/driver/harness/content.go | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/scm/driver/harness/content.go b/scm/driver/harness/content.go
index 91e72ece..40dd24d6 100644
--- a/scm/driver/harness/content.go
+++ b/scm/driver/harness/content.go
@@ -50,10 +50,11 @@ func (s *contentService) Create(ctx context.Context, repo, path string, params *
 		Encoding: "string",
 	}
 	in := editFile{
-		Branch:  params.Branch,
-		Message: params.Message,
-		Title:   params.Message,
-		Actions: []action{a},
+		Branch:      params.Branch,
+		Message:     params.Message,
+		Title:       params.Message,
+		Actions:     []action{a},
+		BypassRules: true,
 	}
 
 	res, err := s.client.do(ctx, "POST", endpoint, in, nil)
@@ -75,10 +76,11 @@ func (s *contentService) Update(ctx context.Context, repo, path string, params *
 		Sha:      params.BlobID,
 	}
 	in := editFile{
-		Branch:  params.Branch,
-		Message: params.Message,
-		Title:   params.Message,
-		Actions: []action{a},
+		Branch:      params.Branch,
+		Message:     params.Message,
+		Title:       params.Message,
+		Actions:     []action{a},
+		BypassRules: true,
 	}
 
 	res, err := s.client.do(ctx, "POST", endpoint, in, nil)
@@ -98,10 +100,11 @@ func (s *contentService) Delete(ctx context.Context, repo, path string, params *
 		Encoding: "string",
 	}
 	in := editFile{
-		Branch:  params.Branch,
-		Message: params.Message,
-		Title:   params.Message,
-		Actions: []action{a},
+		Branch:      params.Branch,
+		Message:     params.Message,
+		Title:       params.Message,
+		Actions:     []action{a},
+		BypassRules: true,
 	}
 
 	res, err := s.client.do(ctx, "POST", endpoint, in, nil)
@@ -126,6 +129,8 @@ type editFile struct {
 	Message   string   `json:"message"`
 	NewBranch string   `json:"new_branch"`
 	Title     string   `json:"title"`
+
+	BypassRules bool `json:"bypass_rules"`
 }
 
 type action struct {

From b7027c6a39629528a55afabff09281f69ac1f3ef Mon Sep 17 00:00:00 2001
From: Abhinav Singh <abhinav.singh@harness.io>
Date: Wed, 18 Sep 2024 02:38:43 -0700
Subject: [PATCH 2/3] feat: bypass branch rules as default for create branch

---
 scm/driver/harness/git.go | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/scm/driver/harness/git.go b/scm/driver/harness/git.go
index adbd34c2..73716c3a 100644
--- a/scm/driver/harness/git.go
+++ b/scm/driver/harness/git.go
@@ -25,8 +25,9 @@ func (s *gitService) CreateBranch(ctx context.Context, repo string, params *scm.
 	}
 	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)
 }
@@ -143,8 +144,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 {

From 32c30d3aedba425b499e8ad33f945ca134603ff4 Mon Sep 17 00:00:00 2001
From: Abhinav Singh <abhinav.singh@harness.io>
Date: Wed, 18 Sep 2024 03:07:37 -0700
Subject: [PATCH 3/3] feat: bypass branch rules as default for create branch

---
 scm/driver/harness/git.go | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/scm/driver/harness/git.go b/scm/driver/harness/git.go
index 22c02279..f261f775 100644
--- a/scm/driver/harness/git.go
+++ b/scm/driver/harness/git.go
@@ -19,11 +19,11 @@ 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,
@@ -34,11 +34,11 @@ func (s *gitService) CreateBranch(ctx context.Context, repo string, params *scm.
 
 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
@@ -46,11 +46,11 @@ func (s *gitService) FindBranch(ctx context.Context, repo, name string) (*scm.Re
 
 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
@@ -62,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
@@ -80,11 +80,11 @@ 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
@@ -92,11 +92,11 @@ func (s *gitService) ListCommits(ctx context.Context, repo string, opts scm.Comm
 
 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
@@ -104,11 +104,11 @@ func (s *gitService) ListTags(ctx context.Context, repo string, opts scm.ListOpt
 
 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
@@ -116,11 +116,11 @@ func (s *gitService) ListChanges(ctx context.Context, repo, ref string, opts scm
 
 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