diff options
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/pull.go | 48 | ||||
-rw-r--r-- | routers/routes/routes.go | 1 |
2 files changed, 48 insertions, 1 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 9de8268957..515b6a91f8 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -9,6 +9,7 @@ package repo import ( "container/list" "fmt" + "io" "path" "strings" @@ -1033,7 +1034,7 @@ func DownloadPullDiff(ctx *context.Context) { return } - // Redirect elsewhere if it's not a pull request + // Return not found if it's not a pull request if !issue.IsPull { ctx.Handle(404, "DownloadPullDiff", fmt.Errorf("Issue is not a pull request")) @@ -1054,3 +1055,48 @@ func DownloadPullDiff(ctx *context.Context) { ctx.ServeFileContent(patch) } + +// DownloadPullPatch render a pull's raw patch +func DownloadPullPatch(ctx *context.Context) { + issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + if err != nil { + if models.IsErrIssueNotExist(err) { + ctx.Handle(404, "GetIssueByIndex", err) + } else { + ctx.Handle(500, "GetIssueByIndex", err) + } + return + } + + // Return not found if it's not a pull request + if !issue.IsPull { + ctx.Handle(404, "DownloadPullDiff", + fmt.Errorf("Issue is not a pull request")) + return + } + + pr := issue.PullRequest + + if err = pr.GetHeadRepo(); err != nil { + ctx.Handle(500, "GetHeadRepo", err) + return + } + + headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath()) + if err != nil { + ctx.Handle(500, "OpenRepository", err) + return + } + + patch, err := headGitRepo.GetFormatPatch(pr.MergeBase, pr.HeadBranch) + if err != nil { + ctx.Handle(500, "GetFormatPatch", err) + return + } + + _, err = io.Copy(ctx, patch) + if err != nil { + ctx.Handle(500, "io.Copy", err) + return + } +} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 3e00f55ebf..fc7401fc9a 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -625,6 +625,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/pulls/:index", func() { m.Get(".diff", repo.DownloadPullDiff) + m.Get(".patch", repo.DownloadPullPatch) m.Get("/commits", context.RepoRef(), repo.ViewPullCommits) m.Get("/files", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ViewPullFiles) m.Post("/merge", reqRepoWriter, bindIgnErr(auth.MergePullRequestForm{}), repo.MergePullRequest) |