Pull DetailView: Show more pull informations (#271)

Pull Detailview: add head/base-branch, reviews, mergable info

print info if reviews can not be loaded

No Conflicts

Reviewed-on: https://gitea.com/gitea/tea/pulls/271
Reviewed-by: Norwin <noerw@noreply.gitea.io>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-Authored-By: 6543 <6543@obermui.de>
Co-Committed-By: 6543 <6543@obermui.de>
This commit is contained in:
6543 2020-12-08 12:06:05 +08:00
parent d0e05e8be2
commit 2b11f408fd
4 changed files with 52 additions and 9 deletions

View File

@ -5,12 +5,15 @@
package cmd package cmd
import ( import (
"fmt"
"code.gitea.io/tea/cmd/flags" "code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/cmd/pulls" "code.gitea.io/tea/cmd/pulls"
"code.gitea.io/tea/modules/config" "code.gitea.io/tea/modules/config"
"code.gitea.io/tea/modules/print" "code.gitea.io/tea/modules/print"
"code.gitea.io/tea/modules/utils" "code.gitea.io/tea/modules/utils"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
@ -40,16 +43,22 @@ func runPulls(ctx *cli.Context) error {
func runPullDetail(index string) error { func runPullDetail(index string) error {
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue) login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
idx, err := utils.ArgToIndex(index) idx, err := utils.ArgToIndex(index)
if err != nil { if err != nil {
return err return err
} }
pr, _, err := login.Client().GetPullRequest(owner, repo, idx)
client := login.Client()
pr, _, err := client.GetPullRequest(owner, repo, idx)
if err != nil { if err != nil {
return err return err
} }
print.PullDetails(pr) reviews, _, err := client.ListPullReviews(owner, repo, idx, gitea.ListPullReviewsOptions{})
if err != nil {
fmt.Printf("error while loading reviews: %v\n", err)
}
print.PullDetails(pr, reviews)
return nil return nil
} }

View File

@ -143,7 +143,7 @@ func runPullsCreate(ctx *cli.Context) error {
log.Fatalf("could not create PR from %s to %s:%s: %s", head, ownerArg, base, err) log.Fatalf("could not create PR from %s to %s:%s: %s", head, ownerArg, base, err)
} }
print.PullDetails(pr) print.PullDetails(pr, nil)
fmt.Println(pr.HTMLURL) fmt.Println(pr.HTMLURL)
return err return err

View File

@ -13,7 +13,7 @@ import (
// IssueDetails print an issue rendered to stdout // IssueDetails print an issue rendered to stdout
func IssueDetails(issue *gitea.Issue) { func IssueDetails(issue *gitea.Issue) {
OutputMarkdown(fmt.Sprintf( OutputMarkdown(fmt.Sprintf(
"# #%d %s (%s)\n%s created %s\n\n%s\n", "# #%d %s (%s)\n@%s created %s\n\n%s\n",
issue.Index, issue.Index,
issue.Title, issue.Title,
issue.State, issue.State,

View File

@ -11,14 +11,48 @@ import (
) )
// PullDetails print an pull rendered to stdout // PullDetails print an pull rendered to stdout
func PullDetails(pr *gitea.PullRequest) { func PullDetails(pr *gitea.PullRequest, reviews []*gitea.PullReview) {
OutputMarkdown(fmt.Sprintf( base := pr.Base.Name
"# #%d %s (%s)\n%s created %s\n\n%s\n", 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",
pr.Index, pr.Index,
pr.Title, pr.Title,
pr.State, pr.State,
pr.Poster.UserName, pr.Poster.UserName,
FormatTime(*pr.Created), FormatTime(*pr.Created),
base,
head,
pr.Body, pr.Body,
)) )
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"
}
OutputMarkdown(out)
} }