Created
April 2, 2013 00:24
-
-
Save miketheman/5288950 to your computer and use it in GitHub Desktop.
Auto-create formatted output for Chef Cookbook Changelog
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 'date' | |
require 'jiralicious' | |
require 'json' | |
require 'net/https' | |
require 'uri' | |
# couldn't quite figure out anonymous API search, so use some method to pass these in here. | |
username = "myusername" | |
password = "somesecretpassword" | |
# Pass component name on command line as first argument | |
componentname = ARGV[0] | |
Jiralicious.configure do |config| | |
config.username = username | |
config.password = password | |
config.uri = "https://tickets.opscode.com/" | |
config.api_version = "latest" | |
config.auth_type = :basic | |
end | |
def date_to_jql(date) | |
date.strftime('%Y/%m/%d') | |
end | |
def call_community_api(url) | |
api_root = "https://cookbooks.opscode.com/api/v1" | |
uri = URI.parse("#{api_root}/#{url}") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Get.new(uri.request_uri) | |
response = http.request(request) | |
json = JSON.parse(response.body) | |
# Can't use HTTParty right now, problem with json parsing. Would have been a bit cleaner. | |
# Ref: https://github.com/jstewart/jiralicious/issues/5 | |
# response = HTTParty.get("#{api_root}/#{url}") | |
end | |
def find_previous_release_date(component) | |
url = "cookbooks/#{component}/versions/latest" | |
details = call_community_api(url) | |
@latest_version = details['version'] | |
latest_update = date_to_jql(Date.parse details['updated_at']) | |
end | |
def find_issues_since_release(component, date) | |
today = date_to_jql(Date.today) | |
# Construct a JQL query, escape quotes | |
jql = "project = COOK AND resolution = Fixed AND status = \"Fix Committed\"" | |
jql << " AND resolutiondate < \"#{today}\"" | |
jql << " AND resolutiondate > \"#{date}\"" | |
jql << " AND component = #{component}" | |
query = Jiralicious.search(jql) | |
query.issues | |
end | |
def format_for_changelog(issues) | |
puts "## v#{@latest_version}:\n\n" | |
# This sorts issues based on type, instead of JIRA key. Easy to change. | |
issues.sort! { |a,b| a.fields['issuetype']['name'] <=> b.fields['issuetype']['name'] } | |
# Took a bit of liberty in formatting this, it's flexible enough to do anything you like | |
issues.each do |issue| | |
puts "* [#{issue.jira_key}] | #{issue.fields['issuetype']['name']} | #{issue.fields['summary']}" | |
end | |
end | |
# Main | |
prev_date = find_previous_release_date(componentname) | |
issues = find_issues_since_release(componentname, prev_date) | |
format_for_changelog(issues) |
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
gem install jiralicious | |
Tested on Ruby 1.9.3, jiralicious 0.1.0 |
Getting a nilNilclass error from jiralicious:
/Users/jtimberman/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jiralicious-0.1.0/lib/jiralicious/search.rb:17:in `block in search': Jiralicious::JqlError (Jiralicious::JqlError)
from /Users/jtimberman/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jiralicious-0.1.0/lib/jiralicious/session.rb:23:in `call'
from /Users/jtimberman/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jiralicious-0.1.0/lib/jiralicious/session.rb:23:in `request'
from /Users/jtimberman/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/jiralicious-0.1.0/lib/jiralicious/search.rb:21:in `search'
from ./clformat.rb:62:in `find_issues_since_release'
from ./clformat.rb:82:in `<main>'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a logical bug with https://gist.github.com/miketheman/5288950#file-clformat-rb-L68, in that I use the latest_version as the header for the next section. Can be removed, offers no real functionality.