-
-
Save miketheman/5791871 to your computer and use it in GitHub Desktop.
Updated clformat for URL handling
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 'bundler/setup' | |
require 'date' | |
require 'jiralicious' | |
require 'json' | |
require 'net/https' | |
require 'uri' | |
# Pass component name on command line as first argument | |
componentname = ARGV[0] || ENV['COMPONENT'] | |
# load credentials from a plain text file on your filesystem. security! | |
credentials = JSON.parse(IO.read(File.join("/", File.expand_path(ENV['HOME']), ".jira"))) | |
Jiralicious.configure do |config| | |
config.username = credentials['username'] | |
config.password = credentials['pw'] | |
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" | |
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 "## vREPLACE:\n\n" | |
tickets = {} | |
issues.each do |i| | |
issuetype = i.fields.current['issuetype']['name'] | |
tickets[issuetype] ||= [] | |
tickets[issuetype] << { | |
"jira_key" => i.jira_key, | |
"summary" => i.fields.current['summary'] | |
} | |
end | |
tickets.each_key do |type| | |
puts "### #{type}\n\n" | |
tickets[type].sort! {|a,b| a['jira_key'] <=> b['jira_key']} | |
tickets[type].each do |data| | |
url = "http://tickets.opscode.com/browse/#{data['jira_key']}" | |
puts "- [[#{data['jira_key']}](url)]: #{data['summary']}" | |
end | |
puts "\n" | |
end | |
end | |
# Main | |
prev_date = find_previous_release_date(componentname) | |
issues = find_issues_since_release(componentname, prev_date) | |
format_for_changelog(issues) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment