FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: Allow to customize temporary working branch created by Updatecli by olblak · Pull Request #5589 · updatecli/updatecli · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (13) .yaml  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
61 changes: 50 additions & 11 deletions pkg/plugins/scms/bitbucket/main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ type Spec struct {
// The working branch created by Updatecli looks like "updatecli_<pipelineID>".
// The working branch can be disabled using the "workingBranch" parameter set to false.
Branch string `yaml:",omitempty"`
// WorkingBranchPrefix defines the prefix used to create a working branch.
//
// compatible:
// * scm
//
// default:
// updatecli
//
// remark:
// A working branch is composed of three components:
// 1. WorkingBranchPrefix
// 2. Target Branch
// 3. PipelineID
//
// If WorkingBranchPrefix is set to '', then
// the working branch will look like "<branch>_<pipelineID>".
WorkingBranchPrefix *string `yaml:",omitempty"`
// WorkingBranchSeparator defines the separator used to create a working branch.
//
// compatible:
// * scm
//
// default:
// "_"
WorkingBranchSeparator *string `yaml:",omitempty"`
// "submodules" defines if Updatecli should checkout submodules.
//
// compatible:
Expand All @@ -123,11 +148,13 @@ type Bitbucket struct {
// Spec contains inputs coming from updatecli configuration
Spec Spec
// client handle the api authentication
client *scm.Client
pipelineID string
nativeGitHandler gitgeneric.GitHandler
workingBranch bool
force bool
client *scm.Client
pipelineID string
nativeGitHandler gitgeneric.GitHandler
workingBranch bool
workingBranchPrefix string
workingBranchSeparator string
force bool
}

// New returns a new valid Bitbucket Cloud object.
Expand Down Expand Up @@ -163,6 +190,16 @@ func New(spec interface{}, pipelineID string) (*Bitbucket, error) {
s.Branch = "main"
}

workingBranchhPrefix := "updatecli"
if s.WorkingBranchPrefix != nil {
workingBranchhPrefix = *s.WorkingBranchPrefix
}

workingBranchSeparator := "_"
if s.WorkingBranchSeparator != nil {
workingBranchSeparator = *s.WorkingBranchSeparator
}

workingBranch := true
if s.WorkingBranch != nil {
workingBranch = *s.WorkingBranch
Expand Down Expand Up @@ -200,12 +237,14 @@ If you know what you are doing, please set the force option to true in your conf

nativeGitHandler := gitgeneric.GoGit{}
g := Bitbucket{
Spec: s,
client: c,
pipelineID: pipelineID,
nativeGitHandler: &nativeGitHandler,
workingBranch: workingBranch,
force: force,
Spec: s,
client: c,
pipelineID: pipelineID,
nativeGitHandler: &nativeGitHandler,
workingBranch: workingBranch,
workingBranchPrefix: workingBranchhPrefix,
workingBranchSeparator: workingBranchSeparator,
force: force,
}

g.setDirectory()
Expand Down
4 changes: 3 additions & 1 deletion pkg/plugins/scms/bitbucket/scm.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bitbucket
import (
"fmt"
"os"
"strings"

"github.com/sirupsen/logrus"
"github.com/updatecli/updatecli/pkg/plugins/resources/bitbucket/client"
Expand All @@ -14,7 +15,8 @@ func (b *Bitbucket) GetBranches() (sourceBranch, workingBranch, targetBranch str
targetBranch = b.Spec.Branch

if len(b.pipelineID) > 0 && b.workingBranch {
workingBranch = b.nativeGitHandler.SanitizeBranchName(fmt.Sprintf("updatecli_%s_%s", targetBranch, b.pipelineID))
workingBranch = b.nativeGitHandler.SanitizeBranchName(
strings.Join([]string{b.workingBranchPrefix, targetBranch, b.pipelineID}, b.workingBranchSeparator))
}

return sourceBranch, workingBranch, targetBranch
Expand Down
51 changes: 45 additions & 6 deletions pkg/plugins/scms/git/main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ type Spec struct {
// For more information, please refer to the following issue:
// https://github.com/updatecli/updatecli/issues/1139
Branch string `yaml:",omitempty"`
// WorkingBranchPrefix defines the prefix used to create a working branch.
//
// compatible:
// * scm
//
// default:
// updatecli
//
// remark:
// A working branch is composed of three components:
// 1. WorkingBranchPrefix
// 2. Target Branch
// 3. PipelineID
//
// If WorkingBranchPrefix is set to '', then
// the working branch will look like "<branch>_<pipelineID>".
WorkingBranchPrefix *string `yaml:",omitempty"`
// WorkingBranchSeparator defines the separator used to create a working branch.
//
// compatible:
// * scm
//
// default:
// "_"
WorkingBranchSeparator *string `yaml:",omitempty"`
// "user" specifies the user associated with new git commit messages created by Updatecli
//
// compatible:
Expand Down Expand Up @@ -136,8 +161,10 @@ type Git struct {
// nativeGitHandler is the native git handler
nativeGitHandler gitgeneric.GitHandler
// workingBranch is used to create a temporary branch to work on.
workingBranch bool
pipelineID string
workingBranch bool
workingBranchPrefix string
workingBranchSeparator string
pipelineID string
}

// New returns a new git object
Expand All @@ -154,6 +181,16 @@ func New(s Spec, pipelineID string) (*Git, error) {
s.Branch = "main"
}

workingBranchPrefix := "updatecli"
if s.WorkingBranchPrefix != nil {
workingBranchPrefix = *s.WorkingBranchPrefix
}

workingBranchSeparator := "_"
if s.WorkingBranchSeparator != nil {
workingBranchSeparator = *s.WorkingBranchSeparator
}

var workingBranch bool
switch s.WorkingBranch {
case nil:
Expand Down Expand Up @@ -181,10 +218,12 @@ If you know what you are doing, please set the workingBranch option to false in
nativeGitHandler := gitgeneric.GoGit{}

return &Git{
spec: s,
nativeGitHandler: &nativeGitHandler,
workingBranch: workingBranch,
pipelineID: pipelineID,
spec: s,
nativeGitHandler: &nativeGitHandler,
workingBranch: workingBranch,
workingBranchPrefix: workingBranchPrefix,
workingBranchSeparator: workingBranchSeparator,
pipelineID: pipelineID,
}, nil
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/plugins/scms/git/scm.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package git

import (
"fmt"
"os"
"strings"

"github.com/sirupsen/logrus"
)
Expand All @@ -13,7 +13,8 @@ func (g *Git) GetBranches() (sourceBranch, workingBranch, targetBranch string) {
targetBranch = g.spec.Branch

if g.workingBranch && len(g.pipelineID) > 0 {
workingBranch = g.nativeGitHandler.SanitizeBranchName(fmt.Sprintf("updatecli_%s_%s", targetBranch, g.pipelineID))
workingBranch = g.nativeGitHandler.SanitizeBranchName(
strings.Join([]string{g.workingBranchPrefix, targetBranch, g.pipelineID}, g.workingBranchSeparator))
}

return sourceBranch, workingBranch, targetBranch
Expand Down
61 changes: 50 additions & 11 deletions pkg/plugins/scms/gitea/main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ type Spec struct {
// The working branch created by Updatecli looks like "updatecli_<pipelineID>".
// The working branch can be disabled using the "workingBranch" parameter set to false.
Branch string `yaml:",omitempty"`
// WorkingBranchPrefix defines the prefix used to create a working branch.
//
// compatible:
// * scm
//
// default:
// updatecli
//
// remark:
// A working branch is composed of three components:
// 1. WorkingBranchPrefix
// 2. Target Branch
// 3. PipelineID
//
// If WorkingBranchPrefix is set to '', then
// the working branch will look like "<branch>_<pipelineID>".
WorkingBranchPrefix *string `yaml:",omitempty"`
// WorkingBranchSeparator defines the separator used to create a working branch.
//
// compatible:
// * scm
//
// default:
// "_"
WorkingBranchSeparator *string `yaml:",omitempty"`
// "submodules" defines if Updatecli should checkout submodules.
//
// compatible:
Expand All @@ -123,11 +148,13 @@ type Gitea struct {
// Spec contains inputs coming from updatecli configuration
Spec Spec
// client handle the api authentication
client client.Client
nativeGitHandler gitgeneric.GitHandler
pipelineID string
workingBranch bool
force bool
client client.Client
nativeGitHandler gitgeneric.GitHandler
pipelineID string
workingBranch bool
workingBranchPrefix string
workingBranchSeparator string
force bool
}

// New returns a new valid Gitea object.
Expand Down Expand Up @@ -177,6 +204,16 @@ func New(spec interface{}, pipelineID string) (*Gitea, error) {
workingBranch = *s.WorkingBranch
}

workingBranchPrefix := "updatecli"
if s.WorkingBranchPrefix != nil {
workingBranchPrefix = *s.WorkingBranchPrefix
}

workingBranchSeparator := "_"
if s.WorkingBranchSeparator != nil {
workingBranchSeparator = *s.WorkingBranchSeparator
}

force := true
if s.Force != nil {
force = *s.Force
Expand Down Expand Up @@ -215,12 +252,14 @@ If you know what you are doing, please set the force option to true in your conf

nativeGitHandler := gitgeneric.GoGit{}
g := Gitea{
Spec: s,
client: c,
pipelineID: pipelineID,
nativeGitHandler: &nativeGitHandler,
workingBranch: workingBranch,
force: force,
Spec: s,
client: c,
pipelineID: pipelineID,
nativeGitHandler: &nativeGitHandler,
workingBranch: workingBranch,
workingBranchPrefix: workingBranchPrefix,
workingBranchSeparator: workingBranchSeparator,
force: force,
}

g.setDirectory()
Expand Down
4 changes: 3 additions & 1 deletion pkg/plugins/scms/gitea/scm.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gitea
import (
"fmt"
"os"
"strings"

"github.com/sirupsen/logrus"
)
Expand All @@ -14,7 +15,8 @@ func (g *Gitea) GetBranches() (sourceBranch, workingBranch, targetBranch string)
targetBranch = g.Spec.Branch

if len(g.pipelineID) > 0 && g.workingBranch {
workingBranch = g.nativeGitHandler.SanitizeBranchName(fmt.Sprintf("updatecli_%s_%s", targetBranch, g.pipelineID))
workingBranch = g.nativeGitHandler.SanitizeBranchName(
strings.Join([]string{g.workingBranchPrefix, targetBranch, g.pipelineID}, g.workingBranchSeparator))
}

return sourceBranch, workingBranch, targetBranch
Expand Down
Loading

Back | FazBrowse Home | New Git URL