|
|
@ -5,6 +5,8 @@
|
|
|
|
package convert
|
|
|
|
package convert
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/git"
|
|
|
|
"code.gitea.io/gitea/modules/git"
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
@ -23,10 +25,12 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest {
|
|
|
|
headCommit *git.Commit
|
|
|
|
headCommit *git.Commit
|
|
|
|
err error
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if err = pr.Issue.LoadRepo(); err != nil {
|
|
|
|
if err = pr.Issue.LoadRepo(); err != nil {
|
|
|
|
log.Error("loadRepo[%d]: %v", pr.ID, err)
|
|
|
|
log.Error("pr.Issue.LoadRepo[%d]: %v", pr.ID, err)
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
apiIssue := pr.Issue.APIFormat()
|
|
|
|
apiIssue := pr.Issue.APIFormat()
|
|
|
|
if pr.BaseRepo == nil {
|
|
|
|
if pr.BaseRepo == nil {
|
|
|
|
pr.BaseRepo, err = models.GetRepositoryByID(pr.BaseRepoID)
|
|
|
|
pr.BaseRepo, err = models.GetRepositoryByID(pr.BaseRepoID)
|
|
|
@ -35,17 +39,13 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if pr.HeadRepo == nil {
|
|
|
|
if pr.HeadRepoID != 0 && pr.HeadRepo == nil {
|
|
|
|
pr.HeadRepo, err = models.GetRepositoryByID(pr.HeadRepoID)
|
|
|
|
pr.HeadRepo, err = models.GetRepositoryByID(pr.HeadRepoID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil && !models.IsErrRepoNotExist(err) {
|
|
|
|
log.Error("GetRepositoryById[%d]: %v", pr.ID, err)
|
|
|
|
log.Error("GetRepositoryById[%d]: %v", pr.ID, err)
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = pr.Issue.LoadRepo(); err != nil {
|
|
|
|
}
|
|
|
|
log.Error("pr.Issue.loadRepo[%d]: %v", pr.ID, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
apiPullRequest := &api.PullRequest{
|
|
|
|
apiPullRequest := &api.PullRequest{
|
|
|
@ -99,6 +99,7 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest {
|
|
|
|
apiPullRequest.Base = apiBaseBranchInfo
|
|
|
|
apiPullRequest.Base = apiBaseBranchInfo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pr.HeadRepo != nil {
|
|
|
|
headBranch, err = repo_module.GetBranch(pr.HeadRepo, pr.HeadBranch)
|
|
|
|
headBranch, err = repo_module.GetBranch(pr.HeadRepo, pr.HeadBranch)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
if git.IsErrBranchNotExist(err) {
|
|
|
|
if git.IsErrBranchNotExist(err) {
|
|
|
@ -127,6 +128,13 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
apiPullRequest.Head = apiHeadBranchInfo
|
|
|
|
apiPullRequest.Head = apiHeadBranchInfo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
apiPullRequest.Head = &api.PRBranchInfo{
|
|
|
|
|
|
|
|
Name: pr.HeadBranch,
|
|
|
|
|
|
|
|
Ref: fmt.Sprintf("refs/pull/%d/head", pr.Index),
|
|
|
|
|
|
|
|
RepoID: -1,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if pr.Status != models.PullRequestStatusChecking {
|
|
|
|
if pr.Status != models.PullRequestStatusChecking {
|
|
|
|
mergeable := !(pr.Status == models.PullRequestStatusConflict || pr.Status == models.PullRequestStatusError) && !pr.IsWorkInProgress()
|
|
|
|
mergeable := !(pr.Status == models.PullRequestStatusConflict || pr.Status == models.PullRequestStatusError) && !pr.IsWorkInProgress()
|
|
|
|