agile_notifier 2.1.4 → 3.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c78f3a5bac969a0cc6f69d75d620318f6bcabedc
4
- data.tar.gz: 3adf76eb73e16945b7f12d6f8cdc184aa09cc8b5
3
+ metadata.gz: c4d765e04744af371120ff8963b4435a5cded507
4
+ data.tar.gz: 3070c25de18589db4dde7e1154553c7911ebc036
5
5
  SHA512:
6
- metadata.gz: 561aa816c522b782932f8aea9da5272bb939d2cac33f2b2ef37618b27dedd1e8f3742480dee1b4e6c89c1924d5c56694589a84ac20d7a8d874d07301ad2d29df
7
- data.tar.gz: eda22362859b2828cd0e64f3b5e832443ad42da30317862461d7f6a760c47b945f8aec0e3c9365505afe2e74ed8f304cbe812fd0cd60af88892518570a099b5e
6
+ metadata.gz: 3848b5b30accf802fcd4e8ae8d93431852ffa3a9eeb87e671e04d5cef3af9b42a185bc3dca5d2c590a7e988410b9a7298521ffe1d4369ea15cb99b6588d001a3
7
+ data.tar.gz: 5570e0b772767c7c74a995b61e36089bb3c906283c6f294a0aa991b63717d988421eacf9c8860d239e5f79d3823e3e9266cfeea9041734f799a75d26bcd35598
data/README.md CHANGED
@@ -13,7 +13,7 @@ The joy of this tool is that, whenever a build fails, it can blame whoever submi
13
13
 
14
14
  Have fun with it!
15
15
 
16
- ## Examples of Usage:
16
+ ## Examples of Usage
17
17
  ```ruby
18
18
  AgileNotifier::Configuration.set do
19
19
  ci_url 'http://x.x.x.x:8080'
@@ -29,7 +29,7 @@ AgileNotifier::Configuration.set do
29
29
  scm_get 'Github', enterprise: true
30
30
 
31
31
  # for non-enterprise version
32
- # scm_url 'https://api.github.com'
32
+ # scm_url 'https://github.com'
33
33
  # scm_repo user: 'your_user_name', repo: 'your_repository_name'
34
34
  # scm_get 'Github'
35
35
 
@@ -49,7 +49,23 @@ AgileNotifier::Configuration.set do
49
49
  end
50
50
  ```
51
51
 
