hookers 0.2.1 → 0.3.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.
data/.gitignore CHANGED
@@ -2,3 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ *.swp
6
+ *.swo
data/hookers.gemspec CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage = ""
11
11
  s.summary = "Git hooks and change logs"
12
12
  s.description = "Contains default hooks files to integrate git with pivotal tracker and change log generator"
13
+ s.add_dependency "activesupport"
13
14
 
14
15
  s.rubyforge_project = "hookers"
15
16
 
@@ -3,33 +3,15 @@
3
3
  module Hookers
4
4
  module Changelog
5
5
  class Affects
6
- attr_accessor :commit, :type, :number
7
6
 
8
- def bug?
9
- self.type == "BUG"
10
- end
11
-
12
- def feature?
13
- self.type == "FEATURE"
14
- end
15
-
16
- def type=(value)
17
- @type = (value == "BUG" ? "BUG" : "FEATURE")
18
- end
19
-
20
- def identifier
21
- "#{type} ##{number}"
22
- end
23
-
24
- def uri
25
- return "http://bugzilla-qa.linux.locaweb.com.br/show_bug.cgi?id=#{self.number}" if bug?
26
- return "http://pivotaltracker.com/story/show/#{self.number}" if feature?
27
- end
7
+ attr_accessor :commit, :type, :number, :uri, :identifier
28
8
 
29
- def initialize(commit, type, number)
9
+ def initialize(commit, type, number, uri, identifier)
30
10
  self.commit = commit
31
11
  self.type = type
32
12
  self.number = number
13
+ self.uri = uri
14
+ self.identifier = identifier
33
15
  end
34
16
  end
35
17
  end
