Skip to content

Commit

Permalink
feat(gitlab): respect project level squash setting (lindell#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeijn authored Feb 5, 2022
1 parent af2c2d9 commit b189661
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/scm/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func (g *Gitlab) CreatePullRequest(ctx context.Context, repo scm.Repository, prR
TargetProjectID: &r.pid,
ReviewerIDs: reviewersIDs,
RemoveSourceBranch: &removeSourceBranch,
Squash: &r.shouldSquash,
AssigneeIDs: assigneesIDs,
})
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions internal/scm/gitlab/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,28 @@ func (g *Gitlab) convertProject(project *gitlab.Project) (repository, error) {
name: project.Path,
ownerName: project.Namespace.Path,
defaultBranch: project.DefaultBranch,
shouldSquash: shouldSquash(project),
}, nil
}

func shouldSquash(project *gitlab.Project) bool {
switch project.SquashOption {
case gitlab.SquashOptionAlways, gitlab.SquashOptionDefaultOn:
return true
case gitlab.SquashOptionNever, gitlab.SquashOptionDefaultOff:
return false
default:
return false
}
}

type repository struct {
url string
pid int
name string
ownerName string
defaultBranch string
shouldSquash bool
}

func (r repository) CloneURL() string {
Expand Down

0 comments on commit b189661

Please sign in to comment.