Skip to content

Commit 37958e4

Browse files
authored
Rename pull request GetGitRefName to GetGitHeadRefName (#35093)
1 parent bc78a9a commit 37958e4

File tree

27 files changed

+81
-81
lines changed

27 files changed

+81
-81
lines changed

models/issues/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ func (pr *PullRequest) getReviewedByLines(ctx context.Context, writer io.Writer)
414414
}
415415

416416
// GetGitRefName returns git ref for hidden pull request branch
417-
func (pr *PullRequest) GetGitRefName() string {
417+
func (pr *PullRequest) GetGitHeadRefName() string {
418418
return fmt.Sprintf("%s%d/head", git.PullPrefix, pr.Index)
419419
}
420420

modules/migration/pullrequest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (p *PullRequest) IsForkPullRequest() bool {
5050
}
5151

5252
// GetGitRefName returns pull request relative path to head
53-
func (p PullRequest) GetGitRefName() string {
53+
func (p PullRequest) GetGitHeadRefName() string {
5454
return fmt.Sprintf("%s%d/head", git.PullPrefix, p.Number)
5555
}
5656

routers/api/v1/repo/pull.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,9 +1461,9 @@ func GetPullRequestCommits(ctx *context.APIContext) {
14611461
defer closer.Close()
14621462

14631463
if pr.HasMerged {
1464-
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitRefName(), false, false)
1464+
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitHeadRefName(), false, false)
14651465
} else {
1466-
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitRefName(), false, false)
1466+
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitHeadRefName(), false, false)
14671467
}
14681468
if err != nil {
14691469
ctx.APIErrorInternal(err)
@@ -1584,16 +1584,16 @@ func GetPullRequestFiles(ctx *context.APIContext) {
15841584

15851585
var prInfo *git.CompareInfo
15861586
if pr.HasMerged {
1587-
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitRefName(), true, false)
1587+
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitHeadRefName(), true, false)
15881588
} else {
1589-
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitRefName(), true, false)
1589+
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitHeadRefName(), true, false)
15901590
}
15911591
if err != nil {
15921592
ctx.APIErrorInternal(err)
15931593
return
15941594
}
15951595

