Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

feat(mr create): add --squash-before-merge parameter #855

Merged
merged 2 commits into from
Oct 4, 2021
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
9 changes: 9 additions & 0 deletions commands/mr/create/mr_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type CreateOpts struct {
CreateSourceBranch bool
RemoveSourceBranch bool
AllowCollaboration bool
SquashBeforeMerge bool

Autofill bool
FillCommitBody bool
Expand Down Expand Up @@ -155,6 +156,7 @@ func NewCmdCreate(f *cmdutils.Factory, runE func(opts *CreateOpts) error) *cobra
mrCreateCmd.Flags().StringVarP(&opts.MilestoneFlag, "milestone", "m", "", "The global ID or title of a milestone to assign")
mrCreateCmd.Flags().BoolVarP(&opts.AllowCollaboration, "allow-collaboration", "", false, "Allow commits from other members")
mrCreateCmd.Flags().BoolVarP(&opts.RemoveSourceBranch, "remove-source-branch", "", false, "Remove Source Branch on merge")
mrCreateCmd.Flags().BoolVarP(&opts.SquashBeforeMerge, "squash-before-merge", "", false, "Squash commits into a single commit when merging")
mrCreateCmd.Flags().BoolVarP(&opts.NoEditor, "no-editor", "", false, "Don't open editor to enter description. If set to true, uses prompt. Default is false")
mrCreateCmd.Flags().StringP("head", "H", "", "Select another head repository using the `OWNER/REPO` or `GROUP/NAMESPACE/REPO` format or the project ID or full URL")
mrCreateCmd.Flags().BoolVarP(&opts.Yes, "yes", "y", false, "Skip submission confirmation prompt, with --fill it skips all optional prompts")
Expand Down Expand Up @@ -352,12 +354,19 @@ func createRun(opts *CreateOpts) error {
mrCreateOpts.Description = gitlab.String(opts.Description)
mrCreateOpts.SourceBranch = gitlab.String(opts.SourceBranch)
mrCreateOpts.TargetBranch = gitlab.String(opts.TargetBranch)

if opts.AllowCollaboration {
mrCreateOpts.AllowCollaboration = gitlab.Bool(true)
}

if opts.RemoveSourceBranch {
mrCreateOpts.RemoveSourceBranch = gitlab.Bool(true)
}

if opts.SquashBeforeMerge {
mrCreateOpts.Squash = gitlab.Bool(true)
}

if opts.TargetProject != nil {
mrCreateOpts.TargetProjectID = gitlab.Int(opts.TargetProject.ID)
}
Expand Down