Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions pkg/cmd/project/item-add/item_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ func addItemArgs(config addItemConfig) (*addProjectItemMutation, map[string]inte
}

func printResults(config addItemConfig, item queries.ProjectItem) error {
if !config.io.IsStdoutTTY() {
return nil
if config.io.IsStdoutTTY() {
_, err := fmt.Fprintln(config.io.Out, "Added item")
return err
}

_, err := fmt.Fprintf(config.io.Out, "Added item\n")
_, err := fmt.Fprintln(config.io.Out, item.Id)
Comment thread
zwick marked this conversation as resolved.
return err
}
32 changes: 32 additions & 0 deletions pkg/cmd/project/item-add/item_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/google/shlex"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/h2non/gock.v1"
)

Expand Down Expand Up @@ -539,3 +540,34 @@ func TestRunAddItem_JSON(t *testing.T) {
`{"id":"item ID","title":"a title","body":"","type":"Issue"}`,
stdout.String())
}

func TestPrintResults(t *testing.T) {
Comment thread
zwick marked this conversation as resolved.
Outdated
tests := []struct {
name string
stdoutTTY bool
want string
}{
{
name: "tty",
stdoutTTY: true,
want: "Added item\n",
},
{
name: "non-tty",
want: "item ID\n",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ios, _, stdout, _ := iostreams.Test()
ios.SetStdoutTTY(tt.stdoutTTY)
config := addItemConfig{io: ios}

err := printResults(config, queries.ProjectItem{Id: "item ID"})

require.NoError(t, err)
assert.Equal(t, tt.want, stdout.String())
})
}
}