mirror of
https://github.com/go-gitea/gitea
synced 2025-11-21 21:58:21 +00:00
Add GITEA_PR_INDEX env variable to githooks (#35938)
`GITEA_PR_ID` is already part of the env variables available in the githooks, but it contains a database ID instead of commonly used index that is part of `owner/repo!index`
This commit is contained in:
@@ -25,6 +25,7 @@ const (
|
||||
EnvKeyID = "GITEA_KEY_ID" // public key ID
|
||||
EnvDeployKeyID = "GITEA_DEPLOY_KEY_ID"
|
||||
EnvPRID = "GITEA_PR_ID"
|
||||
EnvPRIndex = "GITEA_PR_INDEX" // not used by Gitea at the moment, it is for custom git hooks
|
||||
EnvPushTrigger = "GITEA_PUSH_TRIGGER"
|
||||
EnvIsInternal = "GITEA_INTERNAL_PUSH"
|
||||
EnvAppURL = "GITEA_ROOT_URL"
|
||||
@@ -50,11 +51,11 @@ func InternalPushingEnvironment(doer *user_model.User, repo *repo_model.Reposito
|
||||
|
||||
// PushingEnvironment returns an os environment to allow hooks to work on push
|
||||
func PushingEnvironment(doer *user_model.User, repo *repo_model.Repository) []string {
|
||||
return FullPushingEnvironment(doer, doer, repo, repo.Name, 0)
|
||||
return FullPushingEnvironment(doer, doer, repo, repo.Name, 0, 0)
|
||||
}
|
||||
|
||||
// FullPushingEnvironment returns an os environment to allow hooks to work on push
|
||||
func FullPushingEnvironment(author, committer *user_model.User, repo *repo_model.Repository, repoName string, prID int64) []string {
|
||||
func FullPushingEnvironment(author, committer *user_model.User, repo *repo_model.Repository, repoName string, prID, prIndex int64) []string {
|
||||
isWiki := "false"
|
||||
if strings.HasSuffix(repoName, ".wiki") {
|
||||
isWiki = "true"
|
||||
@@ -75,6 +76,7 @@ func FullPushingEnvironment(author, committer *user_model.User, repo *repo_model
|
||||
EnvPusherID+"="+strconv.FormatInt(committer.ID, 10),
|
||||
EnvRepoID+"="+strconv.FormatInt(repo.ID, 10),
|
||||
EnvPRID+"="+strconv.FormatInt(prID, 10),
|
||||
EnvPRIndex+"="+strconv.FormatInt(prIndex, 10),
|
||||
EnvAppURL+"="+setting.AppURL,
|
||||
"SSH_ORIGINAL_COMMAND=gitea-internal",
|
||||
)
|
||||
|
||||
@@ -403,6 +403,7 @@ func doMergeAndPush(ctx context.Context, pr *issues_model.PullRequest, doer *use
|
||||
pr.BaseRepo,
|
||||
pr.BaseRepo.Name,
|
||||
pr.ID,
|
||||
pr.Index,
|
||||
)
|
||||
|
||||
mergeCtx.env = append(mergeCtx.env, repo_module.EnvPushTrigger+"="+string(pushTrigger))
|
||||
|
||||
@@ -80,6 +80,7 @@ func updateHeadByRebaseOnToBase(ctx context.Context, pr *issues_model.PullReques
|
||||
pr.HeadRepo,
|
||||
pr.HeadRepo.Name,
|
||||
pr.ID,
|
||||
pr.Index,
|
||||
)).
|
||||
WithDir(mergeCtx.tmpBasePath).
|
||||
WithStdout(mergeCtx.outbuf).
|
||||
|
||||
@@ -223,6 +223,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
repo,
|
||||
repo.Name+".wiki",
|
||||
0,
|
||||
0,
|
||||
),
|
||||
}); err != nil {
|
||||
log.Error("Push failed: %v", err)
|
||||
@@ -341,6 +342,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
|
||||
repo,
|
||||
repo.Name+".wiki",
|
||||
0,
|
||||
0,
|
||||
),
|
||||
}); err != nil {
|
||||
if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) {
|
||||
|
||||
Reference in New Issue
Block a user