2020-09-29 05:55:34 +00:00
|
|
|
package rebase
|
|
|
|
|
|
|
|
import (
|
2021-01-08 19:38:52 +00:00
|
|
|
"github.com/MakeNowJust/heredoc"
|
2022-09-19 20:23:45 +00:00
|
|
|
"gitlab.com/gitlab-org/cli/commands/cmdutils"
|
|
|
|
"gitlab.com/gitlab-org/cli/commands/mr/mrutils"
|
2020-09-29 05:55:34 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewCmdRebase(f *cmdutils.Factory) *cobra.Command {
|
2022-11-17 18:36:09 +00:00
|
|
|
mrRebaseCmd := &cobra.Command{
|
2021-01-08 19:39:15 +00:00
|
|
|
Use: "rebase [<id> | <branch>] [flags]",
|
|
|
|
Short: `Automatically rebase the source_branch of the merge request against its target_branch.`,
|
2022-11-17 18:36:09 +00:00
|
|
|
Long: heredoc.Doc(`If you don't have permissions to push to the merge request's source branch - you'll get a 403 Forbidden response.
|
2022-10-21 14:38:48 +00:00
|
|
|
`),
|
2021-01-08 19:38:52 +00:00
|
|
|
Example: heredoc.Doc(`
|
2022-10-21 14:38:48 +00:00
|
|
|
glab mr rebase 123
|
|
|
|
glab mr rebase # get from current branch
|
|
|
|
glab mr rebase branch
|
2021-01-08 19:38:52 +00:00
|
|
|
`),
|
|
|
|
Args: cobra.MaximumNArgs(1),
|
2020-09-29 05:55:34 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
apiClient, err := f.HttpClient()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-18 01:26:20 +00:00
|
|
|
mr, repo, err := mrutils.MRFromArgs(f, args, "opened")
|
2020-09-29 05:55:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-04-29 18:30:45 +00:00
|
|
|
if err = mrutils.RebaseMR(f.IO, apiClient, repo, mr); err != nil {
|
2020-09-29 05:55:34 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return mrRebaseCmd
|
|
|
|
}
|