1596-
headCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitRefName())
1596+
headCommitID, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
15971597
if err != nil {
15981598
ctx.APIErrorInternal(err)
15991599
return

routers/api/v1/repo/pull_review.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func CreatePullReview(ctx *context.APIContext) {
336336
}
337337
defer closer.Close()
338338

339-
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
339+
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
340340
if err != nil {
341341
ctx.APIErrorInternal(err)
342342
return
@@ -455,7 +455,7 @@ func SubmitPullReview(ctx *context.APIContext) {
455455
return
456456
}
457457

458-
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitRefName())
458+
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pr.GetGitHeadRefName())
459459
if err != nil {
460460
ctx.APIErrorInternal(err)
461461
return

routers/web/repo/issue_comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func NewComment(ctx *context.Context) {
103103
// check whether the ref of PR <refs/pulls/pr_index/head> in base repo is consistent with the head commit of head branch in the head repo
104104
// get head commit of PR
105105
if pull.Flow == issues_model.PullRequestFlowGithub {
106-
prHeadRef := pull.GetGitRefName()
106+
prHeadRef := pull.GetGitHeadRefName()
107107
if err := pull.LoadBaseRepo(ctx); err != nil {
108108
ctx.ServerError("Unable to load base repo", err)
109109
return

routers/web/repo/issue_view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ func preparePullViewSigning(ctx *context.Context, issue *issues_model.Issue) {
492492
pull := issue.PullRequest
493493
ctx.Data["WillSign"] = false
494494
if ctx.Doer != nil {
495-
sign, key, _, err := asymkey_service.SignMerge(ctx, pull, ctx.Doer, pull.BaseRepo.RepoPath(), pull.BaseBranch, pull.GetGitRefName())
495+
sign, key, _, err := asymkey_service.SignMerge(ctx, pull, ctx.Doer, pull.BaseRepo.RepoPath(), pull.BaseBranch, pull.GetGitHeadRefName())
496496
ctx.Data["WillSign"] = sign
497497
ctx.Data["SigningKey"] = key
498498
if err != nil {

routers/web/repo/pull.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func GetPullDiffStats(ctx *context.Context) {
196196
}
197197

198198
// do not report 500 server error to end users if error occurs, otherwise a PR missing ref won't be able to view.
199-
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pull.GetGitRefName())
199+
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pull.GetGitHeadRefName())
200200
if err != nil {
201201
log.Error("Failed to GetRefCommitID: %v, repo: %v", err, ctx.Repo.Repository.FullName())
202202
return
@@ -218,13 +218,13 @@ func GetMergedBaseCommitID(ctx *context.Context, issue *issues_model.Issue) stri
218218
if pull.MergeBase == "" {
219219
var commitSHA, parentCommit string
220220
// If there is a head or a patch file, and it is readable, grab info
221-
commitSHA, err := ctx.Repo.GitRepo.GetRefCommitID(pull.GetGitRefName())
221+
commitSHA, err := ctx.Repo.GitRepo.GetRefCommitID(pull.GetGitHeadRefName())
222222
if err != nil {
223223
// Head File does not exist, try the patch
224224
commitSHA, err = ctx.Repo.GitRepo.ReadPatchCommit(pull.Index)
225225
if err == nil {
226226
// Recreate pull head in files for next time
227-
if err := ctx.Repo.GitRepo.SetReference(pull.GetGitRefName(), commitSHA); err != nil {
227+
if err := ctx.Repo.GitRepo.SetReference(pull.GetGitHeadRefName(), commitSHA); err != nil {
228228
log.Error("Could not write head file", err)
229229
}
230230
} else {
@@ -274,7 +274,7 @@ func prepareMergedViewPullInfo(ctx *context.Context, issue *issues_model.Issue)
274274
baseCommit := GetMergedBaseCommitID(ctx, issue)
275275

276276
compareInfo, err := ctx.Repo.GitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(),
277-
baseCommit, pull.GetGitRefName(), false, false)
277+
baseCommit, pull.GetGitHeadRefName(), false, false)
278278
if err != nil {
279279
if strings.Contains(err.Error(), "fatal: Not a valid object name") || strings.Contains(err.Error(), "unknown revision or path not in the working tree") {
280280
ctx.Data["IsPullRequestBroken"] = true
@@ -354,9 +354,9 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
354354
ctx.Data["BaseTarget"] = pull.BaseBranch
355355
ctx.Data["HeadTarget"] = pull.HeadBranch
356356

357-
sha, err := baseGitRepo.GetRefCommitID(pull.GetGitRefName())
357+
sha, err := baseGitRepo.GetRefCommitID(pull.GetGitHeadRefName())
358358
if err != nil {
359-
ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitRefName()), err)
359+
ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitHeadRefName()), err)
360360
return nil
361361
}
362362
commitStatuses, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptionsAll)
@@ -374,7 +374,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
374374
}
375375

376376
compareInfo, err := baseGitRepo.GetCompareInfo(pull.BaseRepo.RepoPath(),
377-
pull.MergeBase, pull.GetGitRefName(), false, false)
377+
pull.MergeBase, pull.GetGitHeadRefName(), false, false)
378378
if err != nil {
379379
if strings.Contains(err.Error(), "fatal: Not a valid object name") {
380380
ctx.Data["IsPullRequestBroken"] = true
@@ -407,12 +407,12 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
407407
if pull.Flow == issues_model.PullRequestFlowGithub {
408408
headBranchExist = gitrepo.IsBranchExist(ctx, pull.HeadRepo, pull.HeadBranch)
409409
} else {
410-
headBranchExist = gitrepo.IsReferenceExist(ctx, pull.BaseRepo, pull.GetGitRefName())
410+
headBranchExist = gitrepo.IsReferenceExist(ctx, pull.BaseRepo, pull.GetGitHeadRefName())
411411
}
412412

413413
if headBranchExist {
414414
if pull.Flow != issues_model.PullRequestFlowGithub {
415-
headBranchSha, err = baseGitRepo.GetRefCommitID(pull.GetGitRefName())
415+
headBranchSha, err = baseGitRepo.GetRefCommitID(pull.GetGitHeadRefName())
416416
} else {
417417
headBranchSha, err = headGitRepo.GetBranchCommitID(pull.HeadBranch)
418418
}
@@ -435,7 +435,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
435435
ctx.Data["GetCommitMessages"] = ""
436436
}
437437

438-
sha, err := baseGitRepo.GetRefCommitID(pull.GetGitRefName())
438+
sha, err := baseGitRepo.GetRefCommitID(pull.GetGitHeadRefName())
439439
if err != nil {
440440
if git.IsErrNotExist(err) {
441441
ctx.Data["IsPullRequestBroken"] = true
@@ -451,7 +451,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
451451
ctx.Data["NumFiles"] = 0
452452
return nil
453453
}
454-
ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitRefName()), err)
454+
ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitHeadRefName()), err)
455455
return nil
456456
}
457457

@@ -522,7 +522,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
522522
}
523523

