ping 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d4873e809919a2dbae3e2ba7f759413002d7fc1
4
- data.tar.gz: 6ec66bdfb0f99f3c7ead5a27aea970774e4219f3
3
+ metadata.gz: c17318b1d30362336aaf21ca89ab8cd282b9058d
4
+ data.tar.gz: 605954bbe04c04076ccb996c9f3c4f4f0548c984
5
5
  SHA512:
6
- metadata.gz: d459bf0d42d17e01400201fd9a56443ab0b2d5831377479a313b0152623eaac4e6af1cab3ce403fb782b5b7bac4238fcd12760aa627cb78d6a6316b421bb7d80
7
- data.tar.gz: 20a8203520a10bf9be20a97c1c0b6571aebfb4c0fd2cc55a90e181d7eb5fca3578f92e71a441fe56a4b3983ec6e566758d87c808f6c9f3da1c43b82995deb70a
6
+ metadata.gz: 30b5f2cfcaa7d9daac0190094de884ba82f2212598c5d07bd6f1ba48a9c4edb3c36b8455803617309a980d659bd9b045a128e6a4548b27c9d5a621d69e762fd9
7
+ data.tar.gz: 7e8b2b9fc768e4234bcb058b8c4f9f0f5ff4e3918a895de92e484d859a068458e12a636afe23d2eee31a271084852ef8d037f20076aa768491e6c059d2df8329
@@ -1,6 +1,6 @@
1
1
  module Ping
2
- class Issue
3
- attr_reader :qualifier, :repository, :number
2
+ class IssueReference
3
+ attr_accessor :qualifier, :repository, :number
4
4
 
5
5
  Qualifiers = /
6
6
  close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved|
@@ -36,6 +36,21 @@ module Ping
36
36
  end
37
37
  end
38
38
 
39
+ def self.replace(text, &block)
40
+ text.gsub(Pattern) do |phrase|
41
+ replacement = yield(phrase, self.new(*phrase.scan(Pattern).first))
42
+
43
+ if replacement.is_a?(IssueReference)
44
+ new_phrase = phrase[0] == " " ? " " : "" # fix leading space
45
+ new_phrase << replacement.qualifier + " " if replacement.qualifier
46
+ new_phrase << replacement.repository.to_s
47
+ new_phrase << "#" + replacement.number.to_s
48
+ else
49
+ replacement
50
+ end
51
+ end
52
+ end
53
+
39
54
  def ==(other)
40
55
  other.to_i == to_i
41
56
  end
data/lib/ping/mention.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Ping
2
2
  class Mention
3
- attr_reader :username
3
+ attr_accessor :username
4
4
 
5
5
  Pattern = /
6
6
  (?:^|\W) # beginning of string or non-word char
data/lib/ping/parser.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "ping/mention"
2
- require "ping/issue"
2
+ require "ping/issue_reference"
3
3
 
4
4
  module Ping
5
5
  class Parser
@@ -13,8 +13,12 @@ module Ping
13
13
  Ping::Mention.extract(text)
14
14
  end
15
15
 
16
- def issues
17
- Ping::Issue.extract(text)
16
+ def issue_references
17
+ Ping::IssueReference.extract(text)
18
+ end
19
+
20
+ def replace_issue_references(&block)
21
+ Ping::IssueReference.replace(text, &block)
18
22
  end
19
23
  end
20
24
  end
