Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Refactoring #1

Merged
merged 3 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 11, 2012
  1. @citizen428

    Rename file; add test

    citizen428 authored
  2. @citizen428

    Remove Nokogiri

    citizen428 authored
  3. @citizen428
This page is out of date. Refresh to see the latest.
View
3  Gemfile
@@ -3,9 +3,6 @@ source 'https://rubygems.org'
gem "httparty"
gem "rake"
-gem "nokogiri"
-#gem "github_api"
-#gem "awesome_print"
group :test do
gem 'rspec'
View
2  lib/kraken-build.rb
@@ -1,5 +1,5 @@
require "httparty"
-require 'nokogiri'
+require 'rexml/document'
require 'cgi'
require "kraken-build/version"
View
18 lib/kraken-build/jenkins-api.rb
@@ -1,9 +1,7 @@
class JenkinsApi
include HTTParty
-
def initialize(options = {})
-
if options[:port]
self.class.base_uri "#{options[:host]}:#{options[:port]}"
else
@@ -13,20 +11,17 @@ def initialize(options = {})
if(options[:username] && options[:password])
self.class.basic_auth options[:username] , options[:password]
end
-
end
def get_jobs(options = {})
response = self.class.get("/api/json/", options)
-
jobs = response["jobs"]
- jobs.map{|job| job["name"]}
+ jobs.map { |job| job["name"] }
end
def create_job(job, options = {})
- repo = job.split('.').first
- branch_name = job.split('.').last
+ repo, branch_name = job.split('.')
job_config = create_job_configuration(repo, branch_name)
options.merge!(
:body => job_config,
@@ -36,14 +31,11 @@ def create_job(job, options = {})
end
def create_job_configuration(repo, branch)
-
draft = get_job_configuration("#{repo}.master")
+ doc = REXML::Document.new(draft)
+ REXML::XPath.first(doc, '//branches//hudson.plugins.git.BranchSpec//name').text = branch
- doc = Nokogiri.XML(draft)
-
- doc.xpath('//branches//hudson.plugins.git.BranchSpec//name').first.content = "#{repo}.#{branch}"
-
- doc.to_xml
+ doc.to_s
end
def get_job_configuration(job, options = {})
View
8 spec/lib/jenins_api_spec.rb → spec/lib/jenkins_api_spec.rb
@@ -80,6 +80,14 @@
@api.get_job_configuration("FooJob").should be(a)
end
+ it "#create_job_configuration returns a valid job configuration" do
+ xml = <<XML
+<xml><branches><hudson.plugins.git.BranchSpec><name>master</name></hudson.plugins.git.BranchSpec></branches></xml>
+XML
+ xml.should_receive(:body).and_return(xml)
+ @api.class.should_receive(:get).with('/job/foobar.master/config.xml', {}).and_return(xml)
+ @api.create_job_configuration('foobar', 'feature').should =~ /feature/
+ end
end
Something went wrong with that request. Please try again.