77 "context"
88 "fmt"
99 "os"
10- "strconv"
1110 "strings"
1211
1312 issues_model "code.gitea.io/gitea/models/issues"
@@ -24,10 +23,10 @@ import (
2423// ProcReceive handle proc receive work
2524func ProcReceive (ctx context.Context , repo * repo_model.Repository , gitRepo * git.Repository , opts * private.HookOptions ) ([]private.HookProcReceiveRefResult , error ) {
2625 results := make ([]private.HookProcReceiveRefResult , 0 , len (opts .OldCommitIDs ))
26+ forcePush := opts .GitPushOptions .Bool (private .GitPushOptionForcePush )
2727 topicBranch := opts .GitPushOptions ["topic" ]
28- forcePush , _ := strconv .ParseBool (opts .GitPushOptions ["force-push" ])
2928 title := strings .TrimSpace (opts .GitPushOptions ["title" ])
30- description := strings .TrimSpace (opts .GitPushOptions ["description" ]) // TODO: Add more options?
29+ description := strings .TrimSpace (opts .GitPushOptions ["description" ])
3130 objectFormat := git .ObjectFormatFromName (repo .ObjectFormatName )
3231 userName := strings .ToLower (opts .UserName )
3332
@@ -56,19 +55,19 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
5655 }
5756
5857 baseBranchName := opts .RefFullNames [i ].ForBranchName ()
59- curentTopicBranch := ""
58+ currentTopicBranch := ""
6059 if ! gitRepo .IsBranchExist (baseBranchName ) {
6160 // try match refs/for/<target-branch>/<topic-branch>
6261 for p , v := range baseBranchName {
6362 if v == '/' && gitRepo .IsBranchExist (baseBranchName [:p ]) && p != len (baseBranchName )- 1 {
64- curentTopicBranch = baseBranchName [p + 1 :]
63+ currentTopicBranch = baseBranchName [p + 1 :]
6564 baseBranchName = baseBranchName [:p ]
6665 break
6766 }
6867 }
6968 }
7069
71- if len (topicBranch ) == 0 && len (curentTopicBranch ) == 0 {
70+ if len (topicBranch ) == 0 && len (currentTopicBranch ) == 0 {
7271 results = append (results , private.HookProcReceiveRefResult {
7372 OriginalRef : opts .RefFullNames [i ],
7473 OldOID : opts .OldCommitIDs [i ],
@@ -78,18 +77,18 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
7877 continue
7978 }
8079
81- if len (curentTopicBranch ) == 0 {
82- curentTopicBranch = topicBranch
80+ if len (currentTopicBranch ) == 0 {
81+ currentTopicBranch = topicBranch
8382 }
8483
8584 // because different user maybe want to use same topic,
8685 // So it's better to make sure the topic branch name
87- // has user name prefix
86+ // has username prefix
8887 var headBranch string
89- if ! strings .HasPrefix (curentTopicBranch , userName + "/" ) {
90- headBranch = userName + "/" + curentTopicBranch
88+ if ! strings .HasPrefix (currentTopicBranch , userName + "/" ) {
89+ headBranch = userName + "/" + currentTopicBranch
9190 } else {
92- headBranch = curentTopicBranch
91+ headBranch = currentTopicBranch
9392 }
9493
9594 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.
178177 continue
179178 }
180179
181- if ! forcePush {
180+ if ! forcePush . Value () {
182181 output , _ , err := git .NewCommand (ctx , "rev-list" , "--max-count=1" ).
183182 AddDynamicArguments (oldCommitID , "^" + opts .NewCommitIDs [i ]).
184183 RunStdString (& git.RunOpts {Dir : repo .RepoPath (), Env : os .Environ ()})
0 commit comments