This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
mr_rebase.go
64 lines (57 loc) · 1.49 KB
/
mr_rebase.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package commands
import (
"fmt"
"log"
"strings"
"github.com/spf13/cobra"
"github.com/xanzy/go-gitlab"
"glab/internal/git"
"glab/internal/manip"
)
var mrRebaseCmd = &cobra.Command{
Use: "rebase <id> [flags]",
Short: `Automatically rebase the source_branch of the merge request against its target_branch.`,
Long: `If you don’t have permissions to push to the merge request’s source branch - you’ll get a 403 Forbidden response.`,
Aliases: []string{"accept"},
Args: cobra.ExactArgs(1),
Run: acceptRebaseRequest,
}
func acceptRebaseRequest(cmd *cobra.Command, args []string) {
mergeID := strings.Trim(args[0], " ")
gitlabClient, repo := git.InitGitlabClient()
if r, _ := cmd.Flags().GetString("repo"); r != "" {
repo = r
}
fmt.Println("Sending request...")
_, err := gitlabClient.MergeRequests.RebaseMergeRequest(repo, manip.StringToInt(mergeID))
if err != nil {
er(err)
return
}
opts := &gitlab.GetMergeRequestsOptions{}
opts.IncludeRebaseInProgress = gitlab.Bool(true)
fmt.Println("Checking rebase status...")
i := 0
for {
mr, _, err := gitlabClient.MergeRequests.GetMergeRequest(repo, manip.StringToInt(mergeID), opts)
if err != nil {
log.Fatal(err)
}
if mr.RebaseInProgress {
if i == 0 {
fmt.Println("Rebase in progress...")
}
} else {
if mr.MergeError != "" && mr.MergeError != "null" {
fmt.Println(mr.MergeError)
break
}
fmt.Println("Rebase successful")
break
}
i++
}
}
func init() {
mrCmd.AddCommand(mrRebaseCmd)
}