data/lib/ping/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ping
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class Ping::IssueReferenceTest < MiniTest::Test
4
+ context "#==" do
5
+ should "compare with integers" do
6
+ issue = Ping::IssueReference.new("fixes", "codetree/codetree", "123")
7
+ assert issue == 123
8
+ end
9
+
10
+ should "compare with strings" do
11
+ issue = Ping::IssueReference.new("fixes", "codetree/codetree", "123")
12
+ assert issue == "123"
13
+ end
14
+
15
+ should "compare with issues" do
16
+ issue = Ping::IssueReference.new("fixes", "codetree/codetree", "123")
17
+ assert issue == Ping::IssueReference.new(nil, "codetree/codetree", "123")
18
+ end
19
+ end
20
+
21
+ context "#to_s" do
22
+ should "return the issue number" do
23
+ issue = Ping::IssueReference.new("Fixes", "codetree/codetree", "123")
24
+ assert_equal "123", issue.to_s
25
+ end
26
+ end
27
+
28
+ context "#to_i" do
29
+ should "return the integer issue number" do
30
+ issue = Ping::IssueReference.new("Fixes", "codetree/codetree", "123")
31
+ assert_equal 123, issue.to_i
32
+ end
33
+ end
34
+ end
@@ -16,11 +16,11 @@ class Ping::ParserTest < MiniTest::Test
16
16
  end
17
17
  end
18
18
 
19
- context "#issues" do
19
+ context "#issue_references with standard syntax" do
20
20
  should "extract single issue references" do
21
21
  text = "See #43"
22
22
  parser = Ping::Parser.new(text)
23
- issue = parser.issues.first
23
+ issue = parser.issue_references.first
24
24
 
25
25
  assert_equal nil, issue.qualifier
26
26
  assert_equal nil, issue.repository
@@ -30,7 +30,7 @@ class Ping::ParserTest < MiniTest::Test
30
30
  should "extract single issue references followed by a period" do
31
31
  text = "See #43."
32
32
  parser = Ping::Parser.new(text)
33
- issue = parser.issues.first
33
+ issue = parser.issue_references.first
34
34
 
35
35
  assert_equal nil, issue.qualifier
36
36
  assert_equal nil, issue.repository
@@ -41,7 +41,7 @@ class Ping::ParserTest < MiniTest::Test
41
41
  %w{fix fixes fixed close closes closed resolve resolves resolved}.each do |q|
42
42
  text = "#{q} #55"
43
43
  parser = Ping::Parser.new(text)
44
- issue = parser.issues.first
44
+ issue = parser.issue_references.first
45
45
 
46
46
  assert_equal q, issue.qualifier
47
47
  assert_equal nil, issue.repository
@@ -53,7 +53,7 @@ class Ping::ParserTest < MiniTest::Test
53
53
  %w{need needs needed require requires required}.each do |q|
54
54
  text = "#{q} #123"
55
55
  parser = Ping::Parser.new(text)
56
- issue = parser.issues.first
56
+ issue = parser.issue_references.first
57
57
 
58
58
  assert_equal q, issue.qualifier
59
59
  assert_equal nil, issue.repository
@@ -64,7 +64,7 @@ class Ping::ParserTest < MiniTest::Test
64
64
  should "extract repository" do
65
65
  text = "codetree/codetree#43"
66
66
  parser = Ping::Parser.new(text)
67
- issue = parser.issues.first
67
+ issue = parser.issue_references.first
68
68
 
69
69
  assert_equal nil, issue.qualifier
70
70
  assert_equal "codetree/codetree", issue.repository
@@ -74,7 +74,7 @@ class Ping::ParserTest < MiniTest::Test
74
74
  should "extract repository with qualifier" do
75
75
  text = "Fixes codetree/codetree#43"
76
76
  parser = Ping::Parser.new(text)
77
- issue = parser.issues.first
77
+ issue = parser.issue_references.first
78
78
 
79
79
  assert_equal "Fixes", issue.qualifier
80
80
  assert_equal "codetree/codetree", issue.repository
@@ -84,7 +84,7 @@ class Ping::ParserTest < MiniTest::Test
84
84
  should "handle odd repository names" do
85
85
  text = "giant-sequoia-123/scaling_octokitten#43"
86
86
  parser = Ping::Parser.new(text)
87
- issue = parser.issues.first
87
+ issue = parser.issue_references.first
88
88
 
89
89
  assert_equal "giant-sequoia-123/scaling_octokitten", issue.repository
90
90
  assert_equal "43", issue.number
