tc-client 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  *swp
2
+ *gem
@@ -0,0 +1,22 @@
1
+ TCClient
2
+ ------
3
+ A simple ruby based Team City build checker.
4
+
5
+ Installation
6
+ ------------
7
+ * gem install tc-client
8
+ * Create a file in your home directory (i.e. ~ on linux) called .tc-client
9
+
10
+ Add in:
11
+ user: <user-name>
12
+ pwd: <password>
13
+ base_url: <url to team city instance (servername and port)>
14
+
15
+ projects:
16
+ <short name> : <build target number>
17
+ ...
18
+ <short name n> : <build target number n>
19
+
20
+ Usage
21
+ -----
22
+ tc-client [short name]
@@ -3,12 +3,19 @@
3
3
  $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
4
4
  require 'tc-client'
5
5
 
6
- if ARGV.length != 1
6
+ client = TCClient.new(false)
7
+
8
+ case ARGV.length
9
+ when 1 then
10
+ puts "Available builds on #{ARGV[0]}: "
11
+ puts client.builds(ARGV[0]).map { |x| x[:name] }
12
+ when 2
13
+ puts "Last 10 builds on #{ARGV[0]} [#{ARGV[1]}]: "
14
+ client.statuses(ARGV[0], ARGV[1]).each do |x|
15
+ puts "#{x[:build]} (#{x[:status]})"
16
+ end
17
+ else
7
18
  puts "Usage: #{File.basename(__FILE__)} [build project]"
8
- puts "Available builds:"
9
- puts projects.keys.sort
10
- Process.exit
19
+ puts "Available projects:"
20
+ puts client.projects.map {|x| x[:name] }
11
21
  end
12
-
13
- client = TCClient.new(ARGV[0])
14
- puts client.builds
@@ -3,35 +3,49 @@ require 'restclient'
3
3
  require 'rexml/document'
4
4
  require 'yaml'
5
5
 
6
- def config
7
- file = File.expand_path('~/.tc-client')
8
- raise "No configuration file found! Please provide one at #{file}" unless File.exists? file
9
- @config ||= YAML::load(File.open(file))
10
- end
11
-
12
- def projects
13
- config["projects"].to_hash
14
- end
15
-
16
6
  class TCClient
17
- def initialize(project)
18
- @count = 10
19
- @project = projects[project]
7
+ attr_accessor :config, :base_url, :user, :pwd
8
+ def initialize(verbose=true)
9
+ file = File.expand_path('~/.tc-client')
10
+ raise "No configuration file found! Please provide one at #{file}" unless File.exists? file
20
11
 
12
+ @config ||= YAML::load(File.open(file))
21
13
  @base_url = config["base_url"]
22
- puts "last #{@count} (successful) builds for #{project} (#{@project})"
23
14
  @user = config["user"]
24
15
  @pwd = config["pwd"]
16
+ @verbose = verbose
25
17
  end
26
18
 
27
- def builds
28
- xml = RestClient.get "http://#{@user}:#{@pwd}@#{@base_url}/httpAuth/app/rest/buildTypes/id:#{@project}/builds?status=SUCCESS&count=#{@count}"
19
+ def projects
20
+ xml = get("/httpAuth/app/rest/projects")
29
21
  doc = REXML::Document.new xml
30
- builds = []
31
- doc.elements.each("builds/build") do |build|
32
- builds << build.attributes["number"]
33
- end
34
- builds
22
+ doc.elements.collect("projects/project") { |p| { :name => p.attributes["name"], :href => p.attributes["href"]} }
23
+ end
24
+
25
+ def builds(project)
26
+ p = projects.select{|x| x[:name] == project}.first[:href]
27
+ xml = get(p)
28
+ doc = REXML::Document.new xml
29
+ doc.elements.collect("project/buildTypes/buildType") { |b| { :name => b.attributes["name"], :href => b.attributes["href"] } }
30
+ end
31
+
32
+ def statuses(project, build)
33
+ b = builds(project).select{|x| x[:name] == build}.first[:href]
34
+ xml = get("#{b}/builds?count=10")
35
+ doc = REXML::Document.new xml
36
+ doc.elements.collect("builds/build") {|x| { :build => x.attributes["number"], :status => x.attributes["status"] } }
37
+ end
38
+
39
+ def get(what)
40
+ verbose("http://#{@user}:#{@pwd}@#{@base_url}#{what}") {|x|
41
+ RestClient.get x
42
+ }
43
+ end
44
+
45
+ def verbose(url)
46
+ puts url if @verbose
47
+ yield url if block_given?
35
48
  end
36
49
  end
37
50
 
51
+
@@ -1,3 +1,3 @@
1
1
  class TCClient
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
4
+ require "version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "tc-client"
8
+ s.version = TCClient::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Kristoffer Roupe"]
11
+ s.email = ["kitofr@gmail.com"]
12
+ s.homepage = "http://github.com/kitofr/tc-client"
13
+ s.add_dependency "rest-client", ">= 1.6.1"
14
+
15
+ s.summary = %q{A simple ruby based Team City build checker}
16
+ s.description = %q{Sometimes you just need to know!}
17
+
18
+ s.rubyforge_project = "tc-client"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ s.required_ruby_version = '>= 1.8.7'
25
+ end
26
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tc-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kristoffer Roupe
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-21 00:00:00 +02:00
18
+ date: 2012-03-21 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -45,9 +45,11 @@ extra_rdoc_files: []
45
45
 
46
46
  files:
47
47
  - .gitignore
48
+ - README.rdoc
48
49
  - bin/tc-client
49
50
  - lib/tc-client.rb
50
51
  - lib/version.rb
52
+ - tc-client.gemspec
51
53
  has_rdoc: true
52
54
  homepage: http://github.com/kitofr/tc-client
53
55
  licenses: []