2020-09-30 01:11:33 -04:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package print
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-12-08 05:28:54 -05:00
|
|
|
"strconv"
|
2020-09-30 01:11:33 -04:00
|
|
|
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PullDetails print an pull rendered to stdout
|
2020-12-07 23:06:05 -05:00
|
|
|
func PullDetails(pr *gitea.PullRequest, reviews []*gitea.PullReview) {
|
|
|
|
base := pr.Base.Name
|
|
|
|
head := pr.Head.Name
|
|
|
|
if pr.Head.RepoID != pr.Base.RepoID {
|
|
|
|
if pr.Head.Repository != nil {
|
|
|
|
head = pr.Head.Repository.Owner.UserName + ":" + head
|
|
|
|
} else {
|
|
|
|
head = "delete:" + head
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out := fmt.Sprintf(
|
|
|
|
"# #%d %s (%s)\n@%s created %s\t**%s** <- **%s**\n\n%s\n",
|
2020-10-04 22:23:57 -04:00
|
|
|
pr.Index,
|
2020-09-30 01:11:33 -04:00
|
|
|
pr.Title,
|
|
|
|
pr.State,
|
|
|
|
pr.Poster.UserName,
|
2020-10-05 08:23:32 -04:00
|
|
|
FormatTime(*pr.Created),
|
2020-12-07 23:06:05 -05:00
|
|
|
base,
|
|
|
|
head,
|
2020-09-30 01:11:33 -04:00
|
|
|
pr.Body,
|
2020-12-07 23:06:05 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
if len(reviews) != 0 {
|
|
|
|
out += "\n"
|
|
|
|
revMap := make(map[string]gitea.ReviewStateType)
|
|
|
|
for _, review := range reviews {
|
|
|
|
switch review.State {
|
|
|
|
case gitea.ReviewStateApproved,
|
|
|
|
gitea.ReviewStateRequestChanges,
|
|
|
|
gitea.ReviewStateRequestReview:
|
|
|
|
revMap[review.Reviewer.UserName] = review.State
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for k, v := range revMap {
|
|
|
|
out += fmt.Sprintf("\n @%s: %s", k, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if pr.State == gitea.StateOpen && pr.Mergeable {
|
|
|
|
out += "\nNo Conflicts"
|
|
|
|
}
|
|
|
|
|
2020-12-08 05:28:54 -05:00
|
|
|
outputMarkdown(out)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PullsList prints a listing of pulls
|
|
|
|
func PullsList(prs []*gitea.PullRequest, output string) {
|
2020-12-09 17:04:36 -05:00
|
|
|
t := tableWithHeader(
|
2020-12-08 05:28:54 -05:00
|
|
|
"Index",
|
|
|
|
"Title",
|
|
|
|
"State",
|
|
|
|
"Author",
|
|
|
|
"Milestone",
|
|
|
|
"Updated",
|
2020-12-09 17:04:36 -05:00
|
|
|
)
|
2020-12-08 05:28:54 -05:00
|
|
|
|
|
|
|
for _, pr := range prs {
|
|
|
|
if pr == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
author := pr.Poster.FullName
|
|
|
|
if len(author) == 0 {
|
|
|
|
author = pr.Poster.UserName
|
|
|
|
}
|
|
|
|
mile := ""
|
|
|
|
if pr.Milestone != nil {
|
|
|
|
mile = pr.Milestone.Title
|
|
|
|
}
|
2020-12-09 17:04:36 -05:00
|
|
|
t.addRow(
|
|
|
|
strconv.FormatInt(pr.Index, 10),
|
|
|
|
pr.Title,
|
|
|
|
string(pr.State),
|
|
|
|
author,
|
|
|
|
mile,
|
|
|
|
FormatTime(*pr.Updated),
|
2020-12-08 05:28:54 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-12-09 17:04:36 -05:00
|
|
|
t.print(output)
|
2020-09-30 01:11:33 -04:00
|
|
|
}
|