Skip to content

Commit

Permalink
jira linkifying works now
Browse files Browse the repository at this point in the history
  • Loading branch information
rickschubert committed Jun 17, 2020
1 parent 9d79e4f commit c70e2d0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
36 changes: 30 additions & 6 deletions jira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,38 @@ func splitPlainTextDescriptionIntoJiraApiObjects(plainTextDescription string) []
}
}

func linkifyContentBlock(content content) content {
func linkifyContentBlock(cont content) content {
var newParagraphContents []paragraphContent
for _, paragraph := range content.Content {
if len(linksInParagraph) > 0 {

} else {
newParagraphContents = append(newParagraphContents, paragraph)
for _, paragraph := range cont.Content {
linksInParagraph := utils.SplitTextOnLinks(paragraph.Text)
// if len(linksInParagraph) > 0 {
for _, text := range linksInParagraph {
if text.IsLink {
newParagraphContents = append(newParagraphContents, paragraphContent{
Type: "text",
Text: text.Text,
Marks: []mark{
{
Type: "link",
Attrs: Attr{
Href: text.Text,
},
},
},
})
} else {
newParagraphContents = append(newParagraphContents, paragraphContent{
Type: "text",
Text: text.Text,
})
}
}
// } else {
// }
}
return content{
Type: "paragraph",
Content: newParagraphContents,
}
}

Expand Down
6 changes: 3 additions & 3 deletions utils/SplitTextOnLinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type textChunk struct {
isLink bool
IsLink bool
Text string
}

Expand Down Expand Up @@ -54,13 +54,13 @@ func SplitTextOnLinks(text string) []textChunk {
isPlaceholder, _ := regexp.Match(placeholderMarker, []byte(chunk))
if isPlaceholder {
chunkObjects = append(chunkObjects, textChunk{
isLink: true,
IsLink: true,
Text: linksInText[amountOfLinks],
})
amountOfLinks++
} else {
chunkObjects = append(chunkObjects, textChunk{
isLink: false,
IsLink: false,
Text: chunk,
})
}
Expand Down
12 changes: 6 additions & 6 deletions utils/SplitTextOnLinks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ func TestSplitTextOnLinks(t *testing.T) {
input := "See failure on Jenkins: https://jenkins.tray.io/job/qa-api-utils-tests/6548/allure/#suites/7deabbaf120515942d030aa4a12b42ab/8caffa3c0bf480ed/ and there you https://jenkins.tray.io/job/qa-api-utied/ go https://jenkins.tray.io/"
expectedOutput := []textChunk{
{
isLink: false,
IsLink: false,
Text: "See failure on Jenkins: ",
},
{
isLink: true,
IsLink: true,
Text: "https://jenkins.tray.io/job/qa-api-utils-tests/6548/allure/#suites/7deabbaf120515942d030aa4a12b42ab/8caffa3c0bf480ed/",
},
{
isLink: false,
IsLink: false,
Text: " and there you ",
},
{
isLink: true,
IsLink: true,
Text: "https://jenkins.tray.io/job/qa-api-utied/",
},
{
isLink: false,
IsLink: false,
Text: " go ",
},
{
isLink: true,
IsLink: true,
Text: "https://jenkins.tray.io/",
},
}
Expand Down

0 comments on commit c70e2d0

Please sign in to comment.