@@ -94,16 +94,16 @@ class Ping::ParserTest < MiniTest::Test
94
94
  text = "You should look at #2 and #4 because #5 fixes codetree/codetree#6"
95
95
  parser = Ping::Parser.new(text)
96
96
 
97
- assert parser.issues.include?(2)
98
- assert parser.issues.include?(4)
99
- assert parser.issues.include?(5)
100
- assert parser.issues.include?(6)
97
+ assert parser.issue_references.include?(2)
98
+ assert parser.issue_references.include?(4)
99
+ assert parser.issue_references.include?(5)
100
+ assert parser.issue_references.include?(6)
101
101
  end
102
102
 
103
103
  should "not extract similar non-qualifiers" do
104
104
  text = "afixes #43"
105
105
  parser = Ping::Parser.new(text)
106
- issue = parser.issues.first
106
+ issue = parser.issue_references.first
107
107
 
108
108
  assert_equal nil, issue.qualifier
109
109
  assert_equal nil, issue.repository
@@ -113,7 +113,7 @@ class Ping::ParserTest < MiniTest::Test
113
113
  should "not choke on case" do
114
114
  text = "FIxEs #43"
115
115
  parser = Ping::Parser.new(text)
116
- issue = parser.issues.first
116
+ issue = parser.issue_references.first
117
117
 
118
118
  assert_equal "FIxEs", issue.qualifier
119
119
  assert_equal nil, issue.repository
@@ -123,7 +123,7 @@ class Ping::ParserTest < MiniTest::Test
123
123
  should "require one space between qualifier and issue" do
124
124
  text = "fixes #43"
125
125
  parser = Ping::Parser.new(text)
126
- issue = parser.issues.first
126
+ issue = parser.issue_references.first
127
127
 
128
128
  assert_equal nil, issue.qualifier
129
129
  assert_equal nil, issue.repository
@@ -131,11 +131,11 @@ class Ping::ParserTest < MiniTest::Test
131
131
  end
132
132
  end
133
133
 
134
- context "GH-issues" do
134
+ context "#issue_references with GH-XXX syntax" do
135
135
  should "extract single issue references" do
136
136
  text = "See GH-43"
137
137
  parser = Ping::Parser.new(text)
138
- issue = parser.issues.first
138
+ issue = parser.issue_references.first
139
139
 
140
140
  assert_equal nil, issue.qualifier
141
141
  assert_equal nil, issue.repository
@@ -145,7 +145,7 @@ class Ping::ParserTest < MiniTest::Test
145
145
  should "extract lower case issue references" do
146
146
  text = "See gh-43"
147
147
  parser = Ping::Parser.new(text)
148
- issue = parser.issues.first
148
+ issue = parser.issue_references.first
149
149
 
150
150
  assert_equal nil, issue.qualifier
151
151
  assert_equal nil, issue.repository
@@ -155,7 +155,7 @@ class Ping::ParserTest < MiniTest::Test
155
155
  should "extract single issue references followed by a period" do
156
156
  text = "See GH-43."
157
157
  parser = Ping::Parser.new(text)
158
- issue = parser.issues.first
158
+ issue = parser.issue_references.first
159
159
 
160
160
  assert_equal nil, issue.qualifier
161
161
  assert_equal nil, issue.repository
@@ -166,7 +166,7 @@ class Ping::ParserTest < MiniTest::Test
166
166
  %w{fix fixes fixed close closes closed resolve resolves resolved}.each do |q|
167
167
  text = "#{q} GH-55"
168
168
  parser = Ping::Parser.new(text)
169
- issue = parser.issues.first
169
+ issue = parser.issue_references.first
170
170
 
171
171
  assert_equal q, issue.qualifier
172
172
  assert_equal nil, issue.repository
@@ -178,7 +178,7 @@ class Ping::ParserTest < MiniTest::Test
178
178
  %w{need needs needed require requires required}.each do |q|
179
179
  text = "#{q} GH-123"
180
180
  parser = Ping::Parser.new(text)