524524
compareInfo, err := baseGitRepo.GetCompareInfo(pull.BaseRepo.RepoPath(),
525-
git.BranchPrefix+pull.BaseBranch, pull.GetGitRefName(), false, false)
525+
git.BranchPrefix+pull.BaseBranch, pull.GetGitHeadRefName(), false, false)
526526
if err != nil {
527527
if strings.Contains(err.Error(), "fatal: Not a valid object name") {
528528
ctx.Data["IsPullRequestBroken"] = true
@@ -698,7 +698,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
698698
return
699699
}
700700

701-
headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
701+
headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitHeadRefName())
702702
if err != nil {
703703
ctx.ServerError("GetRefCommitID", err)
704704
return
@@ -1509,7 +1509,7 @@ func CleanUpPullRequest(ctx *context.Context) {
15091509
}()
15101510

15111511
// Check if branch has no new commits
1512-
headCommitID, err := gitBaseRepo.GetRefCommitID(pr.GetGitRefName())
1512+
headCommitID, err := gitBaseRepo.GetRefCommitID(pr.GetGitHeadRefName())
15131513
if err != nil {
15141514
log.Error("GetRefCommitID: %v", err)
15151515
ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))

routers/web/repo/pull_review.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func RenderNewCodeCommentForm(ctx *context.Context) {
4949
ctx.Data["PageIsPullFiles"] = true
5050
ctx.Data["Issue"] = issue
5151
ctx.Data["CurrentReview"] = currentReview
52-
pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(issue.PullRequest.GetGitRefName())
52+
pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(issue.PullRequest.GetGitHeadRefName())
5353
if err != nil {
5454
ctx.ServerError("GetRefCommitID", err)
5555
return
@@ -199,7 +199,7 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment, ori
199199
ctx.ServerError("comment.Issue.LoadPullRequest", err)
200200
return
201201
}
202-
pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(comment.Issue.PullRequest.GetGitRefName())
202+
pullHeadCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(comment.Issue.PullRequest.GetGitHeadRefName())
203203
if err != nil {
204204
ctx.ServerError("GetRefCommitID", err)
205205
return

services/actions/notifier_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (input *notifyInput) WithPayload(payload api.Payloader) *notifyInput {
104104
func (input *notifyInput) WithPullRequest(pr *issues_model.PullRequest) *notifyInput {
105105
input.PullRequest = pr
106106
if input.Ref == "" {
107-
input.Ref = git.RefName(pr.GetGitRefName())
107+
input.Ref = git.RefName(pr.GetGitHeadRefName())
108108
}
109109
return input
110110
}

services/agit/agit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
165165
log.Trace("Pull request created: %d/%d", repo.ID, prIssue.ID)
166166

167167
results = append(results, private.HookProcReceiveRefResult{
168-
Ref: pr.GetGitRefName(),
168+
Ref: pr.GetGitHeadRefName(),
169169
OriginalRef: opts.RefFullNames[i],
170170
OldOID: objectFormat.EmptyObjectID().String(),
171171
NewOID: opts.NewCommitIDs[i],
@@ -182,7 +182,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
182182
return nil, fmt.Errorf("unable to load base repository for PR[%d] Error: %w", pr.ID, err)
183183
}
184184

185-
oldCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
185+
oldCommitID, err := gitRepo.GetRefCommitID(pr.GetGitHeadRefName())
186186
if err != nil {
187187
return nil, fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err)
188188
}
@@ -260,7 +260,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
260260
results = append(results, private.HookProcReceiveRefResult{
261261
OldOID: oldCommitID,
262262
NewOID: opts.NewCommitIDs[i],
263-
Ref: pr.GetGitRefName(),
263+
Ref: pr.GetGitHeadRefName(),
264264
OriginalRef: opts.RefFullNames[i],
265265
IsForcePush: isForcePush,
266266
IsCreatePR: false,

0 commit comments

Comments
 (0)