diff options
author | zeripath <art27@cantab.net> | 2019-07-01 02:18:13 +0100 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-07-01 09:18:13 +0800 |
commit | 3563650bdb273045c55400ee9520a0f78fc90e76 (patch) | |
tree | 29fa8994dd254361d42c7055db17ddef5143bb16 /modules | |
parent | e5a4d784e8dda105832a28ccee0d593bf9dd6348 (diff) | |
download | gitea-3563650bdb273045c55400ee9520a0f78fc90e76.tar.gz gitea-3563650bdb273045c55400ee9520a0f78fc90e76.zip |
#6946 Run hooks on merge/edit and cope with protected branches (#6961)
* Fix #6946 by checking PullRequest ID on pushing
* Ensure we have the owner name, the pr attributes and the the issue
* Fix TestSearchRepo by waiting till indexing is done
* Update integrations/repo_search_test.go
* changes as per @mrsdizzie
* missing comma
* Spelling mistake
* Fix full pushing environment
Diffstat (limited to 'modules')
-rw-r--r-- | modules/private/hook.go | 4 | ||||
-rw-r--r-- | modules/pull/merge.go | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/modules/private/hook.go b/modules/private/hook.go index 7e2a475d4b..caa3819555 100644 --- a/modules/private/hook.go +++ b/modules/private/hook.go @@ -29,11 +29,12 @@ type HookOptions struct { UserName string GitObjectDirectory string GitAlternativeObjectDirectories string + ProtectedBranchID int64 } // HookPreReceive check whether the provided commits are allowed func HookPreReceive(ownerName, repoName string, opts HookOptions) (int, string) { - reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s?old=%s&new=%s&ref=%s&userID=%d&gitObjectDirectory=%s&gitAlternativeObjectDirectories=%s", + reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s?old=%s&new=%s&ref=%s&userID=%d&gitObjectDirectory=%s&gitAlternativeObjectDirectories=%s&prID=%d", url.PathEscape(ownerName), url.PathEscape(repoName), url.QueryEscape(opts.OldCommitID), @@ -42,6 +43,7 @@ func HookPreReceive(ownerName, repoName string, opts HookOptions) (int, string) opts.UserID, url.QueryEscape(opts.GitObjectDirectory), url.QueryEscape(opts.GitAlternativeObjectDirectories), + opts.ProtectedBranchID, ) resp, err := newInternalRequest(reqURL, "GET").Response() diff --git a/modules/pull/merge.go b/modules/pull/merge.go index e12ede81d6..5685336a2b 100644 --- a/modules/pull/merge.go +++ b/modules/pull/merge.go @@ -231,7 +231,17 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor } } - env := models.PushingEnvironment(doer, pr.BaseRepo) + headUser, err := models.GetUserByName(pr.HeadUserName) + if err != nil { + if !models.IsErrUserNotExist(err) { + log.Error("Can't find user: %s for head repository - %v", pr.HeadUserName, err) + return err + } + log.Error("Can't find user: %s for head repository - defaulting to doer: %s - %v", pr.HeadUserName, doer.Name, err) + headUser = doer + } + + env := models.FullPushingEnvironment(headUser, doer, pr.BaseRepo, pr.ID) // Push back to upstream. if err := git.NewCommand("push", "origin", pr.BaseBranch).RunInDirTimeoutEnvPipeline(env, -1, tmpBasePath, nil, &errbuf); err != nil { |