mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
revert: tea 1.0 rewrite (#1122–#1126) (#1146)
Reverts #1126, #1125, #1124, #1123 and #1122. `go.mod` keeps the Go 1.26 line with toolchain `go1.26.9` (instead of the original `go1.26.6`) so the security fix from #1131 isn't lost. reopens #69 reopens #141 reopens #162 reopens #172 reopens #197 reopens #232 reopens #240 reopens #246 reopens #323 reopens #325 reopens #326 reopens #328 reopens #344 reopens #351 reopens #373 reopens #403 reopens #406 reopens #417 reopens #430 reopens #457 reopens #480 reopens #482 reopens #489 reopens #490 reopens #498 reopens #500 reopens #504 reopens #510 reopens #516 reopens #523 reopens #556 reopens #560 reopens #569 reopens #571 reopens #602 reopens #632 reopens #633 reopens #643 reopens #666 reopens #670 reopens #672 reopens #677 reopens #683 reopens #697 reopens #726 reopens #737 reopens #770 reopens #779 reopens #804 reopens #817 reopens #831 reopens #833 reopens #834 reopens #908 reopens #966 reopens #1023 reopens #1029 reopens #1032 reopens #1050 reopens #1052 reopens #1069 reopens #1073 reopens #1087 reopens #1091 reopens #1094 reopens #1110 reopens #1115 reopens #1116 reopens #1118 Reviewed-on: https://gitea.com/gitea/tea/pulls/1146 Reviewed-by: TheFox0x7 <95654+thefox0x7@noreply.gitea.com>
This commit is contained in:
1 parent
33bb12729e
commit
c5f674111a
604 files changed
+33711
-35545
No files matched your search
+198
@@ -0,0 +1,198 @@
|
||||
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
gitea "gitea.dev/sdk"
|
||||
|
||||
"gitea.dev/tea/cmd/flags"
|
||||
"gitea.dev/tea/cmd/pulls"
|
||||
"gitea.dev/tea/modules/context"
|
||||
"gitea.dev/tea/modules/interact"
|
||||
"gitea.dev/tea/modules/print"
|
||||
"gitea.dev/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
type pullLabelData = detailLabelData
|
||||
|
||||
type pullReviewData = detailReviewData
|
||||
|
||||
type pullCommentData = detailCommentData
|
||||
|
||||
type pullData struct {
|
||||
ID int64 `json:"id"`
|
||||
Index int64 `json:"index"`
|
||||
Title string `json:"title"`
|
||||
State gitea.StateType `json:"state"`
|
||||
Created *time.Time `json:"created"`
|
||||
Updated *time.Time `json:"updated"`
|
||||
Labels []pullLabelData `json:"labels"`
|
||||
User string `json:"user"`
|
||||
Body string `json:"body"`
|
||||
Assignees []string `json:"assignees"`
|
||||
URL string `json:"url"`
|
||||
Base string `json:"base"`
|
||||
Head string `json:"head"`
|
||||
HeadSha string `json:"headSha"`
|
||||
DiffURL string `json:"diffUrl"`
|
||||
Mergeable bool `json:"mergeable"`
|
||||
HasMerged bool `json:"hasMerged"`
|
||||
MergedAt *time.Time `json:"mergedAt"`
|
||||
MergedBy string `json:"mergedBy,omitempty"`
|
||||
ClosedAt *time.Time `json:"closedAt"`
|
||||
Reviews []pullReviewData `json:"reviews"`
|
||||
Comments []pullCommentData `json:"comments"`
|
||||
}
|
||||
|
||||
// CmdPulls is the main command to operate on PRs
|
||||
var CmdPulls = cli.Command{
|
||||
Name: "pulls",
|
||||
Aliases: []string{"pull", "pr"},
|
||||
Category: catEntities,
|
||||
Usage: "Manage and checkout pull requests",
|
||||
Description: `Lists PRs when called without argument. If PR index is provided, will show it in detail.`,
|
||||
ArgsUsage: "[<pull index>]",
|
||||
Action: runPulls,
|
||||
Flags: append([]cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "comments",
|
||||
Usage: "Whether to display comments (will prompt if not provided & run interactively)",
|
||||
},
|
||||
}, pulls.CmdPullsList.Flags...),
|
||||
Commands: []*cli.Command{
|
||||
&pulls.CmdPullsList,
|
||||
&pulls.CmdPullsCheckout,
|
||||
&pulls.CmdPullsClean,
|
||||
&pulls.CmdPullsCreate,
|
||||
&pulls.CmdPullsClose,
|
||||
&pulls.CmdPullsReopen,
|
||||
&pulls.CmdPullsEdit,
|
||||
&pulls.CmdPullsReview,
|
||||
&pulls.CmdPullsApprove,
|
||||
&pulls.CmdPullsReject,
|
||||
&pulls.CmdPullsMerge,
|
||||
&pulls.CmdPullsReply,
|
||||
&pulls.CmdPullsReviewComments,
|
||||
&pulls.CmdPullsResolve,
|
||||
&pulls.CmdPullsUnresolve,
|
||||
},
|
||||
}
|
||||
|
||||
func runPulls(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
if cmd.Args().Len() == 1 {
|
||||
return runPullDetail(ctx, cmd, cmd.Args().First())
|
||||
}
|
||||
return pulls.RunPullsList(ctx, cmd)
|
||||
}
|
||||
|
||||
func runPullDetail(requestCtx stdctx.Context, cmd *cli.Command, index string) error {
|
||||
ctx, err := context.InitCommand(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
||||
return err
|
||||
}
|
||||
idx, err := utils.ArgToIndex(index)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client := ctx.Login.Client()
|
||||
pr, _, err := client.PullRequests.GetPullRequest(requestCtx, ctx.Owner, ctx.Repo, idx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var reviews []*gitea.PullReview
|
||||
for page := 1; ; {
|
||||
page_reviews, resp, err := client.PullRequests.ListPullReviews(requestCtx, ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{
|
||||
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("error while loading reviews: %v\n", err)
|
||||
break
|
||||
}
|
||||
reviews = append(reviews, page_reviews...)
|
||||
if resp == nil || resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
page = resp.NextPage
|
||||
}
|
||||
|
||||
if ctx.IsSet("output") {
|
||||
switch ctx.String("output") {
|
||||
case "json":
|
||||
return runPullDetailAsJSON(requestCtx, ctx, pr, reviews)
|
||||
}
|
||||
}
|
||||
|
||||
ci, _, err := client.Repositories.GetCombinedStatus(requestCtx, ctx.Owner, ctx.Repo, pr.Head.Sha)
|
||||
if err != nil {
|
||||
fmt.Printf("error while loading CI: %v\n", err)
|
||||
}
|
||||
|
||||
print.PullDetails(pr, reviews, ci)
|
||||
|
||||
if pr.Comments > 0 {
|
||||
err = interact.ShowCommentsMaybeInteractive(requestCtx, ctx, idx, pr.Comments)
|
||||
if err != nil {
|
||||
fmt.Printf("error loading comments: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func runPullDetailAsJSON(requestCtx stdctx.Context, ctx *context.TeaContext, pr *gitea.PullRequest, reviews []*gitea.PullReview) error {
|
||||
c := ctx.Login.Client()
|
||||
opts := gitea.ListIssueCommentOptions{ListOptions: flags.GetListOptions(ctx.Command)}
|
||||
|
||||
mergedBy := ""
|
||||
if pr.MergedBy != nil {
|
||||
mergedBy = pr.MergedBy.UserName
|
||||
}
|
||||
|
||||
pullSlice := pullData{
|
||||
ID: pr.ID,
|
||||
Index: pr.Index,
|
||||
Title: pr.Title,
|
||||
State: pr.State,
|
||||
Created: pr.Created,
|
||||
Updated: pr.Updated,
|
||||
User: username(pr.Poster),
|
||||
Body: pr.Body,
|
||||
Labels: buildDetailLabels(pr.Labels),
|
||||
Assignees: buildDetailAssignees(pr.Assignees),
|
||||
URL: pr.HTMLURL,
|
||||
Base: pr.Base.Ref,
|
||||
Head: pr.Head.Ref,
|
||||
HeadSha: pr.Head.Sha,
|
||||
DiffURL: pr.DiffURL,
|
||||
Mergeable: pr.Mergeable,
|
||||
HasMerged: pr.HasMerged,
|
||||
MergedAt: pr.Merged,
|
||||
MergedBy: mergedBy,
|
||||
ClosedAt: pr.Closed,
|
||||
Reviews: buildDetailReviews(reviews),
|
||||
Comments: make([]pullCommentData, 0),
|
||||
}
|
||||
|
||||
if ctx.Bool("comments") {
|
||||
comments, _, err := c.Issues.ListIssueComments(requestCtx, ctx.Owner, ctx.Repo, pr.Index, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pullSlice.Comments = buildDetailComments(comments)
|
||||
}
|
||||
|
||||
return writeIndentedJSON(ctx.Writer, pullSlice)
|
||||
}
|
||||
Reference in new issue
Block a user