Skip to content

Commit 1270e2a

Browse files
guillep2ksapk
authored andcommitted
Create PR on Current Repository by Default (#8670) (#9141)
* 'update' * Send push tag event when release created * send tag create event while release created in UI * update to go v1.13 * fix gofmt error * fix #8576 create pull request on current repository by default
1 parent 29fa3a0 commit 1270e2a

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

routers/repo/compare.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,41 @@ func PrepareCompareDiff(
346346
return false
347347
}
348348

349+
// parseBaseRepoInfo parse base repository if current repo is forked.
350+
// The "base" here means the repository where current repo forks from,
351+
// not the repository fetch from current URL.
352+
func parseBaseRepoInfo(ctx *context.Context, repo *models.Repository) error {
353+
if !repo.IsFork {
354+
return nil
355+
}
356+
if err := repo.GetBaseRepo(); err != nil {
357+
return err
358+
}
359+
if err := repo.BaseRepo.GetOwnerName(); err != nil {
360+
return err
361+
}
362+
baseGitRepo, err := git.OpenRepository(models.RepoPath(repo.BaseRepo.OwnerName, repo.BaseRepo.Name))
363+
if err != nil {
364+
return err
365+
}
366+
ctx.Data["BaseRepoBranches"], err = baseGitRepo.GetBranches()
367+
if err != nil {
368+
return err
369+
}
370+
return nil
371+
}
372+
349373
// CompareDiff show different from one commit to another commit
350374
func CompareDiff(ctx *context.Context) {
351375
headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
352376
if ctx.Written() {
353377
return
354378
}
355379
defer headGitRepo.Close()
380+
if err := parseBaseRepoInfo(ctx, headRepo); err != nil {
381+
ctx.ServerError("parseBaseRepoInfo", err)
382+
return
383+
}
356384

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

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)