52
- ## Notes:
52
+ ## Deploy to CI
53
+ First create a config file based on above DSL syntax. (let's say the file name is [*your_own_config*].rb)
54
+ ### Jenkins
55
+ * The **easy** way:
56
+ * Create [*The_Notification_Job*]
57
+ * Configure -> Build -> Execute shell:
58
+ * ```ruby [your_own_config].rb```
59
+ * Your Main Job
60
+ * Configure -> Add post-build action -> Build other projects -> Projects to build -> [*The_Notification_Job*]
61
+ * The **hard** but **precise** way: (imagine there are a few developers pushing all the time, which makes your CI build one after one without rest)
62
+ * Create [The_Notification_Job]
63
+ * Configure -> Build -> Execute shell:
64
+ * ```ruby [your_own_config].rb -b $UPSTREAM_BUILD_NUMBER```
65
+ * Your Main Job
66
+ * Configure -> Add post-build action -> Trigger parameterized build on other projects -> Projects to build -> [*The_Notification_Job*] -> Add Parameters -> Predefined parameters -> ```UPSTREAM_BUILD_NUMBER=${BUILD_NUMBER}```
67
+
68
+ ## Notes
53
69
  * TTS (Text To Speech) on Linux used here has two dependencies:
54
70
 
55
71
  * TTS service benefits from online MARY TTS Web Client: http://mary.dfki.de:59125/ While it has limited languages support, please check before use.
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.name = 'agile_notifier'
8
8
  s.version = AgileNotifier::VERSION
9
9
  s.license = 'MIT'
10
- s.date = '2015-05-01'
10
+ s.date = '2015-09-16'
11
11
  s.summary = %q{agile_notifier alerts you via making wonderful noises when your Continuous Integration status changes.}
12
12
  s.description = %q{agile_notifier alerts you via making wonderful noises when your Continuous Integration status changes. It totally makes software development more agile and more fun.}
13
13
  s.authors = ['Jing Li']
@@ -1,5 +1,5 @@
1
1
  Dir[(File.expand_path(File.dirname(__FILE__)) + "/agile_notifier/*.rb")].each { |file| require file }
2
2
 
3
3
  module AgileNotifier
4
- VERSION = '2.1.4'
4
+ VERSION = '3.0.0'
5
5
  end
@@ -6,12 +6,7 @@ module AgileNotifier
6
6
  include Servable
7
7
  alias_method :original_is_available?, :is_available?
8
8
 
9
- attr_accessor :jobs
10
-
11
- def initialize(url, *jobs)
12
- @url = url
13
- jobs.empty? ? @jobs = get_all_jobs : @jobs = jobs
14
- end
9
+ attr_accessor :job
15
10
 
16
11
  def is_available?
17
12
  original_is_available?(@url)
@@ -21,41 +16,24 @@ module AgileNotifier
21
16
  raise(NotImplementedError, "Abstract method [#{__method__}] is called, please implement", caller)
22
17
  end
23
18
 
24
- def job
25
- if @jobs.size == 1
26
- return @jobs.first
27
- else
28
- raise('There are more than one job, please use method [jobs] instead of [job]')
29
- end
30
- end
31
-
32
19
  class Job
33
20
  attr_accessor :name, :url
34
- attr_reader :last_build, :penultimate_build
21
+ attr_reader :current_build
35
22
 
36
- def initialize(name, url)
23
+ def initialize(name, url, build_number = nil)
37
24
  @name = name
38
25
  @url = url
39
- @last_build = get_last_build
40
- @penultimate_build = get_penultimate_build
26
+ @current_build = build_number.nil? ? get_last_build : get_specific_build(build_number.to_i)
41
27
  end
42
-
43
- def get_last_build
28
+
29
+ def get_specific_build(build_number)
44
30
  raise(NotImplementedError, "Abstract method [#{__method__}] is called, please implement", caller)
45
31
  end
46
32
 
47
- def get_penultimate_build
33
+ def get_last_build
48
34
  raise(NotImplementedError, "Abstract method [#{__method__}] is called, please implement", caller)
49
35
  end
50
36
 
51
- def update_last_build
52
- @last_build = get_last_build
53
- end
54
-
55
- def update_penultimate_build
56
- @penultimate_build = get_penultimate_build
57
- end
58
-
59
37
  class Build
60
38
  include Trackable
61
39
 
@@ -67,6 +45,10 @@ module AgileNotifier
67
45
  @result = get_result
68
46
  @revision = get_revision
69
47
  end
48
+
49
+ def is_building?
50
+ raise(NotImplementedError, "Abstract method [#{__method__}] is called, please implement", caller)
51
+ end
70
52
 
71
53
  def get_result
72
54
  raise(NotImplementedError, "Abstract method [#{__method__}] is called, please implement", caller)
@@ -0,0 +1,21 @@
1
+ require 'optparse'
2
+
3
+ module AgileNotifier
4
+ class Commander
5
+ class << self
6
+ def order(args)
7
+ options = {}
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: #{caller[-1].match(/\S+\.rb/)} [options]"
10
+
11
+ opts.on('-b', '--build-number [BUILD_NUMBER]', OptionParser::DecimalInteger, 'Trigger by specific build') do |build_number|
12
+ options[:build_number] = build_number
13
+ end
14
+ end.parse!
15
+ options
16
+ end
17
+ end
18
+
19
+ private_class_method :new
20
+ end
21
+ end
@@ -5,6 +5,8 @@ module AgileNotifier
5
5
  def initialize(&blk)
6
6
  @current_module = Object.const_get(self.class.to_s.split('::').first)
7
7
  @its_args = Hash.new
8
+ options = Commander.order(ARGV)
9
+ @build_number = options[:build_number]
8
10
  instance_eval(&blk)
9
11
  end
10
12
 
@@ -19,12 +21,11 @@ module AgileNotifier
19
21
  end
20
22
 
21
23
  def ci_job(job)
22
- @ci_jobs ||= []
23
- @ci_jobs.push(job)
24
+ @ci_job = job
24
25
  end
25
26
 
26
27
  def ci_get(ci_type)
27
- @ci = @current_module.const_get(ci_type).new(@ci_url, *@ci_jobs)
28
+ @ci = @current_module.const_get(ci_type).new(@ci_url, @ci_job, @build_number)
28
29
  end
29
30
 
30
31
  def scm_url(url)
@@ -100,8 +101,9 @@ module AgileNotifier
100
101
  judger_type = judger_type.to_s.downcase
101
102
  composer_method = "#{composer_type}_committer_of_a_commit".intern
102
103
  judger_method = "on_#{judger_type}".intern
103
- text = Composer.send(composer_method, repo: @scm.repository, revision: @ci.job.last_build.revision, language: @language)
104
- Judger.send(judger_method, @ci.job.last_build, text, organize_args)
104
+ build = @ci.job.current_build
105
+ text = Composer.send(composer_method, repo: @scm.repository, revision: build.revision, language: @language)
106
+ Judger.send(judger_method, build, text, organize_args)
105
107
  end
106
108
 
107
109
  def alert_on_wip
@@ -15,6 +15,7 @@ module AgileNotifier
15
15
 
16
16
  def initialize(url, args = {})
17
17
  super
18
+ @url.gsub!(/github\./, 'api.github.')
18
19
  basic_auth = args.fetch(:basic_auth, nil)
19
20
  access_token = args.fetch(:Authorization, nil)
20
21
  if basic_auth
@@ -14,18 +14,11 @@ module AgileNotifier
14
14
  def self.get_value(key, url)
15
15
  get_value_of_key(key, url.gsub(/\/$/, '') + JSON_API)
16
16
  end
17
-
18
- def initialize(url, *names)
17
+
18
+ def initialize(url, job_name, build_number = nil)
19
19
  @url = url
20
- if names.empty?
21
- @jobs = get_all_jobs
22
- else
23
- @jobs = []
24
- names.each do |name|
25
- job_url = URI.encode("#{@url}/job/#{name}/")
26
- @jobs.push(Job.new(name, job_url))
27
- end
28
- end
20
+ job_url = URI.encode("#{@url}/job/#{job_name}/")
21
+ @job = Job.new(job_name, job_url, build_number)
29
22
  end
30
23
 
31
24
  def get_all_jobs
@@ -40,17 +33,21 @@ module AgileNotifier
40
33
  end
41
34
 
42
35
  class Job < CI::Job
36
+ def get_specific_build(build_number)
37
+ Build.new(build_number, @url + build_number.to_s + '/')
38
+ end
39
+
43
40
  def get_last_build
44
41
  last_build = Jenkins.get_value('lastBuild', @url)
45
42
  last_build.nil? ? nil : Build.new(last_build['number'], last_build['url'])
46
43
  end
47
44
 
48
- def get_penultimate_build
49
- last_build.get_previous_build
50
- end
51
-
52
45
  class Build < CI::Job::Build
53
46
  include Servable
47
+
48
+ def is_building?
49
+ Jenkins.get_value('building', @url)
50
+ end
54
51
 
55
52
  def get_result
56
53
  result = Jenkins.get_value('result', @url)
@@ -30,6 +30,9 @@ module AgileNotifier
30
30
  def on_condition(condition, text, args)
31
31
  if condition
32
32
  TTS.speak(text, args)
33
+ puts '=' * 70
34
+ puts text
35
+ puts '=' * 70
33
36
  true
34
37
  else
35
38
  false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agile_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jing Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-01 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -87,6 +87,7 @@ files:
87
87
  - agile_notifier.gemspec
88
88
  - lib/agile_notifier.rb
89
89
  - lib/agile_notifier/ci.rb
90
+ - lib/agile_notifier/commander.rb
90
91
  - lib/agile_notifier/composer.rb
91
92
  - lib/agile_notifier/configuration.rb
92
93
  - lib/agile_notifier/git.rb