diff options
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/status.go | 13 | ||||
-rw-r--r-- | routers/repo/pull.go | 24 |
2 files changed, 28 insertions, 9 deletions
diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go index 487e62c91d..1aa4f4e1a1 100644 --- a/routers/api/v1/repo/status.go +++ b/routers/api/v1/repo/status.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/repofiles" api "code.gitea.io/gitea/modules/structs" ) @@ -57,17 +58,12 @@ func NewCommitStatus(ctx *context.APIContext, form api.CreateStatusOption) { Description: form.Description, Context: form.Context, } - if err := models.NewCommitStatus(ctx.Repo.Repository, ctx.User, sha, status); err != nil { - ctx.Error(500, "NewCommitStatus", err) + if err := repofiles.CreateCommitStatus(ctx.Repo.Repository, ctx.User, sha, status); err != nil { + ctx.Error(500, "CreateCommitStatus", err) return } - newStatus, err := models.GetCommitStatus(ctx.Repo.Repository, sha, status) - if err != nil { - ctx.Error(500, "GetCommitStatus", err) - return - } - ctx.JSON(201, newStatus.APIFormat()) + ctx.JSON(201, status.APIFormat()) } // GetCommitStatuses returns all statuses for any given commit hash @@ -140,6 +136,7 @@ func getCommitStatuses(ctx *context.APIContext, sha string) { statuses, err := models.GetCommitStatuses(repo, sha, page) if err != nil { ctx.Error(500, "GetCommitStatuses", fmt.Errorf("GetCommitStatuses[%s, %s, %d]: %v", repo.FullName(), sha, page, err)) + return } apiStatuses := make([]*api.Status, 0, len(statuses)) diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 36b0d047b1..4c377bb364 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -321,15 +321,37 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare setMergeTarget(ctx, pull) var headGitRepo *git.Repository + var headBranchExist bool + // HeadRepo may be missing if pull.HeadRepo != nil { headGitRepo, err = git.OpenRepository(pull.HeadRepo.RepoPath()) if err != nil { ctx.ServerError("OpenRepository", err) return nil } + + headBranchExist = headGitRepo.IsBranchExist(pull.HeadBranch) + + if headBranchExist { + sha, err := headGitRepo.GetBranchCommitID(pull.HeadBranch) + if err != nil { + ctx.ServerError("GetBranchCommitID", err) + return nil + } + + commitStatuses, err := models.GetLatestCommitStatus(repo, sha, 0) + if err != nil { + ctx.ServerError("GetLatestCommitStatus", err) + return nil + } + if len(commitStatuses) > 0 { + ctx.Data["LatestCommitStatuses"] = commitStatuses + ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses) + } + } } - if pull.HeadRepo == nil || !headGitRepo.IsBranchExist(pull.HeadBranch) { + if pull.HeadRepo == nil || !headBranchExist { ctx.Data["IsPullRequestBroken"] = true ctx.Data["HeadTarget"] = "deleted" ctx.Data["NumCommits"] = 0 |