@@ -13,13 +13,24 @@ import (
13
13
)
14
14
15
15
// Update updates pull request with base branch.
16
- func Update (pull * models.PullRequest , doer * models.User , message string ) error {
17
- //use merge functions but switch repo's and branch's
18
- pr := & models.PullRequest {
19
- HeadRepoID : pull .BaseRepoID ,
20
- BaseRepoID : pull .HeadRepoID ,
21
- HeadBranch : pull .BaseBranch ,
22
- BaseBranch : pull .HeadBranch ,
16
+ func Update (pull * models.PullRequest , doer * models.User , message string , rebase bool ) error {
17
+ var (
18
+ pr * models.PullRequest
19
+ style models.MergeStyle
20
+ )
21
+
22
+ if rebase {
23
+ pr = pull
24
+ style = models .MergeStyleRebaseUpdate
25
+ } else {
26
+ //use merge functions but switch repo's and branch's
27
+ pr = & models.PullRequest {
28
+ HeadRepoID : pull .BaseRepoID ,
29
+ BaseRepoID : pull .HeadRepoID ,
30
+ HeadBranch : pull .BaseBranch ,
31
+ BaseBranch : pull .HeadBranch ,
32
+ }
33
+ style = models .MergeStyleMerge
23
34
}
24
35
25
36
if pull .Flow == models .PullRequestFlowAGit {
@@ -42,27 +53,31 @@ func Update(pull *models.PullRequest, doer *models.User, message string) error {
42
53
return fmt .Errorf ("HeadBranch of PR %d is up to date" , pull .Index )
43
54
}
44
55
45
- _ , err = rawMerge (pr , doer , models . MergeStyleMerge , message )
56
+ _ , err = rawMerge (pr , doer , style , message )
46
57
47
58
defer func () {
59
+ if rebase {
60
+ go AddTestPullRequestTask (doer , pr .BaseRepo .ID , pr .BaseBranch , false , "" , "" )
61
+ return
62
+ }
48
63
go AddTestPullRequestTask (doer , pr .HeadRepo .ID , pr .HeadBranch , false , "" , "" )
49
64
}()
50
65
51
66
return err
52
67
}
53
68
54
69
// IsUserAllowedToUpdate check if user is allowed to update PR with given permissions and branch protections
55
- func IsUserAllowedToUpdate (pull * models.PullRequest , user * models.User ) (bool , error ) {
70
+ func IsUserAllowedToUpdate (pull * models.PullRequest , user * models.User ) (mergeAllowed , rebaseAllowed bool , err error ) {
56
71
if pull .Flow == models .PullRequestFlowAGit {
57
- return false , nil
72
+ return false , false , nil
58
73
}
59
74
60
75
if user == nil {
61
- return false , nil
76
+ return false , false , nil
62
77
}
63
78
headRepoPerm , err := models .GetUserRepoPermission (pull .HeadRepo , user )
64
79
if err != nil {
65
- return false , err
80
+ return false , false , err
66
81
}
67
82
68
83
pr := & models.PullRequest {
@@ -74,15 +89,25 @@ func IsUserAllowedToUpdate(pull *models.PullRequest, user *models.User) (bool, e
74
89
75
90
err = pr .LoadProtectedBranch ()
76
91
if err != nil {
77
- return false , err
92
+ return false , false , err
93
+ }
94
+
95
+ // can't do rebase on protected branch because need force push
96
+ if pr .ProtectedBranch == nil {
97
+ rebaseAllowed = true
78
98
}
79
99
80
100
// Update function need push permission
81
101
if pr .ProtectedBranch != nil && ! pr .ProtectedBranch .CanUserPush (user .ID ) {
82
- return false , nil
102
+ return false , false , nil
103
+ }
104
+
105
+ mergeAllowed , err = IsUserAllowedToMerge (pr , headRepoPerm , user )
106
+ if err != nil {
107
+ return false , false , err
83
108
}
84
109
85
- return IsUserAllowedToMerge ( pr , headRepoPerm , user )
110
+ return mergeAllowed , rebaseAllowed , nil
86
111
}
87
112
88
113
// GetDiverging determines how many commits a PR is ahead or behind the PR base branch
0 commit comments