aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-07-01 02:18:13 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2019-07-01 09:18:13 +0800
commit3563650bdb273045c55400ee9520a0f78fc90e76 (patch)
tree29fa8994dd254361d42c7055db17ddef5143bb16 /models
parente5a4d784e8dda105832a28ccee0d593bf9dd6348 (diff)
downloadgitea-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 'models')
-rw-r--r--models/branches.go2
-rw-r--r--models/helper_environment.go22
-rw-r--r--models/pull.go2
3 files changed, 18 insertions, 8 deletions
diff --git a/models/branches.go b/models/branches.go
index df3b69aa21..fa4215d6a0 100644
--- a/models/branches.go
+++ b/models/branches.go
@@ -19,6 +19,8 @@ import (
const (
// ProtectedBranchRepoID protected Repo ID
ProtectedBranchRepoID = "GITEA_REPO_ID"
+ // ProtectedBranchPRID protected Repo PR ID
+ ProtectedBranchPRID = "GITEA_PR_ID"
)
// ProtectedBranch struct
diff --git a/models/helper_environment.go b/models/helper_environment.go
index 199eb6062d..0460fc3df5 100644
--- a/models/helper_environment.go
+++ b/models/helper_environment.go
@@ -12,26 +12,34 @@ import (
// PushingEnvironment returns an os environment to allow hooks to work on push
func PushingEnvironment(doer *User, repo *Repository) []string {
+ return FullPushingEnvironment(doer, doer, repo, 0)
+}
+
+// FullPushingEnvironment returns an os environment to allow hooks to work on push
+func FullPushingEnvironment(author, committer *User, repo *Repository, prID int64) []string {
isWiki := "false"
if strings.HasSuffix(repo.Name, ".wiki") {
isWiki = "true"
}
- sig := doer.NewGitSig()
+ authorSig := author.NewGitSig()
+ committerSig := committer.NewGitSig()
// We should add "SSH_ORIGINAL_COMMAND=gitea-internal",
// once we have hook and pushing infrastructure working correctly
return append(os.Environ(),
- "GIT_AUTHOR_NAME="+sig.Name,
- "GIT_AUTHOR_EMAIL="+sig.Email,
- "GIT_COMMITTER_NAME="+sig.Name,
- "GIT_COMMITTER_EMAIL="+sig.Email,
+ "GIT_AUTHOR_NAME="+authorSig.Name,
+ "GIT_AUTHOR_EMAIL="+authorSig.Email,
+ "GIT_COMMITTER_NAME="+committerSig.Name,
+ "GIT_COMMITTER_EMAIL="+committerSig.Email,
EnvRepoName+"="+repo.Name,
EnvRepoUsername+"="+repo.MustOwnerName(),
EnvRepoIsWiki+"="+isWiki,
- EnvPusherName+"="+doer.Name,
- EnvPusherID+"="+fmt.Sprintf("%d", doer.ID),
+ EnvPusherName+"="+committer.Name,
+ EnvPusherID+"="+fmt.Sprintf("%d", committer.ID),
ProtectedBranchRepoID+"="+fmt.Sprintf("%d", repo.ID),
+ ProtectedBranchPRID+"="+fmt.Sprintf("%d", prID),
+ "SSH_ORIGINAL_COMMAND=gitea-internal",
)
}
diff --git a/models/pull.go b/models/pull.go
index eac36235bb..6ee2ec555d 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -876,7 +876,7 @@ func (pr *PullRequest) UpdatePatch() (err error) {
if err = pr.GetHeadRepo(); err != nil {
return fmt.Errorf("GetHeadRepo: %v", err)
} else if pr.HeadRepo == nil {
- log.Trace("PullRequest[%d].UpdatePatch: ignored cruppted data", pr.ID)
+ log.Trace("PullRequest[%d].UpdatePatch: ignored corrupted data", pr.ID)
return nil
}