Skip to content

Commit 7620492

Browse files
committed
fix bug create/edit wiki pages when code master branch protected
1 parent e3a2c74 commit 7620492

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

models/helper_environment.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212

1313
// PushingEnvironment returns an os environment to allow hooks to work on push
1414
func PushingEnvironment(doer *User, repo *Repository) []string {
15-
return FullPushingEnvironment(doer, doer, repo, 0)
15+
return FullPushingEnvironment(doer, doer, repo.MustOwnerName(), repo.Name, repo.ID, 0)
1616
}
1717

1818
// FullPushingEnvironment returns an os environment to allow hooks to work on push
19-
func FullPushingEnvironment(author, committer *User, repo *Repository, prID int64) []string {
19+
func FullPushingEnvironment(author, committer *User, ownerName, repoName string, repoID, prID int64) []string {
2020
isWiki := "false"
21-
if strings.HasSuffix(repo.Name, ".wiki") {
21+
if strings.HasSuffix(repoName, ".wiki") {
2222
isWiki = "true"
2323
}
2424

@@ -32,12 +32,12 @@ func FullPushingEnvironment(author, committer *User, repo *Repository, prID int6
3232
"GIT_AUTHOR_EMAIL="+authorSig.Email,
3333
"GIT_COMMITTER_NAME="+committerSig.Name,
3434
"GIT_COMMITTER_EMAIL="+committerSig.Email,
35-
EnvRepoName+"="+repo.Name,
36-
EnvRepoUsername+"="+repo.MustOwnerName(),
35+
EnvRepoName+"="+repoName,
36+
EnvRepoUsername+"="+ownerName,
3737
EnvRepoIsWiki+"="+isWiki,
3838
EnvPusherName+"="+committer.Name,
3939
EnvPusherID+"="+fmt.Sprintf("%d", committer.ID),
40-
ProtectedBranchRepoID+"="+fmt.Sprintf("%d", repo.ID),
40+
ProtectedBranchRepoID+"="+fmt.Sprintf("%d", repoID),
4141
ProtectedBranchPRID+"="+fmt.Sprintf("%d", prID),
4242
"SSH_ORIGINAL_COMMAND=gitea-internal",
4343
)

models/wiki.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,14 @@ func (repo *Repository) updateWikiPage(doer *User, oldWikiName, newWikiName, con
217217
if err := git.Push(basePath, git.PushOptions{
218218
Remote: "origin",
219219
Branch: fmt.Sprintf("%s:%s%s", commitHash.String(), git.BranchPrefix, "master"),
220-
Env: PushingEnvironment(doer, repo),
220+
Env: FullPushingEnvironment(
221+
doer,
222+
doer,
223+
repo.MustOwnerName(),
224+
repo.Name+".wiki",
225+
repo.ID,
226+
0,
227+
),
221228
}); err != nil {
222229
log.Error("%v", err)
223230
return fmt.Errorf("Push: %v", err)

modules/pull/merge.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,14 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor
240240
headUser = doer
241241
}
242242

243-
env := models.FullPushingEnvironment(headUser, doer, pr.BaseRepo, pr.ID)
243+
env := models.FullPushingEnvironment(
244+
headUser,
245+
doer,
246+
pr.BaseRepo.MustOwnerName(),
247+
pr.BaseRepo.Name,
248+
pr.BaseRepo.ID,
249+
pr.ID,
250+
)
244251

245252
// Push back to upstream.
246253
if err := git.NewCommand("push", "origin", pr.BaseBranch).RunInDirTimeoutEnvPipeline(env, -1, tmpBasePath, nil, &errbuf); err != nil {

0 commit comments

Comments
 (0)