Skip to content

Commit 3f26b56

Browse files
committed
feat: new option description issue view plain mode
1 parent ca756a7 commit 3f26b56

File tree

3 files changed

+89
-5
lines changed

3 files changed

+89
-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
@@ -105,11 +107,14 @@ func viewPretty(cmd *cobra.Command, args []string) {
105107
plain, err := cmd.Flags().GetBool(flagPlain)
106108
cmdutil.ExitIfError(err)
107109

110+
description, err := cmd.Flags().GetBool(flagDescription)
111+
cmdutil.ExitIfError(err)
112+
108113
v := tuiView.Issue{
109114
Server: viper.GetString(configServer),
110115
Data: iss,
111116
Display: tuiView.DisplayFormat{Plain: plain},
112-
Options: tuiView.IssueOption{NumComments: comments},
117+
Options: tuiView.IssueOption{NumComments: comments, Description: description},
113118
}
114119
cmdutil.ExitIfError(v.Render())
115120
}

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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,79 @@ 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-1",
97+
Fields: jira.IssueFields{
98+
Summary: "This is a test",
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 description"}},
110+
},
111+
},
112+
},
113+
},
114+
IssueType: jira.IssueType{Name: "Bug"},
115+
Assignee: struct {
116+
Name string `json:"displayName"`
117+
}{Name: "Person A"},
118+
Priority: struct {
119+
Name string `json:"name"`
120+
}{Name: "High"},
121+
Reporter: struct {
122+
Name string `json:"displayName"`
123+
}{Name: "Person Z"},
124+
Status: struct {
125+
Name string `json:"name"`
126+
}{Name: "Done"},
127+
Components: []struct {
128+
Name string `json:"name"`
129+
}{{Name: "BE"}, {Name: "FE"}},
130+
Comment: struct {
131+
Comments []struct {
132+
ID string `json:"id"`
133+
Author jira.User `json:"author"`
134+
Body interface{} `json:"body"`
135+
Created string `json:"created"`
136+
} `json:"comments"`
137+
Total int `json:"total"`
138+
}{Total: 0},
139+
Watches: struct {
140+
IsWatching bool `json:"isWatching"`
141+
WatchCount int `json:"watchCount"`
142+
}{IsWatching: true, WatchCount: 4},
143+
Created: "2020-12-13T14:05:20.974+0100",
144+
Updated: "2020-12-13T14:07:20.974+0100",
145+
},
146+
}
147+
148+
issue := Issue{
149+
Server: "https://test.local",
150+
Data: data,
151+
Display: DisplayFormat{Plain: true},
152+
Options: IssueOption{Description: true},
153+
}
154+
155+
expected := issue.description()
156+
157+
actual := issue.String()
158+
159+
assert.NoError(t, issue.renderPlain(&b))
160+
assert.Equal(t, tui.TextData(expected), tui.TextData(actual))
161+
}
162+
90163
func TestIssueDetailsWithV2Description(t *testing.T) {
91164
t.Parallel()
92165

0 commit comments

Comments
 (0)