Created
February 2, 2012 14:24
-
-
Save ejsarge/1723696 to your computer and use it in GitHub Desktop.
Jazz Rational Team Concert Work Items to GitHub 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
# This script converts unresolved work items in IBM Rational Team Concert and | |
# imports them into GitHub as issues. | |
# | |
# Copyright (C) 2012 TrailHunger.com Trail Data Inc. | |
# Contact: edward@trailhunger.com | |
# Licence: Creative Commons Attribution Share-Alike (http://creativecommons.org/licenses/by-sa/2.5/ca/) | |
# To attribute: Please credit TrailHunger.com and link to any page on the site. | |
# Usage: | |
# 1. Replace github-username and github-password with your GitHub username and password. | |
# 2. Replace jazz.trailhunger.com:9443/jazz with the base url to your Jazz server. | |
# 3. Replace jazz-username and jazz-password with your Jazz username and password. | |
# 4. Run it. (ruby JazzToGitIssues.rb) | |
require 'rubygems' | |
require 'HTTParty' | |
require 'crack' | |
require 'pp' | |
require 'json' | |
class Jazz | |
include HTTParty | |
end | |
class Github | |
include HTTParty | |
base_uri 'https://api.github.com' | |
basic_auth 'github-username', 'github-password' | |
end | |
puts "Authenticating..." | |
response = Jazz.get('https://jazz.trailhunger.com:9443/jazz/authenticated/identity') | |
puts "Sending username and password..." | |
@cookie = response.headers['Set-Cookie'] | |
response = Jazz.get('https://jazz.trailhunger.com:9443/jazz/authenticated/j_security_check', | |
:query => { "j_username" => "jazz-username", "j_password" => "jazz-password"}, | |
:headers => {'Cookie' => response.headers['Set-Cookie']}) | |
if response.headers['x-com-ibm-team-repository-web-auth-msg'] == 'authfailed' | |
abort "Authentication failed" | |
end | |
puts "Authentication successful" | |
@cookie = @cookie + ", " + response.headers['Set-Cookie'] | |
puts "Discovering services" | |
response = Jazz.get('https://jazz.trailhunger.com:9443/jazz/rootservices', :headers=> {'Cookie' => @cookie}) | |
puts "Discovering CM Service Providers" | |
services = Crack::XML.parse(response.body) | |
cmServiceProvidersResource = services["rdf:Description"]["oslc_cm:cmServiceProviders"]["rdf:resource"] | |
puts "Discovering CM Services" | |
response = Jazz.get(cmServiceProvidersResource, :headers=> {'Cookie' => @cookie}) | |
providers = Crack::XML.parse(response.body) | |
cmServices = providers["oslc_disc:ServiceProviderCatalog"]["oslc_disc:entry"]["oslc_disc:ServiceProvider"]["oslc_disc:services"]["rdf:resource"] | |
puts "Discovering Change Requests simpleQuery" | |
response = Jazz.get(cmServices, :headers=> {'Cookie' => @cookie}) | |
serviceDescriptor = Crack::XML.parse(response.body) | |
simpleQuery = serviceDescriptor["oslc_cm:ServiceDescriptor"]["oslc_cm:changeRequests"]["oslc_cm:simpleQuery"]["oslc_cm:url"] | |
puts "Querying simpleQuery..." | |
response = Jazz.get(simpleQuery, :headers=> {'Cookie' => @cookie, 'Accept' => 'application/x-oslc-cm-change-request+xml'}) | |
puts "...parsing" | |
results = Crack::XML.parse(response) | |
openChangeRequests = results["oslc_cm:Collection"]["oslc_cm:ChangeRequest"].select{ |cr| cr["rtc_cm:resolved"].nil?} | |
openChangeRequests.each{ |ocr| | |
if ocr["dc:description"].nil? | |
jsonData = { "title" => ocr["dc:title"] } | |
else | |
jsonData = { "title" => ocr["dc:title"], "body" => ocr["dc:description"] } | |
end | |
gitIssueJson = jsonData.to_json | |
response = Github.post('/repos/ejsarge/trailhunger/issues', :body => gitIssueJson ) | |
puts ocr["dc:title"], response.code | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment