Skip to content

Commit

Permalink
Added the parsing of the tasks
Browse files Browse the repository at this point in the history
This will parse the markdown checkboxes from the body and create the tasks on the story items.
  • Loading branch information
nhalstead committed Oct 4, 2020
1 parent 1cfdcb9 commit 66105de
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (migration *Migration) GithubCardToClubhouseStory(state clubhouse.WorkflowS
Archived: isClosed,
WorkflowStateID: &state.ID,

Tasks: parseTasks(issue.Body),
CreatedAt: &card.CreatedAt.Time,
ExternalTickets: []clubhouse.CreateExternalTicketParams{
{
Expand All @@ -159,13 +160,44 @@ func (migration *Migration) GithubCardToClubhouseStory(state clubhouse.WorkflowS
StoryType: clubhouse.StoryTypeFeature,
Archived: false,
WorkflowStateID: &state.ID,

Tasks: parseTasks(card.Note),
CreatedAt: &card.CreatedAt.Time,
}
}

return migration.clubhouseClient().StoryCreate(payload)
}

func parseTasks(body *string) []clubhouse.CreateTaskParams {
var tasks []clubhouse.CreateTaskParams

if body == nil {
return tasks
}

var re = regexp.MustCompile(`(?mi)^( |)- \[(x| |)\] (.*)$`)

for _, match := range re.FindAllStringSubmatch(*body, -1) {

if len(match) == 0 {
continue
}
isComplete := false

if strings.ToLower(match[2]) == "x" {
isComplete = true
}

tasks = append(tasks, clubhouse.CreateTaskParams{
Complete: isComplete,
Description: match[3],
})
}

return tasks
}

func MakeTitle(title string) string {
title = strings.ReplaceAll(title, "\r", "\n")
title = strings.ReplaceAll(title, "\n\n", "\n")
Expand Down

0 comments on commit 66105de

Please sign in to comment.