Skip to content

Instantly share code, notes, and snippets.

@StephenOTT
Last active January 1, 2016 02:19
Show Gist options
  • Save StephenOTT/8078793 to your computer and use it in GitHub Desktop.
Save StephenOTT/8078793 to your computer and use it in GitHub Desktop.
Get Tasks from a GitHub Issue Body or Comment using RegEx to parse issue body or issue comment for a task.
def get_comment_tasks (commentBody, taskStatus = :incomplete)
tasks = []
startStringOpen = /\-\s\[\s\]\s/
startStringClosed = /\-\s\[x\]\s/
endString = /[\r\n]|\z/
if taskStatus == :incomplete
tasksInBody = commentBody.scan(/#{startStringOpen}(.*?)#{endString}/)
tasksInBody.each do |x|
tasks << x[0]
end
elsif taskStatus == :complete
tasksInBody = commentBody.scan(/#{startStringClosed}(.*?)#{endString}/)
tasksInBody.each do |x|
tasks << x[0]
end
end
return tasks
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment