diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-01-10 15:53:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-10 15:53:53 +0800 |
commit | 384c2b342ec01fadb520572666127cb5564e1050 (patch) | |
tree | 73357abe356721749e212b90049444cf279a97e4 /models/pull.go | |
parent | 8878cfa4a125348d92f8163988ac9d3279f27e75 (diff) | |
download | gitea-384c2b342ec01fadb520572666127cb5564e1050.tar.gz gitea-384c2b342ec01fadb520572666127cb5564e1050.zip |
Move pull request api convert to convert package (#9664)
* Move pull request api convert to convert package
* Rename ToPullRequest to ToAPIPullRequest
Diffstat (limited to 'models/pull.go')
-rw-r--r-- | models/pull.go | 134 |
1 files changed, 0 insertions, 134 deletions
diff --git a/models/pull.go b/models/pull.go index a7f51683db..e2a35c5920 100644 --- a/models/pull.go +++ b/models/pull.go @@ -13,7 +13,6 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" ) @@ -397,139 +396,6 @@ func (pr *PullRequest) GetGitRefName() string { return fmt.Sprintf("refs/pull/%d/head", pr.Index) } -// APIFormat assumes following fields have been assigned with valid values: -// Required - Issue -// Optional - Merger -func (pr *PullRequest) APIFormat() *api.PullRequest { - return pr.apiFormat(x) -} - -func (pr *PullRequest) apiFormat(e Engine) *api.PullRequest { - var ( - baseBranch *git.Branch - headBranch *git.Branch - baseCommit *git.Commit - headCommit *git.Commit - err error - ) - if err = pr.Issue.loadRepo(e); err != nil { - log.Error("loadRepo[%d]: %v", pr.ID, err) - return nil - } - apiIssue := pr.Issue.apiFormat(e) - if pr.BaseRepo == nil { - pr.BaseRepo, err = getRepositoryByID(e, pr.BaseRepoID) - if err != nil { - log.Error("GetRepositoryById[%d]: %v", pr.ID, err) - return nil - } - } - if pr.HeadRepo == nil { - pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID) - if err != nil { - log.Error("GetRepositoryById[%d]: %v", pr.ID, err) - return nil - } - } - - if err = pr.Issue.loadRepo(e); err != nil { - log.Error("pr.Issue.loadRepo[%d]: %v", pr.ID, err) - return nil - } - - apiPullRequest := &api.PullRequest{ - ID: pr.ID, - URL: pr.Issue.HTMLURL(), - Index: pr.Index, - Poster: apiIssue.Poster, - Title: apiIssue.Title, - Body: apiIssue.Body, - Labels: apiIssue.Labels, - Milestone: apiIssue.Milestone, - Assignee: apiIssue.Assignee, - Assignees: apiIssue.Assignees, - State: apiIssue.State, - Comments: apiIssue.Comments, - HTMLURL: pr.Issue.HTMLURL(), - DiffURL: pr.Issue.DiffURL(), - PatchURL: pr.Issue.PatchURL(), - HasMerged: pr.HasMerged, - MergeBase: pr.MergeBase, - Deadline: apiIssue.Deadline, - Created: pr.Issue.CreatedUnix.AsTimePtr(), - Updated: pr.Issue.UpdatedUnix.AsTimePtr(), - } - baseBranch, err = pr.BaseRepo.GetBranch(pr.BaseBranch) - if err != nil { - if git.IsErrBranchNotExist(err) { - apiPullRequest.Base = nil - } else { - log.Error("GetBranch[%s]: %v", pr.BaseBranch, err) - return nil - } - } else { - apiBaseBranchInfo := &api.PRBranchInfo{ - Name: pr.BaseBranch, - Ref: pr.BaseBranch, - RepoID: pr.BaseRepoID, - Repository: pr.BaseRepo.innerAPIFormat(e, AccessModeNone, false), - } - baseCommit, err = baseBranch.GetCommit() - if err != nil { - if git.IsErrNotExist(err) { - apiBaseBranchInfo.Sha = "" - } else { - log.Error("GetCommit[%s]: %v", baseBranch.Name, err) - return nil - } - } else { - apiBaseBranchInfo.Sha = baseCommit.ID.String() - } - apiPullRequest.Base = apiBaseBranchInfo - } - - headBranch, err = pr.HeadRepo.GetBranch(pr.HeadBranch) - if err != nil { - if git.IsErrBranchNotExist(err) { - apiPullRequest.Head = nil - } else { - log.Error("GetBranch[%s]: %v", pr.HeadBranch, err) - return nil - } - } else { - apiHeadBranchInfo := &api.PRBranchInfo{ - Name: pr.HeadBranch, - Ref: pr.HeadBranch, - RepoID: pr.HeadRepoID, - Repository: pr.HeadRepo.innerAPIFormat(e, AccessModeNone, false), - } - headCommit, err = headBranch.GetCommit() - if err != nil { - if git.IsErrNotExist(err) { - apiHeadBranchInfo.Sha = "" - } else { - log.Error("GetCommit[%s]: %v", headBranch.Name, err) - return nil - } - } else { - apiHeadBranchInfo.Sha = headCommit.ID.String() - } - apiPullRequest.Head = apiHeadBranchInfo - } - - if pr.Status != PullRequestStatusChecking { - mergeable := !(pr.Status == PullRequestStatusConflict || pr.Status == PullRequestStatusError) && !pr.IsWorkInProgress() - apiPullRequest.Mergeable = mergeable - } - if pr.HasMerged { - apiPullRequest.Merged = pr.MergedUnix.AsTimePtr() - apiPullRequest.MergedCommitID = &pr.MergedCommitID - apiPullRequest.MergedBy = pr.Merger.APIFormat() - } - - return apiPullRequest -} - func (pr *PullRequest) getHeadRepo(e Engine) (err error) { pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID) if err != nil && !IsErrRepoNotExist(err) { |