gitea.tea/modules/task/issue_create.go
Danilo Sousa 83fb7c0d26
Make issues create honor --output json
Same hole and same shape as the merged pulls fix (#1111):
--output parses on issues create through the urfave/cli v3
ancestor-flag cascade but was never read, so the action always
printed glamour markdown plus a second bare URL line.

task.CreateIssue now returns the created issue and the cmd layer
switches on --output, emitting compact lean JSON (index, title,
url, state), matching the post-review shape of
writeCreatedPullAsJSON. Without the flag the output stays
byte-identical: the same print.IssueDetails and HTMLURL println
calls just moved to the callers.

Signed-off-by: Danilo Sousa <code@danilosousa.net>
2026-09-09 20:57:31 -03:00

29 lines
720 B
Go

// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package task
import (
stdctx "context"
"fmt"
gitea "gitea.dev/sdk"
"gitea.dev/tea/modules/config"
)
// CreateIssue creates an issue in the given repo and returns the created issue
func CreateIssue(requestCtx stdctx.Context, rlogin *config.Login, repoOwner, repoName string, opts gitea.CreateIssueOption) (*gitea.Issue, error) {
// title is required
if len(opts.Title) == 0 {
return nil, fmt.Errorf("title is required")
}
issue, _, err := rlogin.Client().Issues.CreateIssue(requestCtx, repoOwner, repoName, opts)
if err != nil {
return nil, fmt.Errorf("could not create issue: %s", err)
}
return issue, nil
}