Browse Source

repo/pull: handle head repository of merged pull requests deleted

pull/4280/head
Unknwon 8 years ago
parent
commit
8fa6d0d302
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 4
      cmd/web.go
  2. 4
      modules/bindata/bindata.go
  3. 20
      routers/repo/pull.go
  4. 5
      templates/repo/commits_table.tmpl
  5. 2
      templates/repo/diff/box.tmpl

4
cmd/web.go

@ -616,9 +616,7 @@ func runWeb(ctx *cli.Context) error {
}, ignSignIn, context.RepoAssignment(), context.RepoRef())
m.Group("/:username", func() {
m.Group("", func() {
m.Get("/:reponame", repo.Home)
}, ignSignIn, context.RepoAssignment(true), context.RepoRef())
m.Get("/:reponame", ignSignIn, context.RepoAssignment(true), context.RepoRef(), repo.Home)
m.Group("/:reponame", func() {
m.Head("/tasks/trigger", repo.TriggerTask)

4
modules/bindata/bindata.go

File diff suppressed because one or more lines are too long

20
routers/repo/pull.go

@ -242,8 +242,11 @@ func ViewPullCommits(ctx *context.Context) {
return
}
pull := issue.PullRequest
if pull.HeadRepo != nil {
ctx.Data["Username"] = pull.HeadUserName
ctx.Data["Reponame"] = pull.HeadRepo.Name
}
var commits *list.List
if pull.HasMerged {
@ -362,16 +365,21 @@ func ViewPullFiles(ctx *context.Context) {
return
}
headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
ctx.Data["IsImageFile"] = commit.IsImageFile
// It is possible head repo has been deleted for merged pull requests
if pull.HeadRepo != nil {
ctx.Data["Username"] = pull.HeadUserName
ctx.Data["Reponame"] = pull.HeadRepo.Name
ctx.Data["IsImageFile"] = commit.IsImageFile
headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", endCommitID)
ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", startCommitID)
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "raw", endCommitID)
ctx.Data["RequireHighlightJS"] = true
}
ctx.Data["RequireHighlightJS"] = true
ctx.HTML(200, PULL_FILES)
}
@ -387,11 +395,7 @@ func MergePullRequest(ctx *context.Context) {
pr, err := models.GetPullRequestByIssueID(issue.ID)
if err != nil {
if models.IsErrPullRequestNotExist(err) {
ctx.Handle(404, "GetPullRequestByIssueID", nil)
} else {
ctx.Handle(500, "GetPullRequestByIssueID", err)
}
ctx.NotFoundOrServerError("GetPullRequestByIssueID", models.IsErrPullRequestNotExist, err)
return
}

5
templates/repo/commits_table.tmpl

@ -41,7 +41,12 @@
</td>
<td class="message collapsing has-emoji">
{{/* Username or Reponame doesn't present we assume the source repository no longer exists */}}
{{if not (and $.Username $.Reponame)}}
<span class="ui sha label">{{ShortSha .ID.String}}</span>
{{else}}
<a rel="nofollow" class="ui sha label" href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{.ID}}">{{ShortSha .ID.String}}</a>
{{end}}
<span {{if gt .ParentCount 1}}class="grey text"{{end}}>{{RenderCommitMessage false .Summary $.RepoLink $.Repository.ComposeMetas}}</span>
</td>
<td class="grey text right aligned">{{TimeSince .Author.When $.Lang}}</td>

2
templates/repo/diff/box.tmpl

@ -71,7 +71,7 @@
<div class="ui right">
{{if $file.IsDeleted}}
<a class="ui basic grey tiny button" rel="nofollow" href="{{EscapePound $.BeforeSourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
{{else}}
{{else if $.SourcePath}} {{/* No SourcePath we assume the source repository no longer exists */}}
<a class="ui basic grey tiny button" rel="nofollow" href="{{EscapePound $.SourcePath}}/{{EscapePound .Name}}">{{$.i18n.Tr "repo.diff.view_file"}}</a>
{{end}}
</div>

Loading…
Cancel
Save