@@ -0,0 +1,102 @@
1
+ # encoding: utf-8
2
+
3
+ module Hookers
4
+ module Changelog
5
+ module Matchers
6
+ class Matcher
7
+ attr_accessor :number, :commit, :type
8
+ SUBPATTERN = /(?:\s+\#\s*(\d+))/
9
+
10
+ def self.scan(commit)
11
+ []
12
+ end
13
+
14
+ def identifier
15
+ "#{type} ##{number}"
16
+ end
17
+
18
+ def initialize(commit, type, number)
19
+ self.commit = commit
20
+ self.type = type
21
+ self.number = number
22
+ end
23
+
24
+ def uri
25
+ nil
26
+ end
27
+
28
+ def type
29
+ @type.upcase if @type
30
+ end
31
+
32
+ def to_affected
33
+ Hookers::Changelog::Affects.new(commit, type, number, uri, identifier)
34
+ end
35
+
36
+ def self.blocks_of(commit, regexp, subpattern = nil)
37
+ results = []
38
+
39
+ commit.message.scan(/(\[(?:#{regexp}\s*)+\])/i).each do |e|
40
+ if subpattern
41
+ results += e[2].scan(subpattern).map { |sub| [e[1], sub[0]] }
42
+ else
43
+ results << e.slice(1..2)
44
+ end
45
+ end
46
+
47
+ results
48
+ end
49
+ end
50
+
51
+ class ServiceNowMatcher < Matcher
52
+ def self.scan(commit)
53
+ blocks_of(commit, /(INC|PRB|TICKET|CHG)(\d+)/).map { |e| new(commit, *e) }
54
+ end
55
+
56
+ def uri
57
+ uris = {"chg" => "change_request_list", "inc" => "incident_list", "prb" => "problem_list"}
58
+
59
+ "https://lwprod.service-now.com/nav_to.do?uri=#{uris.fetch(@type.to_s.downcase)}.do?sysparm_query=number%3D#{identifier}"
60
+ end
61
+
62
+ def type
63
+ {"chg" => "CHANGE"}.fetch(@type.to_s.downcase, @type.to_s)
64
+ end
65
+
66
+ def identifier
67
+ "#{@type}#{number}"
68
+ end
69
+ end
70
+
71
+ class BugzillaMatcher < Matcher
72
+ REGEXP = /(bug)((?:\s+#\s*\d+){1,})/i
73
+ SUBPATTERN = /(?:\s+\#\s*(\d+))/
74
+
75
+ def self.scan(commit)
76
+ blocks_of(commit, REGEXP, SUBPATTERN).map { |e| new(commit, *e) }
77
+ end
78
+
79
+ def uri
80
+ "http://bugzilla-qa.linux.locaweb.com.br/show_bug.cgi?id=#{number}"
81
+ end
82
+ end
83
+
84
+ class PivotalTrackerMatcher < Matcher
85
+ REGEXP = /(feature|story|fixed|fixes|completed|finished|delivers)((?:\s+#\s*\d+){1,})/i
86
+ SUBPATTERN = /(?:\s+\#\s*(\d+))/
87
+
88
+ def self.scan(commit)
89
+ blocks_of(commit, REGEXP, SUBPATTERN).map { |e| new(commit, *e) }
90
+ end
91
+
92
+ def type
93
+ "FEATURE"
94
+ end
95
+
96
+ def uri
97
+ "http://pivotaltracker.com/story/show/#{self.number}"
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,29 +1,30 @@
1
1
  # encoding: UTF-8
2
2
 
3
+ require "hookers/changelog/matchers"
4
+
3
5
  module Hookers
4
6
  module Changelog
5
7
  class Parser
6
- attr_accessor :project, :message
8
+ MATCHERS = [:service_now, :bugzilla, :pivotal_tracker]
7
9
 
8
- REGEXP = /\[(bug|feature|story|fixed|fixes|completed|finished|delivers)((?:\s+#\s*\d+){1,})\]/i
9
- SUBPATTERN = /(?:\s+\#\s*(\d+))/
10
+ attr_accessor :project, :message
10
11
 
11
12
  def initialize(project)
12
13
  self.project = project
13
14
  end
14
15
 
16
+ def get_matcher(name)
17
+ Hookers::Changelog::Matchers.const_get(
18
+ "#{name.to_s.capitalize.gsub(/(_.)/) { |e| e[1].upcase }}Matcher")
19
+ end
20
+
15
21
  def parse(line)
16
22
  id, message = line.split(" ", 2)
17
- data = message.scan(Parser::REGEXP)
18
23
  affects = []
19
24
  commit = Commit.new(project, id, message)
20
25
 
21
- if !data.nil?
22
- data.each do |type, identifiers|
23
- identifiers.scan(Parser::SUBPATTERN).flatten.each do |number|
24
- affects << Affects.new(commit, type.upcase, number)
25
- end
26
- end
26
+ matchers = MATCHERS.each do |m|
27
+ affects += get_matcher(m).scan(commit).map(&:to_affected)
27
28
  end
28
29
 
29
30
  affects
@@ -1,3 +1,3 @@
1
1
  module Hookers
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hookers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-16 00:00:00.000000000 Z
13
+ date: 2013-08-01 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
15
31
  - !ruby/object:Gem::Dependency
16
32
  name: slop
17
33
  requirement: !ruby/object:Gem::Requirement
@@ -83,6 +99,7 @@ files:
83
99
  - lib/hookers/changelog/changelogger.rb
84
100
  - lib/hookers/changelog/commit.rb
85
101
  - lib/hookers/changelog/history.rb
102
+ - lib/hookers/changelog/matchers.rb
86
103
  - lib/hookers/changelog/parser.rb
87
104
  - lib/hookers/changelog/project.rb
88
105
  - lib/hookers/command.rb
@@ -113,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
130
  version: '0'
114
131
  segments:
115
132
  - 0
116
- hash: 3970638991331036522
133
+ hash: 1489418900126096037
117
134
  required_rubygems_version: !ruby/object:Gem::Requirement
118
135
  none: false
119
136
  requirements:
@@ -122,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
139
  version: '0'
123
140
  segments:
124
141
  - 0
125
- hash: 3970638991331036522
142
+ hash: 1489418900126096037
126
143
  requirements: []
127
144
  rubyforge_project: hookers
128
145
  rubygems_version: 1.8.23