Skip to content

Commit 7202104

Browse files
authored
fix: csv format priority (#882)
1 parent d796db2 commit 7202104

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

internal/view/issues.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ type IssueList struct {
3939

4040
// Render renders the view.
4141
func (l *IssueList) Render() error {
42+
// Prioritize CSV format when explicitly requested
43+
if l.Display.CSV {
44+
w := os.Stdout
45+
return l.renderCSV(w)
46+
}
47+
4248
if l.Display.Plain || tui.IsDumbTerminal() || tui.IsNotTTY() {
4349
// custom delimiter is used only in plain mode, otherwise \t is used
4450
delimeter := "\t"
@@ -49,11 +55,6 @@ func (l *IssueList) Render() error {
4955
return l.renderPlain(w, delimeter)
5056
}
5157

52-
if l.Display.CSV {
53-
w := os.Stdout
54-
return l.renderCSV(w)
55-
}
56-
5758
renderer, err := MDRenderer()
5859
if err != nil {
5960
return err

internal/view/issues_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,49 @@ TEST-2 Story Open 2020-12-13 14:05:20
148148
assert.Equal(t, expected, b.String())
149149
}
150150

151+
func TestIssueRenderInCSVFormat(t *testing.T) {
152+
var b bytes.Buffer
153+
154+
issue := IssueList{
155+
Project: "TEST",
156+
Server: "https://test.local",
157+
Data: getIssues(),
158+
Display: DisplayFormat{
159+
CSV: true,
160+
NoHeaders: false,
161+
NoTruncate: true,
162+
},
163+
}
164+
assert.NoError(t, issue.renderCSV(&b))
165+
166+
expected := `TYPE,KEY,SUMMARY,STATUS,ASSIGNEE,REPORTER,PRIORITY,RESOLUTION,CREATED,UPDATED,LABELS
167+
Bug,TEST-1,This is a test,Done,Person A,Person Z,High,Fixed,2020-12-13 14:05:20,2020-12-13 14:07:20,krakatit
168+
Story,TEST-2,This is another test,Open,,Person A,Normal,,2020-12-13 14:05:20,2020-12-13 14:07:20,"pat,mat"
169+
`
170+
assert.Equal(t, expected, b.String())
171+
}
172+
173+
func TestIssueRenderInCSVFormatWithoutHeaders(t *testing.T) {
174+
var b bytes.Buffer
175+
176+
issue := IssueList{
177+
Project: "TEST",
178+
Server: "https://test.local",
179+
Data: getIssues(),
180+
Display: DisplayFormat{
181+
CSV: true,
182+
NoHeaders: true,
183+
NoTruncate: true,
184+
},
185+
}
186+
assert.NoError(t, issue.renderCSV(&b))
187+
188+
expected := `Bug,TEST-1,This is a test,Done,Person A,Person Z,High,Fixed,2020-12-13 14:05:20,2020-12-13 14:07:20,krakatit
189+
Story,TEST-2,This is another test,Open,,Person A,Normal,,2020-12-13 14:05:20,2020-12-13 14:07:20,"pat,mat"
190+
`
191+
assert.Equal(t, expected, b.String())
192+
}
193+
151194
func getIssues() []*jira.Issue {
152195
return []*jira.Issue{
153196
{

0 commit comments

Comments
 (0)