func ToIssue(issue *models.Issue) *api.Issue { apiLabels := make([]*api.Label, len(issue.Labels)) for i := range issue.Labels { apiLabels[i] = ToLabel(issue.Labels[i]) } apiIssue := &api.Issue{ ID: issue.ID, Index: issue.Index, State: issue.State(), Title: issue.Name, Body: issue.Content, User: ToUser(issue.Poster), Labels: apiLabels, Assignee: ToUser(issue.Assignee), Milestone: ToMilestone(issue.Milestone), Comments: issue.NumComments, Created: issue.Created, Updated: issue.Updated, } if issue.IsPull { if err := issue.GetPullRequest(); err != nil { log.Error(4, "GetPullRequest", err) } else { apiIssue.PullRequest = &api.PullRequestMeta{ HasMerged: issue.PullRequest.HasMerged, } if issue.PullRequest.HasMerged { apiIssue.PullRequest.Merged = &issue.PullRequest.Merged } } } return apiIssue }
func PrepareViewPullInfo(ctx *context.Context, pull *models.Issue) *git.PullRequestInfo { repo := ctx.Repo.Repository ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadBranch ctx.Data["BaseTarget"] = ctx.Repo.Owner.Name + "/" + pull.BaseBranch var ( headGitRepo *git.Repository err error ) if err = pull.GetHeadRepo(); err != nil { ctx.Handle(500, "GetHeadRepo", err) return nil } if pull.HeadRepo != nil { headGitRepo, err = git.OpenRepository(pull.HeadRepo.RepoPath()) if err != nil { ctx.Handle(500, "OpenRepository", err) return nil } } if pull.HeadRepo == nil || !headGitRepo.IsBranchExist(pull.HeadBranch) { ctx.Data["IsPullReuqestBroken"] = true ctx.Data["HeadTarget"] = "deleted" ctx.Data["NumCommits"] = 0 ctx.Data["NumFiles"] = 0 return nil } prInfo, err := headGitRepo.GetPullRequestInfo(models.RepoPath(repo.Owner.Name, repo.Name), pull.BaseBranch, pull.HeadBranch) if err != nil { if strings.Contains(err.Error(), "fatal: Not a valid object name") { ctx.Data["IsPullReuqestBroken"] = true ctx.Data["BaseTarget"] = "deleted" ctx.Data["NumCommits"] = 0 ctx.Data["NumFiles"] = 0 return nil } ctx.Handle(500, "GetPullRequestInfo", err) return nil } ctx.Data["NumCommits"] = prInfo.Commits.Len() ctx.Data["NumFiles"] = prInfo.NumFiles return prInfo }
func PrepareMergedViewPullInfo(ctx *middleware.Context, pull *models.Issue) { ctx.Data["HasMerged"] = true var err error if err = pull.GetMerger(); err != nil { ctx.Handle(500, "GetMerger", err) return } ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadBranch ctx.Data["BaseTarget"] = ctx.Repo.Owner.Name + "/" + pull.BaseBranch ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, pull.MergedCommitID) if err != nil { ctx.Handle(500, "Repo.GitRepo.CommitsCountBetween", err) return } ctx.Data["NumFiles"], err = ctx.Repo.GitRepo.FilesCountBetween(pull.MergeBase, pull.MergedCommitID) if err != nil { ctx.Handle(500, "Repo.GitRepo.FilesCountBetween", err) return } }