jenkins_tracker 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,24 +3,33 @@
3
3
  [![Build Status](https://travis-ci.org/prashantrajan/jenkins_tracker.png?branch=master)](https://travis-ci.org/prashantrajan/jenkins_tracker)
4
4
  [![Gem Version](https://badge.fury.io/rb/jenkins_tracker.png)](http://badge.fury.io/rb/jenkins_tracker)
5
5
 
6
- `jenkins_tracker` is a command line utility packaged as a [RubyGem](https://rubygems.org/gems/jenkins_tracker) that integrates [Jenkins](http://jenkins-ci.org/) build information with
7
- the relevant [Pivotal Tracker](https://www.pivotaltracker.com) stories within a project.
6
+ `jenkins_tracker` is a command line utility packaged as a [RubyGem](https://rubygems.org/gems/jenkins_tracker) that
7
+ integrates [Jenkins CI](http://jenkins-ci.org/) build information with [Pivotal Tracker](https://www.pivotaltracker.com) stories within a project.
8
+ The underlying library is also used in the native [Jenkins Tracker Plugin](https://github.com/prashantrajan/jenkins-tracker-plugin).
8
9
 
9
- This utility makes some very specific assumptions about your Jenkins environment:-
10
+ This is an example of a successful build integration:
11
+
12
+ ![Jenkins Post Build Action Screenshot](https://raw.github.com/prashantrajan/static_assets/master/jenkins_tracker/images/tracker_comment_2.jpg)
13
+
14
+
15
+ ## Requirements
16
+
17
+ ### Jenkins
10
18
 
11
19
  * Git as your SCM via the [Jenkins Git Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin).
12
20
 
13
- * The Jenkins build changelog file is available at `$JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_NUMBER/changelog.xml`.
21
+ * The build changelog file is available at `$JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_NUMBER/changelog.xml`.
14
22
  The changelog contents look like this [example](https://github.com/prashantrajan/jenkins_tracker/blob/master/spec/fixtures/git_changelog.txt).
15
23
 
16
- * Ability to execute Ruby 1.9.x scripts.
24
+ * `Ruby` is available in the environment.
17
25
 
18
26
  * Environment variables exists for `$JENKINS_HOME`, `$JOB_NAME`, `$BUILD_NUMBER` & `$BUILD_URL`.
19
27
 
28
+ ### Pivotal Tracker
20
29
 
21
- The following are required for your Pivotal Tracker project:-
30
+ * You have created an [API Token](https://www.pivotaltracker.com/profile).
22
31
 
23
- * [API access enabled](https://www.pivotaltracker.com/help/api) (enabled by default).
32
+ * Project has [API access enabled](https://www.pivotaltracker.com/help/api) (it's enabled by default).
24
33
 
25
34
 
26
35
  ## Installation
@@ -40,18 +49,18 @@ Or install it yourself as:
40
49
 
41
50
  ## Usage
42
51
 
43
- # Assuming environment variables for $JENKINS_HOME, $JOB_NAME, $BUILD_NUMBER & $BUILD_URL exists
44
-
45
- $ bundle exec jenkins_tracker integrate --tracker-token ABC123456 --tracker-project-id 123456
46
- # => Successfully integrated Jenkins Job ($JOB_NAME) with Pivotal Tracker Project (123456)
52
+ ### As a Post-build Action script
47
53
 
48
- This utility could be run as a `Post Build Action` in Jenkins:
54
+ Requires the [Post build task plugin](http://wiki.hudson-ci.org/display/HUDSON/Post+build+task):
49
55
 
50
- ![Jenkins Post Build Action Screenshot](https://raw.github.com/prashantrajan/static_assets/master/jenkins_tracker/images/jenkins_post_build_action.jpg)
56
+ ```
57
+ # Assuming environment variables for $JENKINS_HOME, $JOB_NAME, $BUILD_NUMBER & $BUILD_URL exists
51
58
 
52
- The integration will result in comments being added to the relevant Pivotal Tracker stories:
53
-
54
- ![Jenkins Post Build Action Screenshot](https://raw.github.com/prashantrajan/static_assets/master/jenkins_tracker/images/tracker_comment_2.jpg)
59
+ $ bundle exec jenkins_tracker integrate --tracker-token ABC123456 --tracker-project-id 123456
60
+ # => Successfully integrated Jenkins Job $JOB_NAME with Pivotal Tracker Project #123456
61
+ ```
62
+
63
+ ![Jenkins Post Build Action Screenshot](https://raw.github.com/prashantrajan/static_assets/master/jenkins_tracker/images/jenkins_post_build_action_2.jpg)
55
64
 
56
65
 
57
66
  ## Contributing
@@ -1,5 +1,4 @@
1
1
  #require 'json'
2
- require 'ostruct'
3
2
 
4
3
  require 'rest-client'
5
4
 
@@ -7,4 +6,5 @@ require 'jenkins_tracker/version'
7
6
  require 'jenkins_tracker/exceptions'
8
7
  require 'jenkins_tracker/util'
9
8
  require 'jenkins_tracker/tracker_client'
9
+ require 'jenkins_tracker/changelog_item'
10
10
  require 'jenkins_tracker/base'
@@ -1,6 +1,6 @@
1
1
  module JenkinsTracker
2
2
  class Base
3
- include Util
3
+ #include Util
4
4
 
5
5
  attr_reader :changelog, :tracker_client, :job_name, :build_url
6
6
 
@@ -17,11 +17,30 @@ module JenkinsTracker
17
17
  end
18
18
 
19
19
  def integrate_job_with_tracker(project_id)
20
- parse_changelog(changelog).each do |change|
20
+ parse_changelog.each do |change|
21
21
  note = "*#{change.commit_message}* integrated in *#{job_name}* (#{build_url})"
22
22
  tracker_client.add_note_to_story(project_id, change.story_id, note)
23
23
  end
24
24
  end
25
25
 
26
+ def parse_changelog
27
+ results = []
28
+
29
+ changelog.scan(/(\[[#a-zA-Z0-9\s]+\])(.*)/) do |ids, msg|
30
+ parse_tracker_story_ids(ids).each do |id|
31
+ results << ChangelogItem.new(:story_id => id, :commit_message => "#{ids}#{msg}".strip)
32
+ end
33
+ end
34
+
35
+ results.uniq
36
+ end
37
+
38
+
39
+ private
40
+
41
+ def parse_tracker_story_ids(str)
42
+ str.strip.gsub(/[\[#\]]/, '').split(' ').map(&:to_i).reject { |i| i == 0 }
43
+ end
44
+
26
45
  end
27
46
  end
@@ -0,0 +1,24 @@
1
+ module JenkinsTracker
2
+ class ChangelogItem
3
+
4
+ attr_accessor :story_id, :commit_message
5
+
6
+ def initialize(options = {})
7
+ @story_id = options[:story_id]
8
+ @commit_message = options[:commit_message]
9
+ end
10
+
11
+ def ==(other)
12
+ self.story_id == other.story_id && self.commit_message == other.commit_message
13
+ end
14
+
15
+ def eql?(other)
16
+ (self.class == other.class) && self == other
17
+ end
18
+
19
+ def hash
20
+ [story_id, commit_message].hash
21
+ end
22
+
23
+ end
24
+ end
@@ -17,7 +17,7 @@ module JenkinsTracker
17
17
  connection["projects/#{project_id}/stories/#{story_id}/notes"].post("<note><text>#{note}</text></note>")
18
18
  rescue => e
19
19
  # if the post fails for whatever reason (e.g. invalid story id etc), just ignore it
20
- puts ["An error occurred while trying add note to Story ##{story_id} in Project ##{project_id} ", e.message, e.backtrace] * "\n"
20
+ #puts ["An error occurred while trying add note to Story ##{story_id} in Project ##{project_id} ", e.message, e.backtrace] * "\n"
21
21
  end
22
22
  end
23
23
 
@@ -12,21 +12,5 @@ module JenkinsTracker
12
12
  # JSON.parse(str, options)
13
13
  #end
14
14
 
15
- def parse_changelog(str)
16
- results = []
17
-
18
- str.scan(/(\[[#a-zA-Z0-9\s]+\])(.*)/) do |ids, msg|
19
- parse_tracker_story_ids(ids).each do |id|
20
- results << OpenStruct.new(:story_id => id, :commit_message => "#{ids}#{msg}".strip)
21
- end
22
- end
23
-
24
- results
25
- end
26
-
27
- def parse_tracker_story_ids(str)
28
- str.strip.gsub(/[\[#\]]/, '').split(' ').map(&:to_i).reject { |i| i == 0 }
29
- end
30
-
31
15
  end
32
16
  end
@@ -1,3 +1,3 @@
1
1
  module JenkinsTracker
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -0,0 +1,39 @@
1
+ Changes in branch origin/master, between c0d9a605c020d0ccaac2ef7f4a52607f0b1032ff and 05b96f9a60360525b5a17721e0ed107e53f42ede
2
+ commit 05b96f9a60360525b5a17721e0ed107e53f42ede
3
+ tree 90fae1497ff2e0eb19992993ac2a335561ef9e21
4
+ parent b1d0cda2f3766e5285cbe6f8c788d5d3c2d0aaf3
5
+ author Prashant Nadarajan <mrp@example.com> 1360758891 +0800
6
+ committer Prashant Nadarajan <mrp@example.com> 1360758902 +0800
7
+
8
+ [#123 #456] added more test
9
+
10
+ :100644 100644 7da3210b8da221718054af45ca5384a1b3c5a654 e57a7a9b044142080875d0b5b6548ea62f666143 M README.md
11
+
12
+ commit b1d0cda2f3766e5285cbe6f8c788d5d3c2d0aaf3
13
+ tree 5364d5d2ec4e082218ef7a1d779ac35a89647f3b
14
+ parent c0d9a605c020d0ccaac2ef7f4a52607f0b1032ff
15
+ author Prashant Nadarajan <mrp@example.com> 1360758738 +0800
16
+ committer Prashant Nadarajan <mrp@example.com> 1360758738 +0800
17
+
18
+ [Fixes #456 #789] added test 1 to readme
19
+
20
+ :100644 100644 3979ab174391acf45520c09801a8b6919fd9df95 7da3210b8da221718054af45ca5384a1b3c5a654 M README.md
21
+ commit 05b96f9a60360525b5a17721e0ed107e53f42ede
22
+ tree 90fae1497ff2e0eb19992993ac2a335561ef9e21
23
+ parent b1d0cda2f3766e5285cbe6f8c788d5d3c2d0aaf3
24
+ author Prashant Nadarajan <mrp@example.com> 1360758891 +0800
25
+ committer Prashant Nadarajan <mrp@example.com> 1360758902 +0800
26
+
27
+ [#123 #456] added more test
28
+
29
+ :100644 100644 7da3210b8da221718054af45ca5384a1b3c5a654 e57a7a9b044142080875d0b5b6548ea62f666143 M README.md
30
+
31
+ commit b1d0cda2f3766e5285cbe6f8c788d5d3c2d0aaf3
32
+ tree 5364d5d2ec4e082218ef7a1d779ac35a89647f3b
33
+ parent c0d9a605c020d0ccaac2ef7f4a52607f0b1032ff
34
+ author Prashant Nadarajan <mrp@example.com> 1360758738 +0800
35
+ committer Prashant Nadarajan <mrp@example.com> 1360758738 +0800
36
+
37
+ [Fixes #456 #789] added test 1 to readme
38
+
39
+ :100644 100644 3979ab174391acf45520c09801a8b6919fd9df95 7da3210b8da221718054af45ca5384a1b3c5a654 M README.md
@@ -35,4 +35,32 @@ describe JenkinsTracker::Base do
35
35
  end
36
36
  end
37
37
 
38
+ describe '#parse_changelog' do
39
+ it 'returns an array of ChangelogItems' do
40
+ changelog_file = fixture_file_path('git_changelog.txt')
41
+
42
+ results = described_class.new(:changelog_file => changelog_file).parse_changelog
43
+ expect(results.size).to eq(4)
44
+
45
+ expect(results.first.story_id).to eq(123)
46
+ expect(results.first.commit_message).to eq('[#123 #456] added more test')
47
+
48
+ expect(results.last.story_id).to eq(789)
49
+ expect(results.last.commit_message).to eq('[Fixes #456 #789] added test 1 to readme')
50
+ end
51
+
52
+ it 'does not return duplicate ChangelogItems' do
53
+ changelog_file = fixture_file_path('git_changelog_with_duplicates.txt')
54
+
55
+ results = described_class.new(:changelog_file => changelog_file).parse_changelog
56
+ expect(results.size).to eq(4)
57
+
58
+ expect(results.first.story_id).to eq(123)
59
+ expect(results.first.commit_message).to eq('[#123 #456] added more test')
60
+
61
+ expect(results.last.story_id).to eq(789)
62
+ expect(results.last.commit_message).to eq('[Fixes #456 #789] added test 1 to readme')
63
+ end
64
+ end
65
+
38
66
  end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe JenkinsTracker::ChangelogItem do
4
+
5
+ describe '#story_id' do
6
+ it 'accessor methods' do
7
+ expect(described_class.new).to respond_to('story_id')
8
+ expect(described_class.new).to respond_to('story_id=')
9
+ end
10
+ end
11
+
12
+ describe '#commit_message' do
13
+ it 'accessor methods' do
14
+ expect(described_class.new).to respond_to('commit_message')
15
+ expect(described_class.new).to respond_to('commit_message=')
16
+ end
17
+ end
18
+
19
+ describe '==(other)' do
20
+ it 'is equal to other when its story_id & commit_message are equal' do
21
+ item1 = described_class.new(:story_id => 1, :commit_message => '123abc')
22
+ item2 = described_class.new(:story_id => 1, :commit_message => '123abc')
23
+ item3 = item1
24
+
25
+ expect(item1).to eq(item2)
26
+ expect(item3).to eq(item2)
27
+ end
28
+
29
+ it 'is not equal to other when its story_id are not equal' do
30
+ item1 = described_class.new(:story_id => 1, :commit_message => '123abc')
31
+ item2 = described_class.new(:story_id => 2, :commit_message => '123abc')
32
+
33
+ expect(item1).to_not eq(item2)
34
+ end
35
+
36
+ it 'is not equal to other when its commit_message are not equal' do
37
+ item1 = described_class.new(:story_id => 1, :commit_message => '123abc')
38
+ item2 = described_class.new(:story_id => 1, :commit_message => 'xyz')
39
+
40
+ expect(item1).to_not eq(item2)
41
+ end
42
+ end
43
+
44
+ describe 'eql?(other)' do
45
+ let(:fake_changelog_class) { Struct.new(:story_id, :commit_message) }
46
+
47
+ it 'is equal to other when its class and attributes are equal' do
48
+ item1 = described_class.new(:story_id => 1, :commit_message => '123abc')
49
+ item2 = fake_changelog_class.new(1, '123abc')
50
+ item3 = item1
51
+
52
+ expect(item1).to_not eql(item2)
53
+ expect(item3).to eql(item1)
54
+ end
55
+ end
56
+
57
+ describe 'an array of ChangelogItems' do
58
+ it 'correctly removes duplicates when uniq is called' do
59
+ item1 = described_class.new(:story_id => 1, :commit_message => '123abc')
60
+ item2 = described_class.new(:story_id => 1, :commit_message => '123abc')
61
+ item3 = described_class.new(:story_id => 1, :commit_message => 'xyz')
62
+ item4 = described_class.new(:story_id => 2, :commit_message => '123abc')
63
+
64
+ expect([item1, item2].uniq.size).to eq(1)
65
+ expect([item1, item3].uniq.size).to eq(2)
66
+ expect([item1, item4].uniq.size).to eq(2)
67
+ expect([item1, item3, item4].uniq.size).to eq(3)
68
+ end
69
+ end
70
+
71
+ end
@@ -7,7 +7,7 @@ end
7
7
 
8
8
 
9
9
  describe JenkinsTracker::Util do
10
- let!(:class_instance) { UtilModuleTester.new }
10
+ #let!(:class_instance) { UtilModuleTester.new }
11
11
 
12
12
  #describe '#parse_json' do
13
13
  # let(:json_str) { load_fixture_as_str('job.json') }
@@ -19,17 +19,4 @@ describe JenkinsTracker::Util do
19
19
  #
20
20
  #end
21
21
 
22
- describe '#parse_changelog' do
23
- let(:git_changelog) { load_fixture_as_str('git_changelog.txt') }
24
-
25
- it 'returns an array of struct objects' do
26
- results = class_instance.parse_changelog(git_changelog)
27
- expect(results.first.story_id).to eq(123)
28
- expect(results.first.commit_message).to eq('[#123 #456] added more test')
29
-
30
- expect(results.last.story_id).to eq(789)
31
- expect(results.last.commit_message).to eq('[Fixes #456 #789] added test 1 to readme')
32
- end
33
- end
34
-
35
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-16 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -94,14 +94,17 @@ files:
94
94
  - jenkins_tracker.gemspec
95
95
  - lib/jenkins_tracker.rb
96
96
  - lib/jenkins_tracker/base.rb
97
+ - lib/jenkins_tracker/changelog_item.rb
97
98
  - lib/jenkins_tracker/cli.rb
98
99
  - lib/jenkins_tracker/exceptions.rb
99
100
  - lib/jenkins_tracker/tracker_client.rb
100
101
  - lib/jenkins_tracker/util.rb
101
102
  - lib/jenkins_tracker/version.rb
102
103
  - spec/fixtures/git_changelog.txt
104
+ - spec/fixtures/git_changelog_with_duplicates.txt
103
105
  - spec/fixtures/job.json
104
106
  - spec/jenkins_tracker/base_spec.rb
107
+ - spec/jenkins_tracker/changelog_item_spec.rb
105
108
  - spec/jenkins_tracker/tracker_client_spec.rb
106
109
  - spec/jenkins_tracker/util_spec.rb
107
110
  - spec/spec_helper.rb
@@ -120,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
123
  version: '0'
121
124
  segments:
122
125
  - 0
123
- hash: -2227372096919744340
126
+ hash: -4233350795122730482
124
127
  required_rubygems_version: !ruby/object:Gem::Requirement
125
128
  none: false
126
129
  requirements:
@@ -129,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
132
  version: '0'
130
133
  segments:
131
134
  - 0
132
- hash: -2227372096919744340
135
+ hash: -4233350795122730482
133
136
  requirements: []
134
137
  rubyforge_project:
135
138
  rubygems_version: 1.8.24
@@ -139,8 +142,10 @@ summary: Integrate Jenkins build information as notes in the relevant Pivotal Tr
139
142
  stories based on its post commit message
140
143
  test_files:
141
144
  - spec/fixtures/git_changelog.txt
145
+ - spec/fixtures/git_changelog_with_duplicates.txt
142
146
  - spec/fixtures/job.json
143
147
  - spec/jenkins_tracker/base_spec.rb
148
+ - spec/jenkins_tracker/changelog_item_spec.rb
144
149
  - spec/jenkins_tracker/tracker_client_spec.rb
145
150
  - spec/jenkins_tracker/util_spec.rb
146
151
  - spec/spec_helper.rb