Browse Source

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

Unknwon 8 years ago
parent
commit
8fa6d0d302

+ 1 - 3
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)

File diff suppressed because it is too large
+ 0 - 0
modules/bindata/bindata.go


+ 18 - 14
routers/repo/pull.go

@@ -242,8 +242,11 @@ func ViewPullCommits(ctx *context.Context) {
 		return
 	}
 	pull := issue.PullRequest
-	ctx.Data["Username"] = pull.HeadUserName
-	ctx.Data["Reponame"] = pull.HeadRepo.Name
+
+	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["Username"] = pull.HeadUserName
-	ctx.Data["Reponame"] = pull.HeadRepo.Name
 	ctx.Data["IsImageFile"] = commit.IsImageFile
-	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
 
+	// 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
+
+		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.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
 	}
 

+ 6 - 1
templates/repo/commits_table.tmpl

@@ -41,7 +41,12 @@
 						</td>
 
 						<td class="message collapsing has-emoji">
-							<a rel="nofollow" class="ui sha label" href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{.ID}}">{{ShortSha .ID.String}}</a>
+							{{/* 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>

+ 1 - 1
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>

+ 2 - 2
templates/repo/release/list.tmpl

@@ -64,8 +64,8 @@
 								<a href="{{$.RepoLink}}/src/{{.TagName}}" rel="nofollow"><i class="tag icon"></i> {{.TagName}}</a>
 							</h4>
 							<div class="download">
-								<a href="{{$.RepoLink}}/archive/{{.TagName}}.zip" rel="nofollow"><i class="octicon octicon-file-zip"></i> ZIP</a>
-								<a href="{{$.RepoLink}}/archive/{{.TagName}}.tar.gz"><i class="octicon octicon-file-zip"></i> TAR.GZ</a>
+								<a href="{{$.RepoLink}}/archive/{{.TagName}}.zip" rel="nofollow"><i class="octicon octicon-file-zip"></i>ZIP</a>
+								<a href="{{$.RepoLink}}/archive/{{.TagName}}.tar.gz"><i class="octicon octicon-file-zip"></i>TAR.GZ</a>
 							</div>
 						{{end}}
 						<span class="dot">&nbsp;</span>

Some files were not shown because too many files changed in this diff