support show notification in forked repo

This commit is contained in:
yp05327 2023-07-11 01:39:58 +00:00
parent b3e3b7311c
commit df97530659
2 changed files with 25 additions and 3 deletions

View File

@ -982,7 +982,23 @@ func renderCode(ctx *context.Context) {
ctx.ServerError("GetBaseRepo", err)
return
}
branches, err := git_model.FindRecentlyPushedNewBranches(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID, ctx.Repo.CommitID)
baseRepo := ctx.Repo.Repository
latestCommit := ctx.Repo.Commit
if ctx.Repo.Repository.IsFork {
baseRepo = ctx.Repo.Repository.BaseRepo
repoPath := repo_model.RepoPath(baseRepo.OwnerName, baseRepo.Name)
gitRepo, err := git.OpenRepository(ctx, repoPath)
if err != nil {
ctx.ServerError("OpenRepository", err)
return
}
latestCommit, err = gitRepo.GetBranchCommit(baseRepo.DefaultBranch)
if err != nil {
ctx.ServerError("GetBranchCommit", err)
return
}
}
branches, err := git_model.FindRecentlyPushedNewBranches(ctx, baseRepo.ID, ctx.Doer.ID, latestCommit.ID.String())
if err != nil {
ctx.ServerError("FindRecentlyPushedNewBranches", err)
return

View File

@ -1,9 +1,15 @@
{{range .RecentlyPushedNewBranches}}
{{$pullRepo := $.Repository}}
{{$baseRepo := $.Repository}}
{{$branchName := .Name}}
{{if .Repo}}
{{$pullRepo = .Repo}}
{{$branchName = (print $pullRepo.FullName ":" .Name)}}
{{if and $.Repository.IsFork}}
{{$baseRepo = $.Repository.BaseRepo}}
{{end}}
{{if not (eq .Repo.ID $.Repository.ID)}}
{{$branchName = (print .Repo.FullName ":" .Name)}}
{{end}}
{{end}}
<div class="ui positive message gt-df gt-ac">
<div class="gt-f1">
@ -11,7 +17,7 @@
{{$.locale.Tr "repo.pulls.recently_pushed_new_branches" (PathEscapeSegments $branchName) $timeSince | Safe}}
</div>
<a aria-role="button" class="ui compact positive button gt-m-0" href="{{$pullRepo.ComposeBranchCompareURL $.Repository (PathEscapeSegments .Name)}}">
<a aria-role="button" class="ui compact positive button gt-m-0" href="{{$pullRepo.ComposeBranchCompareURL $baseRepo (PathEscapeSegments .Name)}}">
{{$.locale.Tr "repo.pulls.compare_changes"}}
</a>
</div>