7
7
"context"
8
8
"fmt"
9
9
"os"
10
- "strconv"
11
10
"strings"
12
11
13
12
issues_model "code.gitea.io/gitea/models/issues"
@@ -24,10 +23,10 @@ import (
24
23
// ProcReceive handle proc receive work
25
24
func ProcReceive (ctx context.Context , repo * repo_model.Repository , gitRepo * git.Repository , opts * private.HookOptions ) ([]private.HookProcReceiveRefResult , error ) {
26
25
results := make ([]private.HookProcReceiveRefResult , 0 , len (opts .OldCommitIDs ))
26
+ forcePush := opts .GitPushOptions .Bool (private .GitPushOptionForcePush )
27
27
topicBranch := opts .GitPushOptions ["topic" ]
28
- forcePush , _ := strconv .ParseBool (opts .GitPushOptions ["force-push" ])
29
28
title := strings .TrimSpace (opts .GitPushOptions ["title" ])
30
- description := strings .TrimSpace (opts .GitPushOptions ["description" ]) // TODO: Add more options?
29
+ description := strings .TrimSpace (opts .GitPushOptions ["description" ])
31
30
objectFormat := git .ObjectFormatFromName (repo .ObjectFormatName )
32
31
userName := strings .ToLower (opts .UserName )
33
32
@@ -56,19 +55,19 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
56
55
}
57
56
58
57
baseBranchName := opts .RefFullNames [i ].ForBranchName ()
59
- curentTopicBranch := ""
58
+ currentTopicBranch := ""
60
59
if ! gitRepo .IsBranchExist (baseBranchName ) {
61
60
// try match refs/for/<target-branch>/<topic-branch>
62
61
for p , v := range baseBranchName {
63
62
if v == '/' && gitRepo .IsBranchExist (baseBranchName [:p ]) && p != len (baseBranchName )- 1 {
64
- curentTopicBranch = baseBranchName [p + 1 :]
63
+ currentTopicBranch = baseBranchName [p + 1 :]
65
64
baseBranchName = baseBranchName [:p ]
66
65
break
67
66
}
68
67
}
69
68
}
70
69
71
- if len (topicBranch ) == 0 && len (curentTopicBranch ) == 0 {
70
+ if len (topicBranch ) == 0 && len (currentTopicBranch ) == 0 {
72
71
results = append (results , private.HookProcReceiveRefResult {
73
72
OriginalRef : opts .RefFullNames [i ],
74
73
OldOID : opts .OldCommitIDs [i ],
@@ -78,18 +77,18 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
78
77
continue
79
78
}
80
79
81
- if len (curentTopicBranch ) == 0 {
82
- curentTopicBranch = topicBranch
80
+ if len (currentTopicBranch ) == 0 {
81
+ currentTopicBranch = topicBranch
83
82
}
84
83
85
84
// because different user maybe want to use same topic,
86
85
// So it's better to make sure the topic branch name
87
- // has user name prefix
86
+ // has username prefix
88
87
var headBranch string
89
- if ! strings .HasPrefix (curentTopicBranch , userName + "/" ) {
90
- headBranch = userName + "/" + curentTopicBranch
88
+ if ! strings .HasPrefix (currentTopicBranch , userName + "/" ) {
89
+ headBranch = userName + "/" + currentTopicBranch
91
90
} else {
92
- headBranch = curentTopicBranch
91
+ headBranch = currentTopicBranch
93
92
}
94
93
95
94
pr , err := issues_model .GetUnmergedPullRequest (ctx , repo .ID , repo .ID , headBranch , baseBranchName , issues_model .PullRequestFlowAGit )
@@ -178,7 +177,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
178
177
continue
179
178
}
180
179
181
- if ! forcePush {
180
+ if ! forcePush . Value () {
182
181
output , _ , err := git .NewCommand (ctx , "rev-list" , "--max-count=1" ).
183
182
AddDynamicArguments (oldCommitID , "^" + opts .NewCommitIDs [i ]).
184
183
RunStdString (& git.RunOpts {Dir : repo .RepoPath (), Env : os .Environ ()})
0 commit comments