Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006)

Reviewed-on: https://gitea.com/gitea/tea/pulls/1006
Reviewed-by: Zettat123 <39446+zettat123@noreply.gitea.com>
This commit is contained in:
Lunny Xiao
2026-05-26 04:51:09 +00:00
parent 579099f9d9
commit 28ba9b915b
179 changed files with 617 additions and 599 deletions
+7 -6
View File
@@ -4,10 +4,11 @@
package interact
import (
stdctx "context"
"fmt"
"os"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -20,18 +21,18 @@ import (
// ShowCommentsMaybeInteractive fetches & prints comments, depending on the --comments flag.
// If that flag is unset, and output is not piped, prompts the user first.
func ShowCommentsMaybeInteractive(ctx *context.TeaContext, idx int64, totalComments int) error {
func ShowCommentsMaybeInteractive(requestCtx stdctx.Context, ctx *context.TeaContext, idx int64, totalComments int) error {
if ctx.Bool("comments") {
opts := gitea.ListIssueCommentOptions{ListOptions: flags.GetListOptions(ctx.Command)}
c := ctx.Login.Client()
comments, _, err := c.ListIssueComments(ctx.Owner, ctx.Repo, idx, opts)
comments, _, err := c.Issues.ListIssueComments(requestCtx, ctx.Owner, ctx.Repo, idx, opts)
if err != nil {
return err
}
print.Comments(comments)
} else if print.IsInteractive() && !ctx.IsSet("comments") {
// if we're interactive, but --comments hasn't been explicitly set to false
if err := ShowCommentsPaginated(ctx, idx, totalComments); err != nil {
if err := ShowCommentsPaginated(requestCtx, ctx, idx, totalComments); err != nil {
fmt.Printf("error while loading comments: %v\n", err)
}
}
@@ -39,7 +40,7 @@ func ShowCommentsMaybeInteractive(ctx *context.TeaContext, idx int64, totalComme
}
// ShowCommentsPaginated prompts if issue/pr comments should be shown and continues to do so.
func ShowCommentsPaginated(ctx *context.TeaContext, idx int64, totalComments int) error {
func ShowCommentsPaginated(requestCtx stdctx.Context, ctx *context.TeaContext, idx int64, totalComments int) error {
c := ctx.Login.Client()
opts := gitea.ListIssueCommentOptions{ListOptions: flags.GetListOptions(ctx.Command)}
prompt := "show comments?"
@@ -59,7 +60,7 @@ func ShowCommentsPaginated(ctx *context.TeaContext, idx int64, totalComments int
} else if !loadComments {
break
} else {
if comments, _, err := c.ListIssueComments(ctx.Owner, ctx.Repo, idx, opts); err != nil {
if comments, _, err := c.Issues.ListIssueComments(requestCtx, ctx.Owner, ctx.Repo, idx, opts); err != nil {
return err
} else if len(comments) != 0 {
print.Comments(comments)
+12 -11
View File
@@ -4,9 +4,10 @@
package interact
import (
"context"
"strings"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/modules/config"
"gitea.dev/tea/modules/task"
@@ -21,7 +22,7 @@ func IsQuitting(err error) bool {
}
// CreateIssue interactively creates an issue
func CreateIssue(login *config.Login, owner, repo string) error {
func CreateIssue(ctx context.Context, login *config.Login, owner, repo string) error {
owner, repo, err := promptRepoSlug(owner, repo)
if err != nil {
return err
@@ -29,19 +30,19 @@ func CreateIssue(login *config.Login, owner, repo string) error {
printTitleAndContent("Target repo:", owner+"/"+repo)
var opts gitea.CreateIssueOption
if err := promptIssueProperties(login, owner, repo, &opts); err != nil {
if err := promptIssueProperties(ctx, login, owner, repo, &opts); err != nil {
return err
}
return task.CreateIssue(login, owner, repo, opts)
return task.CreateIssue(ctx, login, owner, repo, opts)
}
func promptIssueProperties(login *config.Login, owner, repo string, o *gitea.CreateIssueOption) error {
func promptIssueProperties(ctx context.Context, login *config.Login, owner, repo string, o *gitea.CreateIssueOption) error {
var milestoneName string
var err error
selectableChan := make(chan (issueSelectables), 1)
go fetchIssueSelectables(login, owner, repo, selectableChan)
go fetchIssueSelectables(ctx, login, owner, repo, selectableChan)
// title
if err := huh.NewInput().
@@ -140,12 +141,12 @@ type issueSelectables struct {
Err error
}
func fetchIssueSelectables(login *config.Login, owner, repo string, done chan issueSelectables) {
func fetchIssueSelectables(ctx context.Context, login *config.Login, owner, repo string, done chan issueSelectables) {
// TODO PERF make these calls concurrent
r := issueSelectables{}
c := login.Client()
r.Repo, _, r.Err = c.GetRepo(owner, repo)
r.Repo, _, r.Err = c.Repositories.GetRepo(ctx, owner, repo)
if r.Err != nil {
done <- r
return
@@ -157,7 +158,7 @@ func fetchIssueSelectables(login *config.Login, owner, repo string, done chan is
return
}
assignees, _, err := c.GetAssignees(owner, repo)
assignees, _, err := c.Repositories.GetAssignees(ctx, owner, repo)
if err != nil {
r.Err = err
done <- r
@@ -168,7 +169,7 @@ func fetchIssueSelectables(login *config.Login, owner, repo string, done chan is
r.Assignees[i] = u.UserName
}
milestones, _, err := c.ListRepoMilestones(owner, repo, gitea.ListMilestoneOption{})
milestones, _, err := c.Repositories.ListMilestones(ctx, owner, repo, gitea.ListMilestoneOption{})
if err != nil {
r.Err = err
done <- r
@@ -184,7 +185,7 @@ func fetchIssueSelectables(login *config.Login, owner, repo string, done chan is
r.LabelMap = make(map[string]int64)
r.LabelList = make([]string, 0)
for page := 1; ; {
labels, resp, err := c.ListRepoLabels(owner, repo, gitea.ListLabelsOptions{
labels, resp, err := c.Repositories.ListRepoLabels(ctx, owner, repo, gitea.ListLabelsOptions{
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
})
if err != nil {
+6 -5
View File
@@ -4,6 +4,7 @@
package interact
import (
stdctx "context"
"slices"
"strings"
@@ -16,7 +17,7 @@ import (
)
// EditIssue interactively edits an issue
func EditIssue(ctx context.TeaContext, index int64) (*task.EditIssueOption, error) {
func EditIssue(requestCtx stdctx.Context, ctx context.TeaContext, index int64) (*task.EditIssueOption, error) {
opts := task.EditIssueOption{}
var err error
@@ -27,7 +28,7 @@ func EditIssue(ctx context.TeaContext, index int64) (*task.EditIssueOption, erro
printTitleAndContent("Target repo:", ctx.Owner+"/"+ctx.Repo)
c := ctx.Login.Client()
i, _, err := c.GetIssue(ctx.Owner, ctx.Repo, index)
i, _, err := c.Issues.GetIssue(requestCtx, ctx.Owner, ctx.Repo, index)
if err != nil {
return &opts, err
}
@@ -55,20 +56,20 @@ func EditIssue(ctx context.TeaContext, index int64) (*task.EditIssueOption, erro
opts.Milestone = &i.Milestone.Title
}
if err := promptIssueEditProperties(&ctx, &opts); err != nil {
if err := promptIssueEditProperties(requestCtx, &ctx, &opts); err != nil {
return &opts, err
}
return &opts, err
}
func promptIssueEditProperties(ctx *context.TeaContext, o *task.EditIssueOption) error {
func promptIssueEditProperties(requestCtx stdctx.Context, ctx *context.TeaContext, o *task.EditIssueOption) error {
var milestoneName string
var labelsSelected []string
var err error
selectableChan := make(chan (issueSelectables), 1)
go fetchIssueSelectables(ctx.Login, ctx.Owner, ctx.Repo, selectableChan)
go fetchIssueSelectables(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, selectableChan)
// title
if err := huh.NewInput().
+5 -4
View File
@@ -4,6 +4,7 @@
package interact
import (
"context"
"errors"
"fmt"
"net/url"
@@ -11,7 +12,7 @@ import (
"strconv"
"strings"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/modules/auth"
"gitea.dev/tea/modules/config"
@@ -22,7 +23,7 @@ import (
)
// CreateLogin create an login interactive
func CreateLogin() error {
func CreateLogin(ctx context.Context) error {
var (
name, token, user, passwd, otp, scopes, sshKey, sshCertPrincipal, sshKeyFingerprint string
insecure, sshAgent, versionCheck, helper bool
@@ -104,7 +105,7 @@ func CreateLogin() error {
}
printTitleAndContent("Allow Insecure connections:", strconv.FormatBool(insecure))
return auth.OAuthLoginWithOptions(name, giteaURL, insecure)
return auth.OAuthLoginWithOptions(ctx, name, giteaURL, insecure)
default: // token
var hasToken bool
if err := huh.NewConfirm().
@@ -270,7 +271,7 @@ func CreateLogin() error {
printTitleAndContent("Check version of Gitea instance:", strconv.FormatBool(versionCheck))
}
return task.CreateLogin(name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint, insecure, sshAgent, versionCheck, helper)
return task.CreateLogin(ctx, name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint, insecure, sshAgent, versionCheck, helper)
}
var tokenScopeOpts = []string{
+4 -5
View File
@@ -4,11 +4,11 @@
package interact
import (
stdctx "context"
"fmt"
"time"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/modules/config"
"gitea.dev/tea/modules/task"
"gitea.dev/tea/modules/theme"
@@ -17,7 +17,7 @@ import (
)
// CreateMilestone interactively creates a milestone
func CreateMilestone(login *config.Login, owner, repo string) error {
func CreateMilestone(requestCtx stdctx.Context, login *config.Login, owner, repo string) error {
var title, description, deadline string
// owner, repo
@@ -60,8 +60,7 @@ func CreateMilestone(login *config.Login, owner, repo string) error {
deadlineTM = &tm
}
return task.CreateMilestone(
login,
return task.CreateMilestone(requestCtx, login,
owner,
repo,
title,
+8 -5
View File
@@ -4,8 +4,9 @@
package interact
import (
"code.gitea.io/sdk/gitea"
stdctx "context"
gitea "gitea.dev/sdk"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/task"
"gitea.dev/tea/modules/theme"
@@ -14,7 +15,7 @@ import (
)
// CreatePull interactively creates a PR
func CreatePull(ctx *context.TeaContext) (err error) {
func CreatePull(requestCtx stdctx.Context, ctx *context.TeaContext) (err error) {
var (
base, head string
allowMaintainerEdits = true
@@ -28,7 +29,7 @@ func CreatePull(ctx *context.TeaContext) (err error) {
}
// base
if base, err = task.GetDefaultPRBase(ctx.Login, ctx.Owner, ctx.Repo); err != nil {
if base, err = task.GetDefaultPRBase(requestCtx, ctx.Login, ctx.Owner, ctx.Repo); err != nil {
return err
}
@@ -86,11 +87,12 @@ func CreatePull(ctx *context.TeaContext) (err error) {
}
opts := gitea.CreateIssueOption{Title: task.GetDefaultPRTitle(head)}
if err = promptIssueProperties(ctx.Login, ctx.Owner, ctx.Repo, &opts); err != nil {
if err = promptIssueProperties(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, &opts); err != nil {
return err
}
return task.CreateAgitFlowPull(
requestCtx,
ctx,
baseRemote,
head,
@@ -128,11 +130,12 @@ func CreatePull(ctx *context.TeaContext) (err error) {
head = task.GetHeadSpec(headOwner, headBranch, ctx.Owner)
opts := gitea.CreateIssueOption{Title: task.GetDefaultPRTitle(head)}
if err = promptIssueProperties(ctx.Login, ctx.Owner, ctx.Repo, &opts); err != nil {
if err = promptIssueProperties(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, &opts); err != nil {
return err
}
return task.CreatePull(
requestCtx,
ctx,
base,
head,
+7 -6
View File
@@ -4,10 +4,11 @@
package interact
import (
stdctx "context"
"fmt"
"strings"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -18,7 +19,7 @@ import (
)
// MergePull interactively creates a PR
func MergePull(ctx *context.TeaContext) error {
func MergePull(requestCtx stdctx.Context, ctx *context.TeaContext) error {
if ctx.LocalRepo == nil {
return fmt.Errorf("pull request index is required")
}
@@ -28,12 +29,12 @@ func MergePull(ctx *context.TeaContext) error {
return err
}
idx, err := getPullIndex(ctx, branch)
idx, err := getPullIndex(requestCtx, ctx, branch)
if err != nil {
return err
}
return task.PullMerge(ctx.Login, ctx.Owner, ctx.Repo, idx, gitea.MergePullRequestOption{
return task.PullMerge(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, idx, gitea.MergePullRequestOption{
Style: gitea.MergeStyle(ctx.String("style")),
Title: ctx.String("title"),
Message: ctx.String("message"),
@@ -41,7 +42,7 @@ func MergePull(ctx *context.TeaContext) error {
}
// getPullIndex interactively determines the PR index
func getPullIndex(ctx *context.TeaContext, branch string) (int64, error) {
func getPullIndex(requestCtx stdctx.Context, ctx *context.TeaContext, branch string) (int64, error) {
c := ctx.Login.Client()
opts := gitea.ListPullRequestsOptions{
State: gitea.StateOpen,
@@ -54,7 +55,7 @@ func getPullIndex(ctx *context.TeaContext, branch string) (int64, error) {
var prs []*gitea.PullRequest
for {
var err error
prs, _, err = c.ListRepoPullRequests(ctx.Owner, ctx.Repo, opts)
prs, _, err = c.PullRequests.ListRepoPullRequests(requestCtx, ctx.Owner, ctx.Repo, opts)
if err != nil {
return 0, err
}
+7 -6
View File
@@ -4,11 +4,12 @@
package interact
import (
stdctx "context"
"fmt"
"os"
"strconv"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/modules/config"
"gitea.dev/tea/modules/context"
@@ -26,7 +27,7 @@ var reviewStates = map[string]gitea.ReviewStateType{
var reviewStateOptions = []string{"comment", "request changes", "approve"}
// ReviewPull interactively reviews a PR
func ReviewPull(ctx *context.TeaContext, idx int64) error {
func ReviewPull(requestCtx stdctx.Context, ctx *context.TeaContext, idx int64) error {
var state gitea.ReviewStateType
var comment string
var codeComments []gitea.CreatePullReviewComment
@@ -44,7 +45,7 @@ func ReviewPull(ctx *context.TeaContext, idx int64) error {
printTitleAndContent("Review / comment the diff?", strconv.FormatBool(reviewDiff))
if reviewDiff {
if codeComments, err = DoDiffReview(ctx, idx); err != nil {
if codeComments, err = DoDiffReview(requestCtx, ctx, idx); err != nil {
fmt.Printf("Error during diff review: %s\n", err)
}
fmt.Printf("Found %d code comments in your review\n", len(codeComments))
@@ -78,14 +79,14 @@ func ReviewPull(ctx *context.TeaContext, idx int64) error {
}
printTitleAndContent("Concluding comment(markdown):", comment)
return task.CreatePullReview(ctx, idx, state, comment, codeComments)
return task.CreatePullReview(requestCtx, ctx, idx, state, comment, codeComments)
}
// DoDiffReview (1) fetches & saves diff in tempfile, (2) starts $VISUAL or $EDITOR to comment on diff,
// (3) parses resulting file into code comments.
// It doesn't really make sense to use survey.Editor() here, as we'd read the file content at least twice.
func DoDiffReview(ctx *context.TeaContext, idx int64) ([]gitea.CreatePullReviewComment, error) {
tmpFile, err := task.SavePullDiff(ctx, idx)
func DoDiffReview(requestCtx stdctx.Context, ctx *context.TeaContext, idx int64) ([]gitea.CreatePullReviewComment, error) {
tmpFile, err := task.SavePullDiff(requestCtx, ctx, idx)
if err != nil {
return nil, err
}