Skip to content

Commit 54c3066

Browse files
committed
feat: new option description issue view plain mode
1 parent adab79f commit 54c3066

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

internal/cmd/issue/view/view.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ $ jira issue view ISSUE-1 --comments 5
2323
# Get the raw JSON data
2424
$ jira issue view ISSUE-1 --raw`
2525

26-
flagRaw = "raw"
27-
flagDebug = "debug"
28-
flagComments = "comments"
29-
flagPlain = "plain"
26+
flagRaw = "raw"
27+
flagDebug = "debug"
28+
flagComments = "comments"
29+
flagPlain = "plain"
30+
flagDescription = "description"
3031

3132
configProject = "project.key"
3233
configServer = "server"
@@ -51,6 +52,7 @@ func NewCmdView() *cobra.Command {
5152

5253
cmd.Flags().Uint(flagComments, 1, "Show N comments")
5354
cmd.Flags().Bool(flagPlain, false, "Display output in plain mode")
55+
cmd.Flags().Bool(flagDescription, false, "Displays only the issue description. Works only with --plain")
5456
cmd.Flags().Bool(flagRaw, false, "Print raw Jira API response")
5557

5658
return &cmd
@@ -111,11 +113,14 @@ func viewPretty(cmd *cobra.Command, args []string) {
111113
plain, err := cmd.Flags().GetBool(flagPlain)
112114
cmdutil.ExitIfError(err)
113115

116+
description, err := cmd.Flags().GetBool(flagDescription)
117+
cmdutil.ExitIfError(err)
118+
114119
v := tuiView.Issue{
115120
Server: viper.GetString(configServer),
116121
Data: iss,
117122
Display: tuiView.DisplayFormat{Plain: plain},
118-
Options: tuiView.IssueOption{NumComments: comments},
123+
Options: tuiView.IssueOption{NumComments: comments, Description: description},
119124
}
120125
cmdutil.ExitIfError(v.Render())
121126
}

internal/view/issue.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type issueComment struct {
4343
// IssueOption is filtering options for an issue.
4444
type IssueOption struct {
4545
NumComments uint
46+
Description bool
4647
}
4748

4849
// Issue is a list view for issues.
@@ -91,6 +92,11 @@ func (i Issue) RenderedOut(renderer *glamour.TermRenderer) (string, error) {
9192
func (i Issue) String() string {
9293
var s strings.Builder
9394

95+
if i.Options.Description {
96+
s.WriteString(i.description())
97+
return s.String()
98+
}
99+
94100
s.WriteString(i.header())
95101

96102
desc := i.description()

internal/view/issue_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,51 @@ func TestIssueDetailsRenderInPlainView(t *testing.T) {
8787
assert.Equal(t, tui.TextData(expected), tui.TextData(actual))
8888
}
8989

90+
func TestIssueDescriptionRenderInPlainView(t *testing.T) {
91+
t.Parallel()
92+
93+
var b bytes.Buffer
94+
95+
data := &jira.Issue{
96+
Key: "TEST-VIEW-DESCRIPTION",
97+
Fields: jira.IssueFields{
98+
Summary: "Test view description",
99+
Resolution: struct {
100+
Name string `json:"name"`
101+
}{Name: "Fixed"},
102+
Description: &adf.ADF{
103+
Version: 1,
104+
DocType: "doc",
105+
Content: []*adf.Node{
106+
{
107+
NodeType: "paragraph",
108+
Content: []*adf.Node{
109+
{NodeType: "text", NodeValue: adf.NodeValue{Text: "Test view description"}},
110+
},
111+
},
112+
},
113+
},
114+
IssueType: jira.IssueType{Name: "Bug"},
115+
Created: "2020-12-13T14:05:20.974+0100",
116+
Updated: "2020-12-13T14:07:20.974+0100",
117+
},
118+
}
119+
120+
issue := Issue{
121+
Server: "https://test.local",
122+
Data: data,
123+
Display: DisplayFormat{Plain: true},
124+
Options: IssueOption{Description: true},
125+
}
126+
127+
expected := issue.description()
128+
129+
actual := issue.String()
130+
131+
assert.NoError(t, issue.renderPlain(&b))
132+
assert.Equal(t, tui.TextData(expected), tui.TextData(actual))
133+
}
134+
90135
func TestIssueDetailsWithV2Description(t *testing.T) {
91136
t.Parallel()
92137

0 commit comments

Comments
 (0)