181
- issue = parser.issues.first
181
+ issue = parser.issue_references.first
182
182
 
183
183
  assert_equal q, issue.qualifier
184
184
  assert_equal nil, issue.repository
@@ -190,16 +190,16 @@ class Ping::ParserTest < MiniTest::Test
190
190
  text = "You should look at GH-2 and GH-4 because GH-5 fixes codetree/codetree#6"
191
191
  parser = Ping::Parser.new(text)
192
192
 
193
- assert parser.issues.include?(2)
194
- assert parser.issues.include?(4)
195
- assert parser.issues.include?(5)
196
- assert parser.issues.include?(6)
193
+ assert parser.issue_references.include?(2)
194
+ assert parser.issue_references.include?(4)
195
+ assert parser.issue_references.include?(5)
196
+ assert parser.issue_references.include?(6)
197
197
  end
198
198
 
199
199
  should "not extract similar non-qualifiers" do
200
200
  text = "afixes GH-43"
201
201
  parser = Ping::Parser.new(text)
202
- issue = parser.issues.first
202
+ issue = parser.issue_references.first
203
203
 
204
204
  assert_equal nil, issue.qualifier
205
205
  assert_equal nil, issue.repository
@@ -209,7 +209,7 @@ class Ping::ParserTest < MiniTest::Test
209
209
  should "not choke on case" do
210
210
  text = "FIxEs GH-43"
211
211
  parser = Ping::Parser.new(text)
212
- issue = parser.issues.first
212
+ issue = parser.issue_references.first
213
213
 
214
214
  assert_equal "FIxEs", issue.qualifier
215
215
  assert_equal nil, issue.repository
@@ -219,7 +219,7 @@ class Ping::ParserTest < MiniTest::Test
219
219
  should "require only one space between qualifier and issue" do
220
220
  text = "fixes GH-43"
221
221
  parser = Ping::Parser.new(text)
222
- issue = parser.issues.first
222
+ issue = parser.issue_references.first
223
223
 
224
224
  assert_equal nil, issue.qualifier
225
225
  assert_equal nil, issue.repository
@@ -229,11 +229,100 @@ class Ping::ParserTest < MiniTest::Test
229
229
  should "require at least one space before GH" do
230
230
  text = "fixes codetree/codetreeGH-99 and fixes GH-43"
231
231
  parser = Ping::Parser.new(text)
232
- issue = parser.issues.first
232
+ issue = parser.issue_references.first
233
233
 
234
234
  assert_equal "fixes", issue.qualifier
235
235
  assert_equal nil, issue.repository
236
236
  assert_equal "43", issue.number
237
237
  end
238
238
  end
