mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-25 12:01:36 +01:00
Show PR CI status (#306)
fix layout of pr reviews show PR CI status put conflict info in status list remove line show merged state deduplicate reviews by user Co-authored-by: Norwin Roosen <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/306 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: 6543 <6543@obermui.de> Co-Authored-By: Norwin <noerw@noreply.gitea.io> Co-Committed-By: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
parent
782a6318f3
commit
83b73ce78e
@ -60,6 +60,11 @@ func runPullDetail(cmd *cli.Context, index string) error {
|
|||||||
fmt.Printf("error while loading reviews: %v\n", err)
|
fmt.Printf("error while loading reviews: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
print.PullDetails(pr, reviews)
|
ci, _, err := client.GetCombinedStatus(ctx.Owner, ctx.Repo, pr.Head.Sha)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("error while loading CI: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
print.PullDetails(pr, reviews, ci)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,21 @@ package print
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ciStatusSymbols = map[gitea.StatusState]string{
|
||||||
|
gitea.StatusSuccess: "✓ ",
|
||||||
|
gitea.StatusPending: "⭮ ",
|
||||||
|
gitea.StatusWarning: "⚠ ",
|
||||||
|
gitea.StatusError: "✘ ",
|
||||||
|
gitea.StatusFailure: "❌ ",
|
||||||
|
}
|
||||||
|
|
||||||
// PullDetails print an pull rendered to stdout
|
// PullDetails print an pull rendered to stdout
|
||||||
func PullDetails(pr *gitea.PullRequest, reviews []*gitea.PullReview) {
|
func PullDetails(pr *gitea.PullRequest, reviews []*gitea.PullReview, ciStatus *gitea.CombinedStatus) {
|
||||||
base := pr.Base.Name
|
base := pr.Base.Name
|
||||||
head := pr.Head.Name
|
head := pr.Head.Name
|
||||||
if pr.Head.RepoID != pr.Base.RepoID {
|
if pr.Head.RepoID != pr.Base.RepoID {
|
||||||
@ -23,11 +32,16 @@ func PullDetails(pr *gitea.PullRequest, reviews []*gitea.PullReview) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state := pr.State
|
||||||
|
if pr.Merged != nil {
|
||||||
|
state = "merged"
|
||||||
|
}
|
||||||
|
|
||||||
out := fmt.Sprintf(
|
out := fmt.Sprintf(
|
||||||
"# #%d %s (%s)\n@%s created %s\t**%s** <- **%s**\n\n%s\n",
|
"# #%d %s (%s)\n@%s created %s\t**%s** <- **%s**\n\n%s\n\n",
|
||||||
pr.Index,
|
pr.Index,
|
||||||
pr.Title,
|
pr.Title,
|
||||||
pr.State,
|
state,
|
||||||
pr.Poster.UserName,
|
pr.Poster.UserName,
|
||||||
FormatTime(*pr.Created),
|
FormatTime(*pr.Created),
|
||||||
base,
|
base,
|
||||||
@ -35,29 +49,70 @@ func PullDetails(pr *gitea.PullRequest, reviews []*gitea.PullReview) {
|
|||||||
pr.Body,
|
pr.Body,
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(reviews) != 0 {
|
if ciStatus != nil || len(reviews) != 0 || pr.State == gitea.StateOpen {
|
||||||
out += "\n"
|
out += "---\n"
|
||||||
revMap := make(map[string]gitea.ReviewStateType)
|
}
|
||||||
for _, review := range reviews {
|
|
||||||
switch review.State {
|
out += formatReviews(reviews)
|
||||||
case gitea.ReviewStateApproved,
|
|
||||||
gitea.ReviewStateRequestChanges,
|
if ciStatus != nil {
|
||||||
gitea.ReviewStateRequestReview:
|
var summary, errors string
|
||||||
revMap[review.Reviewer.UserName] = review.State
|
for _, s := range ciStatus.Statuses {
|
||||||
|
summary += ciStatusSymbols[s.State]
|
||||||
|
if s.State != gitea.StatusSuccess {
|
||||||
|
errors += fmt.Sprintf(" - [**%s**:\t%s](%s)\n", s.Context, s.Description, s.TargetURL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for k, v := range revMap {
|
if len(ciStatus.Statuses) != 0 {
|
||||||
out += fmt.Sprintf("\n @%s: %s", k, v)
|
out += fmt.Sprintf("- CI: %s\n%s", summary, errors)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pr.State == gitea.StateOpen && pr.Mergeable {
|
if pr.State == gitea.StateOpen {
|
||||||
out += "\nNo Conflicts"
|
if pr.Mergeable {
|
||||||
|
out += "- No Conflicts\n"
|
||||||
|
} else {
|
||||||
|
out += "- **Conflicting files**\n"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outputMarkdown(out)
|
outputMarkdown(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func formatReviews(reviews []*gitea.PullReview) string {
|
||||||
|
result := ""
|
||||||
|
if len(reviews) == 0 {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// deduplicate reviews by user (via review time & userID),
|
||||||
|
reviewByUser := make(map[int64]*gitea.PullReview)
|
||||||
|
for _, review := range reviews {
|
||||||
|
switch review.State {
|
||||||
|
case gitea.ReviewStateApproved,
|
||||||
|
gitea.ReviewStateRequestChanges,
|
||||||
|
gitea.ReviewStateRequestReview:
|
||||||
|
if r, ok := reviewByUser[review.Reviewer.ID]; !ok || review.Submitted.After(r.Submitted) {
|
||||||
|
reviewByUser[review.Reviewer.ID] = review
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// group reviews by type
|
||||||
|
usersByState := make(map[gitea.ReviewStateType][]string)
|
||||||
|
for _, r := range reviewByUser {
|
||||||
|
u := r.Reviewer.UserName
|
||||||
|
users := usersByState[r.State]
|
||||||
|
usersByState[r.State] = append(users, u)
|
||||||
|
}
|
||||||
|
|
||||||
|
// stringify
|
||||||
|
for state, user := range usersByState {
|
||||||
|
result += fmt.Sprintf("- %s by @%s\n", state, strings.Join(user, ", @"))
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// PullsList prints a listing of pulls
|
// PullsList prints a listing of pulls
|
||||||
func PullsList(prs []*gitea.PullRequest, output string) {
|
func PullsList(prs []*gitea.PullRequest, output string) {
|
||||||
t := tableWithHeader(
|
t := tableWithHeader(
|
||||||
|
@ -76,7 +76,7 @@ func CreatePull(login *config.Login, repoOwner, repoName, base, head, title, des
|
|||||||
return fmt.Errorf("Could not create PR from %s to %s:%s: %s", head, repoOwner, base, err)
|
return fmt.Errorf("Could not create PR from %s to %s:%s: %s", head, repoOwner, base, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
print.PullDetails(pr, nil)
|
print.PullDetails(pr, nil, nil)
|
||||||
|
|
||||||
fmt.Println(pr.HTMLURL)
|
fmt.Println(pr.HTMLURL)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user