Try to avoid setting an empty github issue title (#20)
Github complains if the title is empty, so work a bit harder on making sure that we have a valid title even if the first line of the text is empty.
This commit is contained in:
parent
0452567cd7
commit
c7d9018647
2 changed files with 69 additions and 5 deletions
|
@ -451,15 +451,16 @@ func (s *submitServer) saveReport(ctx context.Context, p parsedPayload, reportDi
|
|||
}
|
||||
|
||||
func buildGithubIssueRequest(p parsedPayload, listingURL string) github.IssueRequest {
|
||||
// set the title to the first (non-empty) line of the user's report, if any
|
||||
var title string
|
||||
if p.UserText == "" {
|
||||
trimmedUserText := strings.TrimSpace(p.UserText)
|
||||
if trimmedUserText == "" {
|
||||
title = "Untitled report"
|
||||
} else {
|
||||
// set the title to the first line of the user's report
|
||||
if i := strings.IndexAny(p.UserText, "\r\n"); i < 0 {
|
||||
title = p.UserText
|
||||
if i := strings.IndexAny(trimmedUserText, "\r\n"); i < 0 {
|
||||
title = trimmedUserText
|
||||
} else {
|
||||
title = p.UserText[0:i]
|
||||
title = trimmedUserText[0:i]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -361,3 +361,66 @@ func mkTempDir(t *testing.T) string {
|
|||
}
|
||||
return td
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* buildGithubIssueRequest tests
|
||||
*/
|
||||
|
||||
func TestBuildGithubIssueLeadingNewline(t *testing.T) {
|
||||
body := `------WebKitFormBoundarySsdgl8Nq9voFyhdO
|
||||
Content-Disposition: form-data; name="text"
|
||||
|
||||
|
||||
test words.
|
||||
------WebKitFormBoundarySsdgl8Nq9voFyhdO
|
||||
Content-Disposition: form-data; name="app"
|
||||
|
||||
riot-web
|
||||
------WebKitFormBoundarySsdgl8Nq9voFyhdO--
|
||||
`
|
||||
p, _ := testParsePayload(t, body,
|
||||
"multipart/form-data; boundary=----WebKitFormBoundarySsdgl8Nq9voFyhdO",
|
||||
"",
|
||||
)
|
||||
|
||||
if p == nil {
|
||||
t.Fatal("parseRequest returned nil")
|
||||
}
|
||||
|
||||
issueReq := buildGithubIssueRequest(*p, "http://test/listing/foo")
|
||||
|
||||
if *issueReq.Title != "test words." {
|
||||
t.Errorf("Title: got %s, want %s", *issueReq.Title, "test words.")
|
||||
}
|
||||
expectedBody := "User message:\n```\n\ntest words.\n```"
|
||||
if !strings.HasPrefix(*issueReq.Body, expectedBody) {
|
||||
t.Errorf("Body: got %s, want %s", *issueReq.Body, expectedBody)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildGithubIssueEmptyBody(t *testing.T) {
|
||||
body := `------WebKitFormBoundarySsdgl8Nq9voFyhdO
|
||||
Content-Disposition: form-data; name="text"
|
||||
|
||||
------WebKitFormBoundarySsdgl8Nq9voFyhdO--
|
||||
`
|
||||
p, _ := testParsePayload(t, body,
|
||||
"multipart/form-data; boundary=----WebKitFormBoundarySsdgl8Nq9voFyhdO",
|
||||
"",
|
||||
)
|
||||
|
||||
if p == nil {
|
||||
t.Fatal("parseRequest returned nil")
|
||||
}
|
||||
|
||||
issueReq := buildGithubIssueRequest(*p, "http://test/listing/foo")
|
||||
|
||||
if *issueReq.Title != "Untitled report" {
|
||||
t.Errorf("Title: got %s, want %s", *issueReq.Title, "Untitled report")
|
||||
}
|
||||
expectedBody := "User message:\n```\n\n```"
|
||||
if !strings.HasPrefix(*issueReq.Body, expectedBody) {
|
||||
t.Errorf("Body: got %s, want %s", *issueReq.Body, expectedBody)
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue