Skip to content

Instantly share code, notes, and snippets.

@NigelThorne
Last active February 17, 2020 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NigelThorne/3f7120d538dcd18a911a6c90d42d027f to your computer and use it in GitHub Desktop.
Save NigelThorne/3f7120d538dcd18a911a6c90d42d027f to your computer and use it in GitHub Desktop.
Generate issues in Jira from a list
require 'rubygems'
require 'jira-ruby'
require 'awesome_print'
def get_jira_client()
options = {
:username => 'xxx',
:password => 'xxx',
:site => 'http://jira.xxx:80/',#'http://mydomain.atlassian.net:443/',
:context_path => '',
:auth_type => :basic,
:use_ssl => false
}
JIRA::Client.new(options)
end
# project = client.Project.find('LAACM')
# project.issues.each do |issue|
# puts "#{issue.id} - #{issue.summary}"
# end
#
# def add_task(scope, task)
# return [task] if scope == []
# prev = scope[-1]
# return scope << task if task[:indent] == prev[:indent]
# prev[:tasks] = add_task(prev[:tasks], task)
# return scope
# end
def parse_tasks_file(lines)
lines
.reject{|l| /^[^\*]/ =~ l} #ignore titles
.map{|l| l.gsub(/\n$/,"")}
.map{|l|
_, indent, title, rest = l.match(/^(\*+)\s([^-]+)(-.*)?$/).to_a
{indent:indent.length, title:title.strip, rest:rest}
}
.inject([]){ |arr, task|
new = add_task(task, arr[-1])
new ? (arr + [new]) : arr
}
end
def add_task(task, prev)
if(prev && (prev[:indent] < task[:indent]))
prev[:notes] += "\n" + task[:title]
prev[:notes] += "\n\t"+task[:rest] if task[:rest]
nil
else
{indent:task[:indent], title:task[:title], notes:(task[:rest]||"")}
end
end
@lines = File.readlines(ARGV[0])
@tasks = parse_tasks_file(@lines)
@client = get_jira_client();
types = @client.Issuetype.all
@user_story_type = types.find{|t| t.name == "User Story"}
@task_type = types.find{|t| t.name == "Task"}
@project = @client.Project.find('LAACM')
ap @project
ap @user_story_type
def story_fields(project_id, type_id, name, notes)
{"fields"=>
{
"summary"=>"xxx: "+ name,
"description"=>notes,
"project"=>{"id"=>project_id},
"labels"=>["xxx"],
#"subtasks" => [], # TODO : add subtasks (need issuelinks)
"issuetype"=>{"id"=>type_id}
}
}
end
@story_fields = @tasks.map {|task| story_fields(@project.id, @user_story_type.id, task[:title], task[:notes])}
puts "stop here incase you change jira!! :)"
exit
@story_fields.each{|story|
puts "Creating Story:"
ap story
issue = @client.Issue.build
ap issue.save(story)
puts "--------story done--------"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment