Skip to content

Commit 74a4d01

Browse files
committed
fix go-gitea#8576 create pull request on current repository by default
1 parent 13bf498 commit 74a4d01

File tree

4 files changed

+35
-46
lines changed

4 files changed

+35
-46
lines changed

routers/repo/compare.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,40 @@ func PrepareCompareDiff(
339339
return false
340340
}
341341

342+
// parseBaseRepoInfo parse base repository if current repo is forked.
343+
// The "base" here means the repository where current repo forks from,
344+
// not the repository fetch from current URL.
345+
func parseBaseRepoInfo(ctx *context.Context, repo *models.Repository) error {
346+
if !repo.IsFork {
347+
return nil
348+
}
349+
if err := repo.GetBaseRepo(); err != nil {
350+
return err
351+
}
352+
if err := repo.BaseRepo.GetOwnerName(); err != nil {
353+
return err
354+
}
355+
baseGitRepo, err := git.OpenRepository(models.RepoPath(repo.BaseRepo.OwnerName, repo.BaseRepo.Name))
356+
if err != nil {
357+
return err
358+
}
359+
ctx.Data["BaseRepoBranches"], err = baseGitRepo.GetBranches()
360+
if err != nil {
361+
return err
362+
}
363+
return nil
364+
}
365+
342366
// CompareDiff show different from one commit to another commit
343367
func CompareDiff(ctx *context.Context) {
344368
headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
345369
if ctx.Written() {
346370
return
347371
}
372+
if err := parseBaseRepoInfo(ctx, headRepo); err != nil {
373+
ctx.ServerError("parseBaseRepoInfo", err)
374+
return
375+
}
348376

349377
nothingToCompare := PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch)
350378
if ctx.Written() {

services/release/release.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"code.gitea.io/gitea/modules/git"
1414
"code.gitea.io/gitea/modules/log"
1515
"code.gitea.io/gitea/modules/process"
16-
"code.gitea.io/gitea/modules/setting"
1716
api "code.gitea.io/gitea/modules/structs"
1817
"code.gitea.io/gitea/modules/timeutil"
1918
)
@@ -38,49 +37,6 @@ func createTag(gitRepo *git.Repository, rel *models.Release) error {
3837
return err
3938
}
4039
rel.LowerTagName = strings.ToLower(rel.TagName)
41-
42-
// Prepare Webhook
43-
if err := rel.LoadAttributes(); err != nil {
44-
log.Error("LoadAttributes: %v", err)
45-
} else {
46-
47-
defer func() {
48-
go models.HookQueue.Add(rel.Repo.ID)
49-
}()
50-
51-
var shaSum string
52-
mode, _ := models.AccessLevel(rel.Publisher, rel.Repo)
53-
apiRepo := rel.Repo.APIFormat(mode)
54-
apiPusher := rel.Publisher.APIFormat()
55-
shaSum, err = gitRepo.GetTagCommitID(rel.TagName)
56-
if err != nil {
57-
log.Error("GetTagCommitID[%s]: %v", rel.TagName, err)
58-
}
59-
60-
// Tag Create
61-
if err = models.PrepareWebhooks(rel.Repo, models.HookEventCreate, &api.CreatePayload{
62-
Ref: git.TagPrefix + rel.TagName,
63-
Sha: shaSum,
64-
RefType: "tag",
65-
Repo: apiRepo,
66-
Sender: apiPusher,
67-
}); err != nil {
68-
return fmt.Errorf("PrepareWebhooks: %v", err)
69-
}
70-
// Tag Push
71-
if err = models.PrepareWebhooks(rel.Repo, models.HookEventPush, &api.PushPayload{
72-
Ref: git.TagPrefix + rel.TagName,
73-
Before: git.EmptySHA,
74-
After: shaSum,
75-
CompareURL: setting.AppURL,
76-
Commits: make([]*api.PayloadCommit, 0),
77-
Repo: apiRepo,
78-
Pusher: apiPusher,
79-
Sender: apiPusher,
80-
}); err != nil {
81-
return fmt.Errorf("PrepareWebhooks: %v", err)
82-
}
83-
}
8440
}
8541
commit, err := gitRepo.GetTagCommit(rel.TagName)
8642
if err != nil {

templates/repo/diff/compare.tmpl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
{{range .Branches}}
2929
<div class="item {{if eq $.BaseBranch .}}selected{{end}}" data-url="{{$.RepoLink}}/compare/{{EscapePound .}}...{{if not $.PullRequestCtx.SameRepo}}{{$.HeadUser.Name}}:{{end}}{{EscapePound $.HeadBranch}}">{{$.BaseName}}:{{.}}</div>
3030
{{end}}
31+
{{if .Repository.IsFork}}
32+
{{range .BaseRepoBranches}}
33+
<div class="item" data-url="{{$.PullRequestCtx.BaseRepo.Link}}/compare/{{EscapePound .}}...{{$.HeadUser.Name}}:{{EscapePound $.HeadBranch}}">{{$.PullRequestCtx.BaseRepo.OwnerName}}:{{.}}</div>
34+
{{end}}
35+
{{end}}
3136
</div>
3237
</div>
3338
</div>
@@ -54,7 +59,7 @@
5459

5560
{{if .IsNothingToCompare}}
5661
<div class="ui segment">{{.i18n.Tr "repo.pulls.nothing_to_compare"}}</div>
57-
{{else if .PageIsComparePull}}
62+
{{else if .PageIsComparePull}}
5863
{{if .HasPullRequest}}
5964
<div class="ui segment">
6065
{{.i18n.Tr "repo.pulls.has_pull_request" $.RepoLink $.RepoRelPath .PullRequest.Index | Safe}}

templates/repo/issue/list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{{if .PageIsIssueList}}
1515
<a class="ui green button" href="{{.RepoLink}}/issues/new">{{.i18n.Tr "repo.issues.new"}}</a>
1616
{{else}}
17-
<a class="ui green button {{if not .PullRequestCtx.Allowed}}disabled{{end}}" href="{{if .PullRequestCtx.Allowed}}{{.PullRequestCtx.BaseRepo.Link}}/compare/{{.PullRequestCtx.BaseRepo.DefaultBranch | EscapePound}}...{{if ne .Repository.Owner.Name .PullRequestCtx.BaseRepo.Owner.Name}}{{.Repository.Owner.Name}}:{{end}}{{.Repository.DefaultBranch | EscapePound}}{{end}}">{{.i18n.Tr "repo.pulls.new"}}</a>
17+
<a class="ui green button {{if not .PullRequestCtx.Allowed}}disabled{{end}}" href="{{if .PullRequestCtx.Allowed}}{{.Repository.Link}}/compare/{{.Repository.DefaultBranch | EscapePound}}...{{if ne .Repository.Owner.Name .PullRequestCtx.BaseRepo.Owner.Name}}{{.Repository.Owner.Name}}:{{end}}{{.Repository.DefaultBranch | EscapePound}}{{end}}">{{.i18n.Tr "repo.pulls.new"}}</a>
1818
{{end}}
1919
</div>
2020
{{else}}

0 commit comments

Comments
 (0)