Last active
July 15, 2016 02:30
-
-
Save kylog/8450099 to your computer and use it in GitHub Desktop.
One-off script to create a puppet release ticket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'jira' | |
require 'pp' | |
require 'getoptlong' | |
# default values | |
username = "gepetto-bot" | |
password = ENV["GEPETTO_BOT_PASSWORD"] | |
if password.nil? | |
puts "Must specify gepetto-bot password in GEPETTO_BOT_PASSWORD" | |
exit 1 | |
end | |
#site = 'https://jira-webhook-test.puppetlabs.com' | |
site = 'https://tickets.puppetlabs.com' | |
opts = GetoptLong.new( | |
['--help', '-h', GetoptLong::NO_ARGUMENT], | |
['--builder', '-b', GetoptLong::REQUIRED_ARGUMENT], | |
['--developer', '-d', GetoptLong::REQUIRED_ARGUMENT], | |
['--project', '-p', GetoptLong::REQUIRED_ARGUMENT], | |
['--release', '-r', GetoptLong::REQUIRED_ARGUMENT], | |
['--writer', '-w', GetoptLong::REQUIRED_ARGUMENT] | |
) | |
known_projects = ['FACT', 'HI', 'PUP', 'NC'] | |
known_devs = ['kylo', 'andy', 'patrick'] | |
known_builders = ['melissa', 'matthaus', 'ryan.mckern'] | |
known_writers = ['justin.holguin', 'nickf'] | |
def help | |
puts " | |
$PROGRAM_NAME [options] | |
-h, --help: | |
show help | |
-b x, --builder x | |
Required. Must be a known build engineer id in Jira | |
-d x, --developer x | |
Required. Must be a known developer id in Jira | |
-p x, --project x | |
Required. Must be one of: FACT, HI, PUP, NC | |
-r x, --release x | |
Required. Must be a release number, e.g. 1.7.5-rc3 or 4.0.1 | |
-w x, --writer x | |
Required. Must be a known documentarian id in Jira | |
" | |
exit | |
end | |
builder = nil | |
developer = nil | |
project = nil | |
release = nil | |
writer = nil | |
begin | |
opts.each do |opt, arg| | |
case opt | |
when '--help' | |
help | |
when '--builder' | |
builder = arg | |
when '--developer' | |
developer = arg | |
when '--project' | |
project = arg | |
when '--release' | |
release = arg | |
when '--writer' | |
writer = arg | |
end | |
end | |
rescue | |
help | |
end | |
if release.nil? or project.nil? or developer.nil? or builder.nil? or writer.nil? | |
puts "Must specify builder, developer, writer, project, and release" | |
help | |
end | |
if not known_projects.include? project | |
puts "Project must be one of #{known_projects.join(', ')}" | |
help | |
end | |
if not known_builders.include? builder | |
puts "Build Engineer must be one of #{known_builders.join(', ')}" | |
help | |
end | |
if not known_devs.include? developer | |
puts "Developer must be one of #{known_devs.join(', ')}" | |
help | |
end | |
# The how-to for releasing FOSS. The subtickets below should be sanity checked | |
# against the doc for each release. In fact, that's the first subticket :) | |
release_doc = "https://confluence.puppetlabs.com/display/DEL/FOSS+Release+Process" | |
# The subtickets to create for the individual tasks | |
subtickets = | |
[ | |
{ | |
:summary => 'Is checklist current', | |
:description => "Do sub-tickets here match steps in #{release_doc}? And do those steps need updating for any recent tooling changes?", | |
:assignee => developer | |
}, | |
{ | |
:summary => 'Ensure tests are passing', | |
:description => 'All tests (spec, acceptance) should be passing on all platforms.', | |
:assignee => developer | |
}, | |
{ | |
:summary => 'Is there a bug targeted at the release for every commit?', | |
:description => '', | |
:assignee => developer | |
}, | |
{ | |
:summary => 'Is there a commit for every bug targeted at the release?', | |
:description => '', | |
:assignee => developer | |
}, | |
{ | |
:summary => 'Is a new version created for the next version in the series?', | |
:description => '', | |
:assignee => developer | |
}, | |
{ | |
:summary => 'Prepare long form release notes and short form release story', | |
:description => 'Collaborating with product for release story', | |
:assignee => writer | |
}, | |
{ | |
:summary => 'Update version number', | |
:description => '', | |
:assignee => developer | |
}, | |
{ | |
:summary => 'Tag the release and create packages', | |
:description => 'Developer provides the SHA', | |
:assignee => builder | |
}, | |
{ | |
:summary => 'Smoke test packages', | |
:description => 'Procedure may vary by project and point in the release cycle. Ask around.', | |
:assignee => developer | |
}, | |
{ | |
:summary => 'Go/no-go meeting', | |
:description => 'Should include: dev, docs, product, qa, releng', | |
:assignee => developer | |
}, | |
{ | |
:summary => 'Docs pushed', | |
:description => '', | |
:assignee => writer | |
}, | |
{ | |
:summary => 'Packages pushed', | |
:description => '', | |
:assignee => builder | |
}, | |
{ | |
:summary => 'Push tag' | |
:description => '', | |
:assignee => builder | |
}, | |
{ | |
:summary => 'Update the downloads page', | |
:description => '', | |
:assignee => builder | |
}, | |
{ | |
:summary => 'Send out announcements', | |
:description => '', | |
:assignee => 'eric.sorenson' | |
}, | |
{ | |
:summary => 'Close all resolved tickets in Jira', | |
:description => '', | |
:assignee => developer | |
}, | |
] | |
# Jira client options | |
options = { | |
:username => username, | |
:password => password, | |
:site => site, | |
:context_path => '', | |
:auth_type => :basic, | |
:use_ssl => true, | |
:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, | |
} | |
client = JIRA::Client.new(options) | |
projects = client.Project.all | |
project_name = projects.find { |p| p.key == project } | |
name = project_name.name | |
summary = "#{name} #{release}" | |
issue = client.Issue.build | |
issue.save!({'fields' => { | |
'summary' => "#{summary} Release", | |
'description' => "See https://confluence.puppetlabs.com/display/DEL/FOSS+Release+Process", | |
'project' => { 'key' => "#{project}" }, | |
'issuetype' => { 'name' => "Task" }, | |
'assignee' => { 'name' => developer } | |
} | |
} | |
) | |
issue.fetch | |
puts "Main release ticket: #{issue.key} (#{issue.assignee.name}) - #{issue.summary}" | |
parent_id = issue.id | |
subticket_idx = 1 | |
subtickets.each { |subticket| | |
issue2 = client.Issue.build | |
subticket_fields = {'fields' => { | |
'summary' => subticket[:summary], | |
'description' => subticket[:description], | |
'project' => { 'key' => "#{project}" }, | |
'parent' => { 'id' => parent_id }, | |
'issuetype' => { 'name' => 'Sub-task'}, | |
'assignee' => { 'name' => subticket[:assignee]} | |
} | |
} | |
issue2.save!(subticket_fields) | |
issue2.fetch | |
puts "\tSubticket #{subticket_idx.to_s.rjust(2)}: #{issue2.key} (#{subticket[:assignee]}) - #{subticket[:summary]}" | |
subticket_idx += 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment