Read issue/PR description from stdin or a file (#1096)

Closes #1095.

`tea issues create` and `tea pulls create` now resolve the description in the same way as comments: when stdin is piped and neither `--description` nor `--description-file` is given, the body is read from stdin. Both create and edit commands also accept:

```text
--description-file <path>   # '-' reads stdin
```

This avoids the PowerShell 5.1 argument mangling and ANSI code page issues described in #1095.

## Changes

- Add `--description-file` to `issues create`, `issues edit`, `pulls create`, and `pulls edit`.
- Create commands fall back to piped stdin when no description flag is set.
- Add unit tests for the new body resolution.

---------

Co-authored-by: bircni <bircni@icloud.com>
Reviewed-on: https://gitea.com/gitea/tea/pulls/1096
Reviewed-by: bircni <bircni@icloud.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
Lunny Xiao
2026-08-23 12:46:22 +00:00
committed by bircni
parent dfe89dfb6b
commit bfda25be63
4 changed files with 270 additions and 5 deletions
+28 -5
View File
@@ -100,6 +100,10 @@ var issuePRFlags = append([]cli.Flag{
Name: "description",
Aliases: []string{"d"},
},
&cli.StringFlag{
Name: "description-file",
Usage: "Read description from file ('-' for stdin)",
},
&cli.StringFlag{
Name: "referenced-version",
Aliases: []string{"v"},
@@ -133,12 +137,22 @@ var IssuePRCreateFlags = append([]cli.Flag{
// GetIssuePRCreateFlags parses all IssuePREditFlags
func GetIssuePRCreateFlags(requestCtx stdctx.Context, ctx *context.TeaContext) (*gitea.CreateIssueOption, error) {
body, err := resolveCreateBody(
ctx.String("description"),
ctx.String("description-file"),
ctx.IsSet("description-file"),
stdinPiped(),
ctx.Reader,
)
if err != nil {
return nil, err
}
opts := gitea.CreateIssueOption{
Title: ctx.String("title"),
Body: ctx.String("description"),
Body: body,
Assignees: strings.Split(ctx.String("assignees"), ","),
}
var err error
date := ctx.String("deadline")
if date != "" {
@@ -208,9 +222,18 @@ func GetIssuePREditFlags(ctx *context.TeaContext) (*task.EditIssueOption, error)
val := ctx.String("title")
opts.Title = &val
}
if ctx.IsSet("description") {
val := ctx.String("description")
opts.Body = &val
body, err := resolveEditBody(
ctx.String("description"),
ctx.IsSet("description"),
ctx.String("description-file"),
ctx.IsSet("description-file"),
ctx.Reader,
)
if err != nil {
return nil, err
}
if body != nil {
opts.Body = body
}
if ctx.IsSet("referenced-version") {
val := ctx.String("referenced-version")