Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Changing the jenkins/hudson branch name #15

Merged
merged 2 commits into from

2 participants

@tmacedo

No description provided.

@mikz mikz merged commit 95b4abe into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 22, 2012
  1. ability to change branch name !job job-name branch-name

    Tiago Macedo authored
  2. name of job is assumed to be the nickname

    Tiago Macedo authored
This page is out of date. Refresh to see the latest.
View
1  Gemfile
@@ -27,6 +27,7 @@ gem 'github_api'
gem 'json'
gem 'nokogiri'
+gem 'curb'
group :test do
gem 'rspec'
View
2  Gemfile.lock
@@ -8,6 +8,7 @@ GEM
awesome_print (1.0.2)
cinch (2.0.2)
coderay (1.0.6)
+ curb (0.8.0)
diff-lcs (1.1.3)
fakefs (0.4.0)
faraday (0.7.6)
@@ -64,6 +65,7 @@ DEPENDENCIES
activesupport
awesome_print
cinch
+ curb
fakefs
github_api
hiredis
View
10 plugins/hudson.rb
@@ -6,6 +6,7 @@ class Hudson
autoload :Fetcher, 'hudson/fetcher'
autoload :Reporter, 'hudson/reporter'
autoload :TestRun, 'hudson/test_run'
+ autoload :Config, 'hudson/config'
HYDRA = Typhoeus::Hydra.new
@@ -16,6 +17,7 @@ class Hudson
match /#{FAILED} #{JOB}#{BUILD}$/, method: :failures
match /(?:failures|failed|f) #{JOB}#{BUILD} diff #{JOB}#{BUILD}$/, method: :diff
match /Project (.+?) build #(\d+): (?:SUCCESS|FIXED) (?:.+?): (.*)$/, method: :green, :use_prefix => false
+ match /(?:job) (.*)$/, method: :update_branch
register_help 'failures|failed|f project', 'list failed tests (cukes and test units) from last test run'
register_help 'failures|failed|f project/test_number', 'list failed tests from specific test run'
@@ -45,4 +47,12 @@ def green(m, project_name, build, url)
issues.comment(m, pull["number"], "Green: #{url}") if pull
end
end
+
+ def update_branch(m, new_branch)
+ config = Config.new(m.user.to_s)
+ config.update_branch(new_branch)
+ m.reply "Job updated"
+ rescue
+ m.reply "Error updating job"
+ end
end
View
32 plugins/hudson/config.rb
@@ -0,0 +1,32 @@
+require 'open-uri'
+
+class Hudson
+ class Config
+ BASE_URL = "http://localhost:8080"
+ CONFIG_URL = "/job/<project>/config.xml"
+
+ attr_reader :job
+
+ def initialize(job)
+ @job = job
+ end
+
+ def config_url
+ (BASE_URL + CONFIG_URL).gsub('<project>', job)
+ end
+
+ def config
+ @config ||= Nokogiri::XML(open(config_url))
+ end
+
+ def update_branch(branch_name)
+ config.xpath('/project/scm/branches/hudson.plugins.git.BranchSpec/name').each do |branch|
+ branch.content = branch_name
+ end
+
+ Curl::Easy.http_post(config_url, config.to_s) do |curl|
+ curl.headers['Content-Type'] = 'text/xml'
+ end
+ end
+ end
+end
View
2  plugins/hudson/fetcher.rb
@@ -1,6 +1,6 @@
class Hudson
class Fetcher < Typhoeus::Request
- BASE_URL = "http://localhost:8080/"
+ BASE_URL = "http://localhost:8080"
JOB_URL = "/job/<project>/<test_run>/consoleText"
attr_reader :test_run
Something went wrong with that request. Please try again.