forked from forgejo/forgejo
This reverts commit e4238583db
.
Refs: https://codeberg.org/forgejo/forgejo/issues/395
This commit is contained in:
parent
cd299fc44d
commit
cb7ea004ee
9 changed files with 145 additions and 228 deletions
|
@ -9,7 +9,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
|
@ -134,27 +133,6 @@ const (
|
|||
PullRequestStatusAncestor
|
||||
)
|
||||
|
||||
func (status PullRequestStatus) String() string {
|
||||
switch status {
|
||||
case PullRequestStatusConflict:
|
||||
return "CONFLICT"
|
||||
case PullRequestStatusChecking:
|
||||
return "CHECKING"
|
||||
case PullRequestStatusMergeable:
|
||||
return "MERGEABLE"
|
||||
case PullRequestStatusManuallyMerged:
|
||||
return "MANUALLY_MERGED"
|
||||
case PullRequestStatusError:
|
||||
return "ERROR"
|
||||
case PullRequestStatusEmpty:
|
||||
return "EMPTY"
|
||||
case PullRequestStatusAncestor:
|
||||
return "ANCESTOR"
|
||||
default:
|
||||
return strconv.Itoa(int(status))
|
||||
}
|
||||
}
|
||||
|
||||
// PullRequestFlow the flow of pull request
|
||||
type PullRequestFlow int
|
||||
|
||||
|
@ -226,42 +204,6 @@ func DeletePullsByBaseRepoID(ctx context.Context, repoID int64) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// ColorFormat writes a colored string to identify this struct
|
||||
func (pr *PullRequest) ColorFormat(s fmt.State) {
|
||||
if pr == nil {
|
||||
log.ColorFprintf(s, "PR[%d]%s#%d[%s...%s:%s]",
|
||||
log.NewColoredIDValue(0),
|
||||
log.NewColoredValue("<nil>/<nil>"),
|
||||
log.NewColoredIDValue(0),
|
||||
log.NewColoredValue("<nil>"),
|
||||
log.NewColoredValue("<nil>/<nil>"),
|
||||
log.NewColoredValue("<nil>"),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
log.ColorFprintf(s, "PR[%d]", log.NewColoredIDValue(pr.ID))
|
||||
if pr.BaseRepo != nil {
|
||||
log.ColorFprintf(s, "%s#%d[%s...", log.NewColoredValue(pr.BaseRepo.FullName()),
|
||||
log.NewColoredIDValue(pr.Index), log.NewColoredValue(pr.BaseBranch))
|
||||
} else {
|
||||
log.ColorFprintf(s, "Repo[%d]#%d[%s...", log.NewColoredIDValue(pr.BaseRepoID),
|
||||
log.NewColoredIDValue(pr.Index), log.NewColoredValue(pr.BaseBranch))
|
||||
}
|
||||
if pr.HeadRepoID == pr.BaseRepoID {
|
||||
log.ColorFprintf(s, "%s]", log.NewColoredValue(pr.HeadBranch))
|
||||
} else if pr.HeadRepo != nil {
|
||||
log.ColorFprintf(s, "%s:%s]", log.NewColoredValue(pr.HeadRepo.FullName()), log.NewColoredValue(pr.HeadBranch))
|
||||
} else {
|
||||
log.ColorFprintf(s, "Repo[%d]:%s]", log.NewColoredIDValue(pr.HeadRepoID), log.NewColoredValue(pr.HeadBranch))
|
||||
}
|
||||
}
|
||||
|
||||
// String represents the pr as a simple string
|
||||
func (pr *PullRequest) String() string {
|
||||
return log.ColorFormatAsString(pr)
|
||||
}
|
||||
|
||||
// MustHeadUserName returns the HeadRepo's username if failed return blank
|
||||
func (pr *PullRequest) MustHeadUserName() string {
|
||||
if err := pr.LoadHeadRepo(); err != nil {
|
||||
|
@ -313,7 +255,7 @@ func (pr *PullRequest) LoadHeadRepoCtx(ctx context.Context) (err error) {
|
|||
|
||||
pr.HeadRepo, err = repo_model.GetRepositoryByIDCtx(ctx, pr.HeadRepoID)
|
||||
if err != nil && !repo_model.IsErrRepoNotExist(err) { // Head repo maybe deleted, but it should still work
|
||||
return fmt.Errorf("pr[%d].LoadHeadRepo[%d]: %w", pr.ID, pr.HeadRepoID, err)
|
||||
return fmt.Errorf("getRepositoryByID(head): %w", err)
|
||||
}
|
||||
pr.isHeadRepoLoaded = true
|
||||
}
|
||||
|
@ -348,7 +290,7 @@ func (pr *PullRequest) LoadBaseRepoCtx(ctx context.Context) (err error) {
|
|||
|
||||
pr.BaseRepo, err = repo_model.GetRepositoryByIDCtx(ctx, pr.BaseRepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("pr[%d].LoadBaseRepo[%d]: %w", pr.ID, pr.BaseRepoID, err)
|
||||
return fmt.Errorf("repo_model.GetRepositoryByID(base): %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue