Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/attachments/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
"github.com/spf13/pflag"
)

const flagName = "attach"
const (
flagName = "attach"
maxAttachments = 50
)

// errEmptyPath is reported for a --attach that named no file, whether the flag
// held nothing else or the empty value sat beside a real one.
Expand Down Expand Up @@ -42,6 +45,9 @@ func (f *Flag) UserAssets() ([]UserAsset, error) {
if !f.Changed() {
return nil, nil
}
if len(f.values) > maxAttachments {
return nil, fmt.Errorf("`--attach` accepts at most %d values per command", maxAttachments)
}
return userAssetsFromArgs(f.values)
}

Expand Down
15 changes: 15 additions & 0 deletions internal/attachments/flags_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package attachments

import (
"fmt"
"io/fs"
"os"
"strings"
"testing"

"github.com/google/shlex"
Expand Down Expand Up @@ -136,6 +138,11 @@ func TestFlagUserAssets(t *testing.T) {
input: "--attach ./b.png --attach ./a.png",
wantPaths: []string{"./b.png", "./a.png"},
},
{
name: "too many attachments are rejected before filesystem validation",
input: strings.Repeat("--attach ./missing.txt ", maxAttachments+1),
wantErr: "`--attach` accepts at most 50 values per command",
},
{
name: "a file that does not exist",
input: "--attach ./gone.png",
Expand Down Expand Up @@ -262,4 +269,12 @@ func TestFlagUserAssets(t *testing.T) {
}
})
}

t.Run("maximum number of attachments", func(t *testing.T) {
names := make([]string, maxAttachments)
for i := range names {
names[i] = fmt.Sprintf("attachment-%d.png", i)
}
assert.Len(t, NewTestAssets(t, names...), maxAttachments)
})
}
1 change: 1 addition & 0 deletions pkg/cmd/issue/comment/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func NewCmdComment(f *cmdutil.Factory, runF func(*prShared.CommentableOptions) e
attached file, such as %[1]s![alt](./login.png)%[1]s, that reference is rewritten to point
at the uploaded asset. Any attached file the body does not reference is appended
to the end of the comment.
You can attach up to 50 files per command.

Alt text for an image follows the path after %[1]s#%[1]s, as in
%[1]s--attach './login.png#The login error state'%[1]s. Without it the filename is used.
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/issue/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
Use %[1]s--attach%[1]s to upload an image or video. The attachment is appended to the
body. If the body references an attached file, such as %[1]s![alt](./login.png)%[1]s, that
reference is rewritten to point at the uploaded asset instead.
You can attach up to 50 files per command.

Alt text for an image follows the path after %[1]s#%[1]s, as in
%[1]s--attach './login.png#The login error state'%[1]s. Without it the filename is used.
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/issue/edit/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
flag the issue keeps the body it already has and the attachment is appended to it.
If the body references an attached file, such as %[1]s![alt](./login.png)%[1]s, that
reference is rewritten to point at the uploaded asset instead.
You can attach up to 50 files per command.

Alt text for an image follows the path after %[1]s#%[1]s, as in
%[1]s--attach './login.png#The login error state'%[1]s. Without it the filename is used.
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/pr/comment/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewCmdComment(f *cmdutil.Factory, runF func(*shared.CommentableOptions) err
attached file, such as %[1]s![alt](./login.png)%[1]s, that reference is rewritten to point
at the uploaded asset. Any attached file the body does not reference is appended
to the end of the comment.
You can attach up to 50 files per command.

Alt text for an image follows the path after %[1]s#%[1]s, as in
%[1]s--attach './login.png#The login error state'%[1]s. Without it the filename is used.
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/pr/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
Use %[1]s--attach%[1]s to upload an image or video. The attachment is appended to the
body. If the body references an attached file, such as %[1]s![alt](./login.png)%[1]s, that
reference is rewritten to point at the uploaded asset instead.
You can attach up to 50 files per command.

Alt text for an image follows the path after %[1]s#%[1]s, as in
%[1]s--attach './login.png#The login error state'%[1]s. Without it the filename is used.
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/pr/edit/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
request keeps the body it already has and the attachment is appended to it. If the
body references an attached file, such as %[1]s![alt](./login.png)%[1]s, that reference
is rewritten to point at the uploaded asset instead.
You can attach up to 50 files per command.

Alt text for an image follows the path after %[1]s#%[1]s, as in
%[1]s--attach './login.png#The login error state'%[1]s. Without it the filename is used.
Expand Down
2 changes: 2 additions & 0 deletions skills/gh/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ blocked-by/blocking relationships.

- Repeat `--attach` to upload multiple files:
`gh issue comment 12 --attach ./before.png --attach ./after.png`.
- Each command invocation accepts at most 50 `--attach` values total across
images and videos.
- Supported files are `png`, `jpg`, `jpeg`, `gif`, `webp`, `svg`, `mp4`,
`mov`, and `webm`.
- For an image, append alt text to the path after `#`. Quote the value so the
Expand Down
Loading