mirror of
https://gitea.com/gitea/tea.git
synced 2026-09-10 07:26:33 -04:00
fix(issues): resolve project before creating issue
Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
bc164f28f6
commit
2c500cc0f6
|
|
@ -47,6 +47,14 @@ func runIssuesCreate(requestCtx stdctx.Context, cmd *cli.Command) error {
|
|||
return err
|
||||
}
|
||||
|
||||
var projectTarget *task.IssueProject
|
||||
if project := ctx.String("project"); project != "" {
|
||||
projectTarget, err = task.ResolveIssueProject(requestCtx, ctx.Login.Client(), ctx.Owner, ctx.Repo, project)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
issue, err := task.CreateIssue(requestCtx, ctx.Login,
|
||||
ctx.Owner,
|
||||
ctx.Repo,
|
||||
|
|
@ -56,8 +64,8 @@ func runIssuesCreate(requestCtx stdctx.Context, cmd *cli.Command) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if project := ctx.String("project"); project != "" {
|
||||
if err := task.AddIssueToProject(requestCtx, ctx.Login.Client(), ctx.Owner, ctx.Repo, issue.ID, project); err != nil {
|
||||
if projectTarget != nil {
|
||||
if err := projectTarget.AddIssue(requestCtx, ctx.Login.Client(), issue.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,25 +13,50 @@ import (
|
|||
gitea "gitea.dev/sdk"
|
||||
)
|
||||
|
||||
// AddIssueToProject adds an issue to the default column of a project.
|
||||
// The project argument may be either a project ID or a project title.
|
||||
func AddIssueToProject(requestCtx stdctx.Context, client *gitea.Client, owner, repo string, issueID int64, project string) error {
|
||||
// IssueProject is a resolved project column target for an issue.
|
||||
type IssueProject struct {
|
||||
scope gitea.ProjectScope
|
||||
projectID int64
|
||||
columnID int64
|
||||
}
|
||||
|
||||
// ResolveIssueProject resolves a project ID or title to a project and its default column.
|
||||
func ResolveIssueProject(requestCtx stdctx.Context, client *gitea.Client, owner, repo, project string) (*IssueProject, error) {
|
||||
scope, projectID, err := resolveProject(requestCtx, client, owner, repo, project)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
column, err := defaultProjectColumn(requestCtx, client, scope, projectID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not find default column for project '%s': %w", project, err)
|
||||
return nil, fmt.Errorf("could not find default column for project '%s': %w", project, err)
|
||||
}
|
||||
|
||||
if _, err := client.Projects.AddIssueToProjectColumn(requestCtx, scope, projectID, column.ID, issueID); err != nil {
|
||||
return fmt.Errorf("could not add issue to project '%s': %w", project, err)
|
||||
return &IssueProject{
|
||||
scope: scope,
|
||||
projectID: projectID,
|
||||
columnID: column.ID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// AddIssue adds an issue to the resolved project column.
|
||||
func (p *IssueProject) AddIssue(requestCtx stdctx.Context, client *gitea.Client, issueID int64) error {
|
||||
if _, err := client.Projects.AddIssueToProjectColumn(requestCtx, p.scope, p.projectID, p.columnID, issueID); err != nil {
|
||||
return fmt.Errorf("could not add issue to project: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddIssueToProject adds an issue to the default column of a project.
|
||||
// The project argument may be either a project ID or a project title.
|
||||
func AddIssueToProject(requestCtx stdctx.Context, client *gitea.Client, owner, repo string, issueID int64, project string) error {
|
||||
projectTarget, err := ResolveIssueProject(requestCtx, client, owner, repo, project)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return projectTarget.AddIssue(requestCtx, client, issueID)
|
||||
}
|
||||
|
||||
func defaultProjectColumn(requestCtx stdctx.Context, client *gitea.Client, scope gitea.ProjectScope, projectID int64) (*gitea.ProjectColumn, error) {
|
||||
var fallback *gitea.ProjectColumn
|
||||
page := 1
|
||||
|
|
|
|||
Loading…
Reference in a new issue