Skip to content

Commit 191a5e0

Browse files
author
DerZersaeger
committed
Squash commits + delete source branch when needed
1 parent bcdbb9d commit 191a5e0

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

gitprovider/gitlab_adapter.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/meinto/glow"
1313
"github.com/pkg/errors"
14+
"github.com/spf13/viper"
1415
)
1516

1617
type gitlabAdapter struct {
@@ -27,7 +28,7 @@ func (a *gitlabAdapter) Close(b glow.Branch) error {
2728
targets := b.CloseBranches(branchList)
2829

2930
for _, t := range targets {
30-
err := a.createMergeRequest(b, t)
31+
err := a.createMergeRequest(b, t, true)
3132
if err != nil {
3233
return errors.Wrap(err, "error creating merge request")
3334
}
@@ -41,24 +42,26 @@ func (a *gitlabAdapter) Publish(b glow.Branch) error {
4142
remoteBranchExists := a.gitService.RemoteBranchExists(b.ShortBranchName())
4243
if b.CanBePublished() && remoteBranchExists == nil {
4344
t := b.PublishBranch()
44-
return a.createMergeRequest(b, t)
45+
return a.createMergeRequest(b, t, false)
4546
}
4647
return errors.Wrap(remoteBranchExists, "cannot be published")
4748
}
4849

49-
func (a *gitlabAdapter) createMergeRequest(source glow.Branch, target glow.Branch) error {
50+
func (a *gitlabAdapter) createMergeRequest(source glow.Branch, target glow.Branch, removeSourceBranch bool) error {
5051
type Payload struct {
5152
SourceBranch string `json:"source_branch"`
5253
TargetBranch string `json:"target_branch"`
5354
Title string `json:"title"`
5455
RemoveSourceBranch bool `json:"remove_source_branch"`
56+
Squash bool `json:"squash"`
5557
}
5658

5759
data := Payload{
5860
SourceBranch: source.ShortBranchName(),
5961
TargetBranch: target.ShortBranchName(),
6062
Title: fmt.Sprintf("Merge %s in %s", source.ShortBranchName(), target.ShortBranchName()),
61-
RemoveSourceBranch: false,
63+
RemoveSourceBranch: removeSourceBranch,
64+
Squash: viper.GetBool("mergeRequest.squashCommits"),
6265
}
6366
payloadBytes, err := json.Marshal(data)
6467
if err != nil {

glow.config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"gitProviderDomain": "https://api.github.com",
44
"gitProvider": "github",
55
"projectNamespace": "meinto",
6-
"projectName": "glow"
6+
"projectName": "glow",
7+
"mergeRequest.squashCommits": true
78
}

0 commit comments

Comments
 (0)