239
+
240
+ context "#replace_issue_references" do
241
+ should "yield the phrase and parsed reference" do
242
+ text = "Fixes codetree/codetree#123 needs codetree/feedback#456"
243
+ parser = Ping::Parser.new(text)
244
+
245
+ expected = [
246
+ "Fixes codetree/codetree#123",
247
+ " needs codetree/feedback#456"
248
+ ]
249
+
250
+ parser.replace_issue_references do |phrase, reference|
251
+ expected_phrase = expected.shift
252
+ expected_reference = Ping::Parser.new(expected_phrase).issue_references.first
253
+
254
+ assert_equal expected_phrase, phrase
255
+ assert_equal expected_reference, reference
256
+ end
257
+ end
258
+
259
+ context "given a IssueReference replacement" do
260
+ should "handle qualifier + repo + number" do
261
+ text = "Fixes a/b#123 fixes #456"
262
+ parser = Ping::Parser.new(text)
263
+
264
+ result = parser.replace_issue_references do |phrase, reference|
265
+ reference.tap do |r|
266
+ r.repository = "codetree/feedback" unless r.repository
267
+ end
268
+ end
269
+
270
+ assert_equal "Fixes a/b#123 fixes codetree/feedback#456", result
271
+ end
272
+
273
+ should "handle qualifier + number" do
274
+ text = "Fixes #123 fixes #456"
275
+ parser = Ping::Parser.new(text)
276
+
277
+ result = parser.replace_issue_references do |phrase, reference|
278
+ reference.tap do |r|
279
+ r.qualifier = "needs"
280
+ r.repository = "a/b"
281
+ end
282
+ end
283
+
284
+ assert_equal "needs a/b#123 needs a/b#456", result
285
+ end
286
+
287
+ should "handle repo + number" do
288
+ text = "a/b#123 b/c#456"
289
+ parser = Ping::Parser.new(text)
290
+
291
+ result = parser.replace_issue_references do |phrase, reference|
292
+ reference.tap do |r|
293
+ r.qualifier = "needs"
294
+ r.repository = "d/e"
295
+ end
296
+ end
297
+
298
+ assert_equal "needs d/e#123 needs d/e#456", result
299
+ end
300
+
301
+ should "handle number only" do
302
+ text = "#123 #456"
303
+ parser = Ping::Parser.new(text)
304
+
305
+ result = parser.replace_issue_references do |phrase, reference|
306
+ reference.tap do |r|
307
+ r.repository = "d/e"
308
+ end
309
+ end
310
+
311
+ assert_equal "d/e#123 d/e#456", result
312
+ end
313
+ end
314
+
315
+ context "given a string replacement" do
316
+ should "replace references" do
317
+ text = "Fixes a/b#123 fixes #456"
318
+ parser = Ping::Parser.new(text)
319
+
320
+ result = parser.replace_issue_references do |phrase, reference|
321
+ phrase + " bar"
322
+ end
323
+
324
+ assert_equal "Fixes a/b#123 bar fixes #456 bar", result
325
+ end
326
+ end
327
+ end
239
328
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derrick Reimer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-21 00:00:00.000000000 Z
11
+ date: 2015-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,12 +93,12 @@ files:
93
93
  - README.md
94
94
  - Rakefile
95
95
  - lib/ping.rb
96
- - lib/ping/issue.rb
96
+ - lib/ping/issue_reference.rb
97
97
  - lib/ping/mention.rb
98
98
  - lib/ping/parser.rb
99
99
  - lib/ping/version.rb
100
100
  - ping.gemspec
101
- - test/ping/issue_test.rb
101
+ - test/ping/issue_reference_test.rb
102
102
  - test/ping/mention_test.rb
103
103
  - test/ping/parser_test.rb
104
104
  - test/test_helper.rb
@@ -127,7 +127,7 @@ signing_key:
127
127
  specification_version: 4
128
128
  summary: Parse @mentions and issue references
129
129
  test_files:
130
- - test/ping/issue_test.rb
130
+ - test/ping/issue_reference_test.rb
131
131
  - test/ping/mention_test.rb
132
132
  - test/ping/parser_test.rb
133
133
  - test/test_helper.rb
@@ -1,34 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- class Ping::IssueTest < MiniTest::Test
4
- context "#==" do
5
- should "compare with integers" do
6
- issue = Ping::Issue.new("fixes", "codetree/codetree", "123")
7
- assert issue == 123
8
- end
9
-
10
- should "compare with strings" do
11
- issue = Ping::Issue.new("fixes", "codetree/codetree", "123")
12
- assert issue == "123"
13
- end
14
-
15
- should "compare with issues" do
16
- issue = Ping::Issue.new("fixes", "codetree/codetree", "123")
17
- assert issue == Ping::Issue.new(nil, "codetree/codetree", "123")
18
- end
19
- end
20
-
21
- context "#to_s" do
22
- should "return the issue number" do
23
- issue = Ping::Issue.new("Fixes", "codetree/codetree", "123")
24
- assert_equal "123", issue.to_s
25
- end
26
- end
27
-
28
- context "#to_i" do
29
- should "return the integer issue number" do
30
- issue = Ping::Issue.new("Fixes", "codetree/codetree", "123")
31
- assert_equal 123, issue.to_i
32
- end
33
- end
34
- end