ping 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +29 -0
- data/Rakefile +14 -6
- data/circle.yml +3 -0
- data/lib/ping.rb +2 -2
- data/lib/ping/issue_reference.rb +57 -18
- data/lib/ping/mention.rb +4 -4
- data/lib/ping/parser.rb +2 -7
- data/lib/ping/version.rb +1 -1
- data/ping.gemspec +16 -15
- data/test/ping/issue_reference_test.rb +409 -16
- data/test/ping/mention_test.rb +34 -11
- data/test/ping/parser_test.rb +0 -354
- data/test/test_helper.rb +5 -5
- metadata +19 -5
- data/lib/ping/size.rb +0 -40
- data/test/ping/size_test.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53bcca036a31b4ffcaeab4ea6ac4c1a645dba51b
|
4
|
+
data.tar.gz: ae2324d2655747a23f261fa733f91a79651f9611
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c20cdfbb8bc258e14d51213f0fedb1bdf357e72b4ae3f36a44d8efadc8d26bb1957c42c7f00e825971529906767e4101e7f27978ce781e25954459e64a509217
|
7
|
+
data.tar.gz: 05464ba9e01249d5c89d90360c7f2413f369a7bd8f4a5b4483d7f11e63fbeb125d6f0c26cd16eb0a39347230da6b02916f681a0417174da23dcc1e3522aa8522
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-08-01 15:11:49 -0700 using RuboCop version 0.32.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 1
|
9
|
+
# Configuration parameters: CountComments.
|
10
|
+
Metrics/ClassLength:
|
11
|
+
Max: 335
|
12
|
+
|
13
|
+
# Offense count: 7
|
14
|
+
# Configuration parameters: AllowURI, URISchemes.
|
15
|
+
Metrics/LineLength:
|
16
|
+
Max: 93
|
17
|
+
|
18
|
+
# Offense count: 4
|
19
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
20
|
+
Style/ClassAndModuleChildren:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
# Offense count: 9
|
24
|
+
Style/Documentation:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
# Offense count: 1
|
28
|
+
Style/OpMethod:
|
29
|
+
Enabled: false
|
data/Rakefile
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rake/testtask'
|
4
4
|
|
5
5
|
Rake::TestTask.new do |t|
|
6
|
-
t.libs <<
|
7
|
-
t.pattern =
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.pattern = 'test/**/*_test.rb'
|
8
8
|
t.verbose = true
|
9
9
|
end
|
10
10
|
|
11
|
-
desc
|
12
|
-
task :
|
11
|
+
desc 'Run tests'
|
12
|
+
task default: :test
|
13
|
+
|
14
|
+
# append to the default rake task
|
15
|
+
require 'rubocop/rake_task'
|
16
|
+
RuboCop::RakeTask.new
|
17
|
+
|
18
|
+
task :default do
|
19
|
+
Rake::Task['rubocop'].invoke
|
20
|
+
end
|
data/circle.yml
ADDED
data/lib/ping.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'ping/version'
|
2
|
+
require 'ping/parser'
|
data/lib/ping/issue_reference.rb
CHANGED
@@ -2,17 +2,26 @@ module Ping
|
|
2
2
|
class IssueReference
|
3
3
|
attr_accessor :qualifier, :repository, :number
|
4
4
|
|
5
|
-
|
5
|
+
QUALIFIERS = /
|
6
6
|
close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved|
|
7
7
|
need|needs|needed|require|requires|required
|
8
8
|
/ix
|
9
9
|
|
10
|
-
|
10
|
+
REPOSITORY_NAME = /[a-z0-9][a-z0-9\-]*\/[a-z0-9][a-z0-9\-_]*/ix
|
11
11
|
|
12
|
-
|
12
|
+
# Match references of the form:
|
13
|
+
#
|
14
|
+
# - #123
|
15
|
+
# - codetree/feedback#123
|
16
|
+
# - GH-123
|
17
|
+
# - needs #123
|
18
|
+
# - etc...
|
19
|
+
#
|
20
|
+
# See http://rubular.com/r/evB7RlvUfI
|
21
|
+
SHORT_PATTERN = /
|
13
22
|
(?:^|\W) # beginning of string or non-word char
|
14
|
-
(?:(#{
|
15
|
-
(?:(#{
|
23
|
+
(?:(#{QUALIFIERS})(?:\s))? # qualifier (optional)
|
24
|
+
(?:(#{REPOSITORY_NAME})? # repository name (optional)
|
16
25
|
\#|(?:GH\-))(\d+) # issue number
|
17
26
|
(?=
|
18
27
|
\.+[ \t\W]| # dots followed by space or non-word character
|
@@ -22,7 +31,26 @@ module Ping
|
|
22
31
|
)
|
23
32
|
/ix
|
24
33
|
|
25
|
-
#
|
34
|
+
# Match references of the form:
|
35
|
+
#
|
36
|
+
# - https://github.com/codetree/feedback/issues/123
|
37
|
+
# - https://github.com/codetree/feedback/pulls/123
|
38
|
+
# - needs https://github.com/codetree/feedback/issues/123
|
39
|
+
# - etc...
|
40
|
+
URL_PATTERN = /
|
41
|
+
(?:^|\W) # beginning of string or non-word char
|
42
|
+
(?:(#{QUALIFIERS})(?:\s))? # qualifier (optional)
|
43
|
+
https:\/\/github.com\/
|
44
|
+
(#{REPOSITORY_NAME}) # repository name
|
45
|
+
\/(?:issues|pulls)\/
|
46
|
+
(\d+) # issue number
|
47
|
+
(?=
|
48
|
+
\.+[ \t\W]| # dots followed by space or non-word character
|
49
|
+
\.+$| # dots at end of line
|
50
|
+
[^0-9a-zA-Z_.]| # non-word character except dot
|
51
|
+
$ # end of line
|
52
|
+
)
|
53
|
+
/ix
|
26
54
|
|
27
55
|
def initialize(qualifier, repository, number)
|
28
56
|
@qualifier = qualifier
|
@@ -31,24 +59,35 @@ module Ping
|
|
31
59
|
end
|
32
60
|
|
33
61
|
def self.extract(text)
|
34
|
-
|
35
|
-
|
62
|
+
[SHORT_PATTERN, URL_PATTERN].inject([]) do |memo, pattern|
|
63
|
+
memo.tap do |m|
|
64
|
+
text.scan(pattern).each do |match|
|
65
|
+
m << new(*match)
|
66
|
+
end
|
67
|
+
end
|
36
68
|
end
|
37
69
|
end
|
38
70
|
|
39
71
|
def self.replace(text, &block)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
72
|
+
[SHORT_PATTERN, URL_PATTERN].each do |pattern|
|
73
|
+
text = text.gsub(pattern) do |match|
|
74
|
+
ref = new(*match.scan(pattern).first)
|
75
|
+
replace_match(match, ref, &block)
|
50
76
|
end
|
51
77
|
end
|
78
|
+
|
79
|
+
text
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.replace_match(match, ref, &_block)
|
83
|
+
replacement = yield(match, ref)
|
84
|
+
return replacement unless replacement.is_a?(IssueReference)
|
85
|
+
|
86
|
+
# Reformat the given issue reference replacement to match
|
87
|
+
new_phrase = match[0] == ' ' ? ' ' : '' # fix leading space
|
88
|
+
new_phrase << replacement.qualifier + ' ' if replacement.qualifier
|
89
|
+
new_phrase << replacement.repository.to_s
|
90
|
+
new_phrase << '#' + replacement.number.to_s
|
52
91
|
end
|
53
92
|
|
54
93
|
def ==(other)
|
data/lib/ping/mention.rb
CHANGED
@@ -2,7 +2,7 @@ module Ping
|
|
2
2
|
class Mention
|
3
3
|
attr_accessor :username
|
4
4
|
|
5
|
-
|
5
|
+
PATTERN = /
|
6
6
|
(?:^|\W) # beginning of string or non-word char
|
7
7
|
@((?>[a-z0-9][a-z0-9-]*)) # @username
|
8
8
|
(?!\/) # without a trailing slash
|
@@ -19,9 +19,9 @@ module Ping
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.extract(text)
|
22
|
-
text.scan(
|
23
|
-
map(&:downcase).uniq.map do |username|
|
24
|
-
|
22
|
+
text.scan(PATTERN).flatten
|
23
|
+
.map(&:downcase).uniq.map do |username|
|
24
|
+
new(username)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
data/lib/ping/parser.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require "ping/size"
|
1
|
+
require 'ping/mention'
|
2
|
+
require 'ping/issue_reference'
|
4
3
|
|
5
4
|
module Ping
|
6
5
|
class Parser
|
@@ -21,9 +20,5 @@ module Ping
|
|
21
20
|
def replace_issue_references(&block)
|
22
21
|
Ping::IssueReference.replace(text, &block)
|
23
22
|
end
|
24
|
-
|
25
|
-
def size
|
26
|
-
Ping::Size.extract(text)
|
27
|
-
end
|
28
23
|
end
|
29
24
|
end
|
data/lib/ping/version.rb
CHANGED
data/ping.gemspec
CHANGED
@@ -4,23 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'ping/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'ping'
|
8
8
|
spec.version = Ping::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Derrick Reimer']
|
10
|
+
spec.email = ['derrickreimer@gmail.com']
|
11
|
+
spec.summary = 'Parse @mentions and issue references'
|
12
|
+
spec.description = 'A little library for parsing GitHub @mentions and issue references'
|
13
|
+
spec.homepage = 'https://github.com/codetree/ping'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(
|
18
|
-
spec.test_files = spec.files.grep(
|
19
|
-
spec.require_paths = [
|
17
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
24
|
+
spec.add_development_dependency 'shoulda-context', '~> 1.2'
|
25
|
+
spec.add_development_dependency 'mocha', '~> 1.0'
|
26
|
+
spec.add_development_dependency 'rubocop'
|
26
27
|
end
|
@@ -1,33 +1,426 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
2
|
|
3
3
|
class Ping::IssueReferenceTest < MiniTest::Test
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def extract(text)
|
5
|
+
Ping::IssueReference.extract(text)
|
6
|
+
end
|
7
|
+
|
8
|
+
def extract_first(text)
|
9
|
+
Ping::IssueReference.extract(text).first
|
10
|
+
end
|
11
|
+
|
12
|
+
context '.extract with standard syntax' do
|
13
|
+
should 'extract single issue references' do
|
14
|
+
text = 'See #43'
|
15
|
+
issue = extract_first(text)
|
16
|
+
|
17
|
+
assert_equal nil, issue.qualifier
|
18
|
+
assert_equal nil, issue.repository
|
19
|
+
assert_equal '43', issue.number
|
20
|
+
end
|
21
|
+
|
22
|
+
should 'extract single issue references followed by a period' do
|
23
|
+
text = 'See #43.'
|
24
|
+
issue = extract_first(text)
|
25
|
+
|
26
|
+
assert_equal nil, issue.qualifier
|
27
|
+
assert_equal nil, issue.repository
|
28
|
+
assert_equal '43', issue.number
|
29
|
+
end
|
30
|
+
|
31
|
+
should 'extract close qualifiers' do
|
32
|
+
%w(fix fixes fixed close closes closed resolve resolves resolved).each do |q|
|
33
|
+
text = "#{q} #55"
|
34
|
+
issue = extract_first(text)
|
35
|
+
|
36
|
+
assert_equal q, issue.qualifier
|
37
|
+
assert_equal nil, issue.repository
|
38
|
+
assert_equal '55', issue.number
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
should 'extract dependency qualifiers' do
|
43
|
+
%w(need needs needed require requires required).each do |q|
|
44
|
+
text = "#{q} #123"
|
45
|
+
issue = extract_first(text)
|
46
|
+
|
47
|
+
assert_equal q, issue.qualifier
|
48
|
+
assert_equal nil, issue.repository
|
49
|
+
assert_equal '123', issue.number
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
should 'extract repository' do
|
54
|
+
text = 'codetree/codetree#43'
|
55
|
+
issue = extract_first(text)
|
56
|
+
|
57
|
+
assert_equal nil, issue.qualifier
|
58
|
+
assert_equal 'codetree/codetree', issue.repository
|
59
|
+
assert_equal '43', issue.number
|
60
|
+
end
|
61
|
+
|
62
|
+
should 'extract repository with qualifier' do
|
63
|
+
text = 'Fixes codetree/codetree#43'
|
64
|
+
issue = extract_first(text)
|
65
|
+
|
66
|
+
assert_equal 'Fixes', issue.qualifier
|
67
|
+
assert_equal 'codetree/codetree', issue.repository
|
68
|
+
assert_equal '43', issue.number
|
69
|
+
end
|
70
|
+
|
71
|
+
should 'handle odd repository names' do
|
72
|
+
text = 'giant-sequoia-123/scaling_octokitten#43'
|
73
|
+
issue = extract_first(text)
|
74
|
+
|
75
|
+
assert_equal 'giant-sequoia-123/scaling_octokitten', issue.repository
|
76
|
+
assert_equal '43', issue.number
|
77
|
+
end
|
78
|
+
|
79
|
+
should 'extract multiple references' do
|
80
|
+
text = 'You should look at #2 and #4 because #5 fixes codetree/codetree#6'
|
81
|
+
refs = extract(text)
|
82
|
+
|
83
|
+
assert refs.include?(2)
|
84
|
+
assert refs.include?(4)
|
85
|
+
assert refs.include?(5)
|
86
|
+
assert refs.include?(6)
|
87
|
+
end
|
88
|
+
|
89
|
+
should 'not extract similar non-qualifiers' do
|
90
|
+
text = 'afixes #43'
|
91
|
+
issue = extract_first(text)
|
92
|
+
|
93
|
+
assert_equal nil, issue.qualifier
|
94
|
+
assert_equal nil, issue.repository
|
95
|
+
assert_equal '43', issue.number
|
96
|
+
end
|
97
|
+
|
98
|
+
should 'not choke on case' do
|
99
|
+
text = 'FIxEs #43'
|
100
|
+
issue = extract_first(text)
|
101
|
+
|
102
|
+
assert_equal 'FIxEs', issue.qualifier
|
103
|
+
assert_equal nil, issue.repository
|
104
|
+
assert_equal '43', issue.number
|
105
|
+
end
|
106
|
+
|
107
|
+
should 'require one space between qualifier and issue' do
|
108
|
+
text = 'fixes #43'
|
109
|
+
issue = extract_first(text)
|
110
|
+
|
111
|
+
assert_equal nil, issue.qualifier
|
112
|
+
assert_equal nil, issue.repository
|
113
|
+
assert_equal '43', issue.number
|
114
|
+
end
|
115
|
+
|
116
|
+
should 'handle variable casing in repo names' do
|
117
|
+
text = 'needs Liquid-Labs/rf-app-admin-web-app#2'
|
118
|
+
issue = extract_first(text)
|
119
|
+
|
120
|
+
assert_equal 'needs', issue.qualifier
|
121
|
+
assert_equal 'Liquid-Labs/rf-app-admin-web-app', issue.repository
|
122
|
+
assert_equal '2', issue.number
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context '.extract with GH-XXX syntax' do
|
127
|
+
should 'extract single issue references' do
|
128
|
+
text = 'See GH-43'
|
129
|
+
issue = extract_first(text)
|
130
|
+
|
131
|
+
assert_equal nil, issue.qualifier
|
132
|
+
assert_equal nil, issue.repository
|
133
|
+
assert_equal '43', issue.number
|
134
|
+
end
|
135
|
+
|
136
|
+
should 'extract lower case issue references' do
|
137
|
+
text = 'See gh-43'
|
138
|
+
issue = extract_first(text)
|
139
|
+
|
140
|
+
assert_equal nil, issue.qualifier
|
141
|
+
assert_equal nil, issue.repository
|
142
|
+
assert_equal '43', issue.number
|
143
|
+
end
|
144
|
+
|
145
|
+
should 'extract single issue references followed by a period' do
|
146
|
+
text = 'See GH-43.'
|
147
|
+
issue = extract_first(text)
|
148
|
+
|
149
|
+
assert_equal nil, issue.qualifier
|
150
|
+
assert_equal nil, issue.repository
|
151
|
+
assert_equal '43', issue.number
|
152
|
+
end
|
153
|
+
|
154
|
+
should 'extract close qualifiers' do
|
155
|
+
%w(fix fixes fixed close closes closed resolve resolves resolved).each do |q|
|
156
|
+
text = "#{q} GH-55"
|
157
|
+
issue = extract_first(text)
|
158
|
+
|
159
|
+
assert_equal q, issue.qualifier
|
160
|
+
assert_equal nil, issue.repository
|
161
|
+
assert_equal '55', issue.number
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
should 'extract dependency qualifiers' do
|
166
|
+
%w(need needs needed require requires required).each do |q|
|
167
|
+
text = "#{q} GH-123"
|
168
|
+
issue = extract_first(text)
|
169
|
+
|
170
|
+
assert_equal q, issue.qualifier
|
171
|
+
assert_equal nil, issue.repository
|
172
|
+
assert_equal '123', issue.number
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
should 'extract multiple references' do
|
177
|
+
text = 'You should look at GH-2 and GH-4 because GH-5 fixes codetree/codetree#6'
|
178
|
+
refs = extract(text)
|
179
|
+
|
180
|
+
assert refs.include?(2)
|
181
|
+
assert refs.include?(4)
|
182
|
+
assert refs.include?(5)
|
183
|
+
assert refs.include?(6)
|
184
|
+
end
|
185
|
+
|
186
|
+
should 'not extract similar non-qualifiers' do
|
187
|
+
text = 'afixes GH-43'
|
188
|
+
issue = extract_first(text)
|
189
|
+
|
190
|
+
assert_equal nil, issue.qualifier
|
191
|
+
assert_equal nil, issue.repository
|
192
|
+
assert_equal '43', issue.number
|
193
|
+
end
|
194
|
+
|
195
|
+
should 'not choke on case' do
|
196
|
+
text = 'FIxEs GH-43'
|
197
|
+
issue = extract_first(text)
|
198
|
+
|
199
|
+
assert_equal 'FIxEs', issue.qualifier
|
200
|
+
assert_equal nil, issue.repository
|
201
|
+
assert_equal '43', issue.number
|
202
|
+
end
|
203
|
+
|
204
|
+
should 'require only one space between qualifier and issue' do
|
205
|
+
text = 'fixes GH-43'
|
206
|
+
issue = extract_first(text)
|
207
|
+
|
208
|
+
assert_equal nil, issue.qualifier
|
209
|
+
assert_equal nil, issue.repository
|
210
|
+
assert_equal '43', issue.number
|
211
|
+
end
|
212
|
+
|
213
|
+
should 'require at least one space before GH' do
|
214
|
+
text = 'fixes codetree/codetreeGH-99 and fixes GH-43'
|
215
|
+
issue = extract_first(text)
|
216
|
+
|
217
|
+
assert_equal 'fixes', issue.qualifier
|
218
|
+
assert_equal nil, issue.repository
|
219
|
+
assert_equal '43', issue.number
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context '#issue_references with URL syntax' do
|
224
|
+
should 'extract single issue references' do
|
225
|
+
text = 'See https://github.com/codetree/feedback/issues/43'
|
226
|
+
issue = extract_first(text)
|
227
|
+
|
228
|
+
assert_equal nil, issue.qualifier
|
229
|
+
assert_equal 'codetree/feedback', issue.repository
|
230
|
+
assert_equal '43', issue.number
|
231
|
+
end
|
232
|
+
|
233
|
+
should 'extract single pull requests references' do
|
234
|
+
text = 'See https://github.com/codetree/feedback/pulls/43'
|
235
|
+
issue = extract_first(text)
|
236
|
+
|
237
|
+
assert_equal nil, issue.qualifier
|
238
|
+
assert_equal 'codetree/feedback', issue.repository
|
239
|
+
assert_equal '43', issue.number
|
240
|
+
end
|
241
|
+
|
242
|
+
should 'extract single issue references followed by a period' do
|
243
|
+
text = 'See https://github.com/codetree/feedback/issues/43.'
|
244
|
+
issue = extract_first(text)
|
245
|
+
|
246
|
+
assert_equal nil, issue.qualifier
|
247
|
+
assert_equal 'codetree/feedback', issue.repository
|
248
|
+
assert_equal '43', issue.number
|
249
|
+
end
|
250
|
+
|
251
|
+
should 'extract close qualifiers' do
|
252
|
+
%w(fix fixes fixed close closes closed resolve resolves resolved).each do |q|
|
253
|
+
text = "#{q} https://github.com/codetree/feedback/issues/55"
|
254
|
+
issue = extract_first(text)
|
255
|
+
|
256
|
+
assert_equal q, issue.qualifier
|
257
|
+
assert_equal 'codetree/feedback', issue.repository
|
258
|
+
assert_equal '55', issue.number
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
should 'extract dependency qualifiers' do
|
263
|
+
%w(need needs needed require requires required).each do |q|
|
264
|
+
text = "#{q} https://github.com/codetree/feedback/issues/123"
|
265
|
+
issue = extract_first(text)
|
266
|
+
|
267
|
+
assert_equal q, issue.qualifier
|
268
|
+
assert_equal 'codetree/feedback', issue.repository
|
269
|
+
assert_equal '123', issue.number
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
should 'extract multiple references' do
|
274
|
+
text = 'You should look at https://github.com/codetree/feedback/issues/2 ' \
|
275
|
+
'and https://github.com/codetree/feedback/issues/4 because ' \
|
276
|
+
'https://github.com/codetree/feedback/issues/5 fixes codetree/codetree#6'
|
277
|
+
|
278
|
+
refs = extract(text)
|
279
|
+
|
280
|
+
assert refs.include?(2)
|
281
|
+
assert refs.include?(4)
|
282
|
+
assert refs.include?(5)
|
283
|
+
assert refs.include?(6)
|
284
|
+
end
|
285
|
+
|
286
|
+
should 'not extract similar non-qualifiers' do
|
287
|
+
text = 'afixes https://github.com/codetree/feedback/issues/43'
|
288
|
+
issue = extract_first(text)
|
289
|
+
|
290
|
+
assert_equal nil, issue.qualifier
|
291
|
+
assert_equal 'codetree/feedback', issue.repository
|
292
|
+
assert_equal '43', issue.number
|
293
|
+
end
|
294
|
+
|
295
|
+
should 'not choke on case' do
|
296
|
+
text = 'FIxEs https://github.com/codetree/feedback/issues/43'
|
297
|
+
issue = extract_first(text)
|
298
|
+
|
299
|
+
assert_equal 'FIxEs', issue.qualifier
|
300
|
+
assert_equal 'codetree/feedback', issue.repository
|
301
|
+
assert_equal '43', issue.number
|
302
|
+
end
|
303
|
+
|
304
|
+
should 'require only one space between qualifier and issue' do
|
305
|
+
text = 'fixes https://github.com/codetree/feedback/issues/43'
|
306
|
+
issue = extract_first(text)
|
307
|
+
|
308
|
+
assert_equal nil, issue.qualifier
|
309
|
+
assert_equal 'codetree/feedback', issue.repository
|
310
|
+
assert_equal '43', issue.number
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
context '.replace' do
|
315
|
+
should 'yield the phrase and parsed reference' do
|
316
|
+
text = 'Fixes codetree/codetree#123 needs codetree/feedback#456'
|
317
|
+
|
318
|
+
expected = [
|
319
|
+
'Fixes codetree/codetree#123',
|
320
|
+
' needs codetree/feedback#456'
|
321
|
+
]
|
322
|
+
|
323
|
+
Ping::IssueReference.replace(text) do |phrase, reference|
|
324
|
+
expected_phrase = expected.shift
|
325
|
+
expected_reference = Ping::IssueReference.extract(expected_phrase).first
|
326
|
+
|
327
|
+
assert_equal expected_phrase, phrase
|
328
|
+
assert_equal expected_reference, reference
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
context 'given a IssueReference replacement' do
|
333
|
+
should 'handle qualifier + repo + number' do
|
334
|
+
text = 'Fixes a/b#123 fixes #456'
|
335
|
+
|
336
|
+
result = Ping::IssueReference.replace(text) do |_phrase, reference|
|
337
|
+
reference.tap do |r|
|
338
|
+
r.repository = 'codetree/feedback' unless r.repository
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
assert_equal 'Fixes a/b#123 fixes codetree/feedback#456', result
|
343
|
+
end
|
344
|
+
|
345
|
+
should 'handle qualifier + number' do
|
346
|
+
text = 'Fixes #123 fixes #456'
|
347
|
+
|
348
|
+
result = Ping::IssueReference.replace(text) do |_phrase, reference|
|
349
|
+
reference.tap do |r|
|
350
|
+
r.qualifier = 'needs'
|
351
|
+
r.repository = 'a/b'
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
assert_equal 'needs a/b#123 needs a/b#456', result
|
356
|
+
end
|
357
|
+
|
358
|
+
should 'handle repo + number' do
|
359
|
+
text = 'a/b#123 b/c#456'
|
360
|
+
|
361
|
+
result = Ping::IssueReference.replace(text) do |_phrase, reference|
|
362
|
+
reference.tap do |r|
|
363
|
+
r.qualifier = 'needs'
|
364
|
+
r.repository = 'd/e'
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
assert_equal 'needs d/e#123 needs d/e#456', result
|
369
|
+
end
|
370
|
+
|
371
|
+
should 'handle number only' do
|
372
|
+
text = '#123 #456'
|
373
|
+
|
374
|
+
result = Ping::IssueReference.replace(text) do |_phrase, reference|
|
375
|
+
reference.tap do |r|
|
376
|
+
r.repository = 'd/e'
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
assert_equal 'd/e#123 d/e#456', result
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
context 'given a string replacement' do
|
385
|
+
should 'replace references' do
|
386
|
+
text = 'Fixes a/b#123 fixes #456'
|
387
|
+
|
388
|
+
result = Ping::IssueReference.replace(text) do |phrase, _reference|
|
389
|
+
phrase + ' bar'
|
390
|
+
end
|
391
|
+
|
392
|
+
assert_equal 'Fixes a/b#123 bar fixes #456 bar', result
|
393
|
+
end
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
context '#==' do
|
398
|
+
should 'compare with integers' do
|
399
|
+
issue = Ping::IssueReference.new('fixes', 'codetree/codetree', '123')
|
7
400
|
assert issue == 123
|
8
401
|
end
|
9
402
|
|
10
|
-
should
|
11
|
-
issue = Ping::IssueReference.new(
|
12
|
-
assert issue ==
|
403
|
+
should 'compare with strings' do
|
404
|
+
issue = Ping::IssueReference.new('fixes', 'codetree/codetree', '123')
|
405
|
+
assert issue == '123'
|
13
406
|
end
|
14
407
|
|
15
|
-
should
|
16
|
-
issue = Ping::IssueReference.new(
|
17
|
-
assert issue == Ping::IssueReference.new(nil,
|
408
|
+
should 'compare with issues' do
|
409
|
+
issue = Ping::IssueReference.new('fixes', 'codetree/codetree', '123')
|
410
|
+
assert issue == Ping::IssueReference.new(nil, 'codetree/codetree', '123')
|
18
411
|
end
|
19
412
|
end
|
20
413
|
|
21
|
-
context
|
22
|
-
should
|
23
|
-
issue = Ping::IssueReference.new(
|
24
|
-
assert_equal
|
414
|
+
context '#to_s' do
|
415
|
+
should 'return the issue number' do
|
416
|
+
issue = Ping::IssueReference.new('Fixes', 'codetree/codetree', '123')
|
417
|
+
assert_equal '123', issue.to_s
|
25
418
|
end
|
26
419
|
end
|
27
420
|
|
28
|
-
context
|
29
|
-
should
|
30
|
-
issue = Ping::IssueReference.new(
|
421
|
+
context '#to_i' do
|
422
|
+
should 'return the integer issue number' do
|
423
|
+
issue = Ping::IssueReference.new('Fixes', 'codetree/codetree', '123')
|
31
424
|
assert_equal 123, issue.to_i
|
32
425
|
end
|
33
426
|
end
|
data/test/ping/mention_test.rb
CHANGED
@@ -1,22 +1,45 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
2
|
|
3
3
|
class Ping::MentionTest < MiniTest::Test
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
def extract(text)
|
5
|
+
Ping::Mention.extract(text)
|
6
|
+
end
|
7
|
+
|
8
|
+
def extract_first(text)
|
9
|
+
Ping::Mention.extract(text).first
|
10
|
+
end
|
11
|
+
|
12
|
+
context '.extract' do
|
13
|
+
should 'extract @mentions' do
|
14
|
+
text = "Hey there, @djreimer. How's @defunkt?"
|
15
|
+
result = extract(text)
|
16
|
+
assert result.include?('djreimer')
|
17
|
+
assert result.include?('defunkt')
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'de-dup mentions' do
|
21
|
+
text = "Hey there, @djreimer. How's @djreimer?"
|
22
|
+
result = extract(text)
|
23
|
+
assert_equal 1, result.length
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context '#==' do
|
28
|
+
should 'compare with strings' do
|
29
|
+
mention = Ping::Mention.new('djreimer')
|
30
|
+
assert mention == 'djreimer'
|
8
31
|
end
|
9
32
|
|
10
|
-
should
|
11
|
-
mention = Ping::Mention.new(
|
12
|
-
assert mention == Ping::Mention.new(
|
33
|
+
should 'compare with mentions' do
|
34
|
+
mention = Ping::Mention.new('djreimer')
|
35
|
+
assert mention == Ping::Mention.new('djreimer')
|
13
36
|
end
|
14
37
|
end
|
15
38
|
|
16
|
-
context
|
17
|
-
should
|
18
|
-
mention = Ping::Mention.new(
|
19
|
-
assert_equal
|
39
|
+
context '#to_s' do
|
40
|
+
should 'return the username' do
|
41
|
+
mention = Ping::Mention.new('djreimer')
|
42
|
+
assert_equal 'djreimer', mention.to_s
|
20
43
|
end
|
21
44
|
end
|
22
45
|
end
|
data/test/ping/parser_test.rb
CHANGED
@@ -1,358 +1,4 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
2
|
|
3
3
|
class Ping::ParserTest < MiniTest::Test
|
4
|
-
context "#mentions" do
|
5
|
-
should "extract @mentions" do
|
6
|
-
text = "Hey there, @djreimer. How's @defunkt?"
|
7
|
-
parser = Ping::Parser.new(text)
|
8
|
-
assert parser.mentions.include?("djreimer")
|
9
|
-
assert parser.mentions.include?("defunkt")
|
10
|
-
end
|
11
|
-
|
12
|
-
should "de-dup mentions" do
|
13
|
-
text = "Hey there, @djreimer. How's @djreimer?"
|
14
|
-
parser = Ping::Parser.new(text)
|
15
|
-
assert_equal 1, parser.mentions.length
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "#issue_references with standard syntax" do
|
20
|
-
should "extract single issue references" do
|
21
|
-
text = "See #43"
|
22
|
-
parser = Ping::Parser.new(text)
|
23
|
-
issue = parser.issue_references.first
|
24
|
-
|
25
|
-
assert_equal nil, issue.qualifier
|
26
|
-
assert_equal nil, issue.repository
|
27
|
-
assert_equal "43", issue.number
|
28
|
-
end
|
29
|
-
|
30
|
-
should "extract single issue references followed by a period" do
|
31
|
-
text = "See #43."
|
32
|
-
parser = Ping::Parser.new(text)
|
33
|
-
issue = parser.issue_references.first
|
34
|
-
|
35
|
-
assert_equal nil, issue.qualifier
|
36
|
-
assert_equal nil, issue.repository
|
37
|
-
assert_equal "43", issue.number
|
38
|
-
end
|
39
|
-
|
40
|
-
should "extract close qualifiers" do
|
41
|
-
%w{fix fixes fixed close closes closed resolve resolves resolved}.each do |q|
|
42
|
-
text = "#{q} #55"
|
43
|
-
parser = Ping::Parser.new(text)
|
44
|
-
issue = parser.issue_references.first
|
45
|
-
|
46
|
-
assert_equal q, issue.qualifier
|
47
|
-
assert_equal nil, issue.repository
|
48
|
-
assert_equal "55", issue.number
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
should "extract dependency qualifiers" do
|
53
|
-
%w{need needs needed require requires required}.each do |q|
|
54
|
-
text = "#{q} #123"
|
55
|
-
parser = Ping::Parser.new(text)
|
56
|
-
issue = parser.issue_references.first
|
57
|
-
|
58
|
-
assert_equal q, issue.qualifier
|
59
|
-
assert_equal nil, issue.repository
|
60
|
-
assert_equal "123", issue.number
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
should "extract repository" do
|
65
|
-
text = "codetree/codetree#43"
|
66
|
-
parser = Ping::Parser.new(text)
|
67
|
-
issue = parser.issue_references.first
|
68
|
-
|
69
|
-
assert_equal nil, issue.qualifier
|
70
|
-
assert_equal "codetree/codetree", issue.repository
|
71
|
-
assert_equal "43", issue.number
|
72
|
-
end
|
73
|
-
|
74
|
-
should "extract repository with qualifier" do
|
75
|
-
text = "Fixes codetree/codetree#43"
|
76
|
-
parser = Ping::Parser.new(text)
|
77
|
-
issue = parser.issue_references.first
|
78
|
-
|
79
|
-
assert_equal "Fixes", issue.qualifier
|
80
|
-
assert_equal "codetree/codetree", issue.repository
|
81
|
-
assert_equal "43", issue.number
|
82
|
-
end
|
83
|
-
|
84
|
-
should "handle odd repository names" do
|
85
|
-
text = "giant-sequoia-123/scaling_octokitten#43"
|
86
|
-
parser = Ping::Parser.new(text)
|
87
|
-
issue = parser.issue_references.first
|
88
|
-
|
89
|
-
assert_equal "giant-sequoia-123/scaling_octokitten", issue.repository
|
90
|
-
assert_equal "43", issue.number
|
91
|
-
end
|
92
|
-
|
93
|
-
should "extract multiple references" do
|
94
|
-
text = "You should look at #2 and #4 because #5 fixes codetree/codetree#6"
|
95
|
-
parser = Ping::Parser.new(text)
|
96
|
-
|
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
|
-
end
|
102
|
-
|
103
|
-
should "not extract similar non-qualifiers" do
|
104
|
-
text = "afixes #43"
|
105
|
-
parser = Ping::Parser.new(text)
|
106
|
-
issue = parser.issue_references.first
|
107
|
-
|
108
|
-
assert_equal nil, issue.qualifier
|
109
|
-
assert_equal nil, issue.repository
|
110
|
-
assert_equal "43", issue.number
|
111
|
-
end
|
112
|
-
|
113
|
-
should "not choke on case" do
|
114
|
-
text = "FIxEs #43"
|
115
|
-
parser = Ping::Parser.new(text)
|
116
|
-
issue = parser.issue_references.first
|
117
|
-
|
118
|
-
assert_equal "FIxEs", issue.qualifier
|
119
|
-
assert_equal nil, issue.repository
|
120
|
-
assert_equal "43", issue.number
|
121
|
-
end
|
122
|
-
|
123
|
-
should "require one space between qualifier and issue" do
|
124
|
-
text = "fixes #43"
|
125
|
-
parser = Ping::Parser.new(text)
|
126
|
-
issue = parser.issue_references.first
|
127
|
-
|
128
|
-
assert_equal nil, issue.qualifier
|
129
|
-
assert_equal nil, issue.repository
|
130
|
-
assert_equal "43", issue.number
|
131
|
-
end
|
132
|
-
|
133
|
-
should "handle variable casing in repo names" do
|
134
|
-
text = "needs Liquid-Labs/rf-app-admin-web-app#2"
|
135
|
-
parser = Ping::Parser.new(text)
|
136
|
-
issue = parser.issue_references.first
|
137
|
-
|
138
|
-
assert_equal "needs", issue.qualifier
|
139
|
-
assert_equal "Liquid-Labs/rf-app-admin-web-app", issue.repository
|
140
|
-
assert_equal "2", issue.number
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
context "#issue_references with GH-XXX syntax" do
|
145
|
-
should "extract single issue references" do
|
146
|
-
text = "See GH-43"
|
147
|
-
parser = Ping::Parser.new(text)
|
148
|
-
issue = parser.issue_references.first
|
149
|
-
|
150
|
-
assert_equal nil, issue.qualifier
|
151
|
-
assert_equal nil, issue.repository
|
152
|
-
assert_equal "43", issue.number
|
153
|
-
end
|
154
|
-
|
155
|
-
should "extract lower case issue references" do
|
156
|
-
text = "See gh-43"
|
157
|
-
parser = Ping::Parser.new(text)
|
158
|
-
issue = parser.issue_references.first
|
159
|
-
|
160
|
-
assert_equal nil, issue.qualifier
|
161
|
-
assert_equal nil, issue.repository
|
162
|
-
assert_equal "43", issue.number
|
163
|
-
end
|
164
|
-
|
165
|
-
should "extract single issue references followed by a period" do
|
166
|
-
text = "See GH-43."
|
167
|
-
parser = Ping::Parser.new(text)
|
168
|
-
issue = parser.issue_references.first
|
169
|
-
|
170
|
-
assert_equal nil, issue.qualifier
|
171
|
-
assert_equal nil, issue.repository
|
172
|
-
assert_equal "43", issue.number
|
173
|
-
end
|
174
|
-
|
175
|
-
should "extract close qualifiers" do
|
176
|
-
%w{fix fixes fixed close closes closed resolve resolves resolved}.each do |q|
|
177
|
-
text = "#{q} GH-55"
|
178
|
-
parser = Ping::Parser.new(text)
|
179
|
-
issue = parser.issue_references.first
|
180
|
-
|
181
|
-
assert_equal q, issue.qualifier
|
182
|
-
assert_equal nil, issue.repository
|
183
|
-
assert_equal "55", issue.number
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
should "extract dependency qualifiers" do
|
188
|
-
%w{need needs needed require requires required}.each do |q|
|
189
|
-
text = "#{q} GH-123"
|
190
|
-
parser = Ping::Parser.new(text)
|
191
|
-
issue = parser.issue_references.first
|
192
|
-
|
193
|
-
assert_equal q, issue.qualifier
|
194
|
-
assert_equal nil, issue.repository
|
195
|
-
assert_equal "123", issue.number
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
should "extract multiple references" do
|
200
|
-
text = "You should look at GH-2 and GH-4 because GH-5 fixes codetree/codetree#6"
|
201
|
-
parser = Ping::Parser.new(text)
|
202
|
-
|
203
|
-
assert parser.issue_references.include?(2)
|
204
|
-
assert parser.issue_references.include?(4)
|
205
|
-
assert parser.issue_references.include?(5)
|
206
|
-
assert parser.issue_references.include?(6)
|
207
|
-
end
|
208
|
-
|
209
|
-
should "not extract similar non-qualifiers" do
|
210
|
-
text = "afixes GH-43"
|
211
|
-
parser = Ping::Parser.new(text)
|
212
|
-
issue = parser.issue_references.first
|
213
|
-
|
214
|
-
assert_equal nil, issue.qualifier
|
215
|
-
assert_equal nil, issue.repository
|
216
|
-
assert_equal "43", issue.number
|
217
|
-
end
|
218
|
-
|
219
|
-
should "not choke on case" do
|
220
|
-
text = "FIxEs GH-43"
|
221
|
-
parser = Ping::Parser.new(text)
|
222
|
-
issue = parser.issue_references.first
|
223
|
-
|
224
|
-
assert_equal "FIxEs", issue.qualifier
|
225
|
-
assert_equal nil, issue.repository
|
226
|
-
assert_equal "43", issue.number
|
227
|
-
end
|
228
|
-
|
229
|
-
should "require only one space between qualifier and issue" do
|
230
|
-
text = "fixes GH-43"
|
231
|
-
parser = Ping::Parser.new(text)
|
232
|
-
issue = parser.issue_references.first
|
233
|
-
|
234
|
-
assert_equal nil, issue.qualifier
|
235
|
-
assert_equal nil, issue.repository
|
236
|
-
assert_equal "43", issue.number
|
237
|
-
end
|
238
|
-
|
239
|
-
should "require at least one space before GH" do
|
240
|
-
text = "fixes codetree/codetreeGH-99 and fixes GH-43"
|
241
|
-
parser = Ping::Parser.new(text)
|
242
|
-
issue = parser.issue_references.first
|
243
|
-
|
244
|
-
assert_equal "fixes", issue.qualifier
|
245
|
-
assert_equal nil, issue.repository
|
246
|
-
assert_equal "43", issue.number
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
context "#replace_issue_references" do
|
251
|
-
should "yield the phrase and parsed reference" do
|
252
|
-
text = "Fixes codetree/codetree#123 needs codetree/feedback#456"
|
253
|
-
parser = Ping::Parser.new(text)
|
254
|
-
|
255
|
-
expected = [
|
256
|
-
"Fixes codetree/codetree#123",
|
257
|
-
" needs codetree/feedback#456"
|
258
|
-
]
|
259
|
-
|
260
|
-
parser.replace_issue_references do |phrase, reference|
|
261
|
-
expected_phrase = expected.shift
|
262
|
-
expected_reference = Ping::Parser.new(expected_phrase).issue_references.first
|
263
|
-
|
264
|
-
assert_equal expected_phrase, phrase
|
265
|
-
assert_equal expected_reference, reference
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
context "given a IssueReference replacement" do
|
270
|
-
should "handle qualifier + repo + number" do
|
271
|
-
text = "Fixes a/b#123 fixes #456"
|
272
|
-
parser = Ping::Parser.new(text)
|
273
|
-
|
274
|
-
result = parser.replace_issue_references do |phrase, reference|
|
275
|
-
reference.tap do |r|
|
276
|
-
r.repository = "codetree/feedback" unless r.repository
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
assert_equal "Fixes a/b#123 fixes codetree/feedback#456", result
|
281
|
-
end
|
282
|
-
|
283
|
-
should "handle qualifier + number" do
|
284
|
-
text = "Fixes #123 fixes #456"
|
285
|
-
parser = Ping::Parser.new(text)
|
286
|
-
|
287
|
-
result = parser.replace_issue_references do |phrase, reference|
|
288
|
-
reference.tap do |r|
|
289
|
-
r.qualifier = "needs"
|
290
|
-
r.repository = "a/b"
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
assert_equal "needs a/b#123 needs a/b#456", result
|
295
|
-
end
|
296
|
-
|
297
|
-
should "handle repo + number" do
|
298
|
-
text = "a/b#123 b/c#456"
|
299
|
-
parser = Ping::Parser.new(text)
|
300
|
-
|
301
|
-
result = parser.replace_issue_references do |phrase, reference|
|
302
|
-
reference.tap do |r|
|
303
|
-
r.qualifier = "needs"
|
304
|
-
r.repository = "d/e"
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
assert_equal "needs d/e#123 needs d/e#456", result
|
309
|
-
end
|
310
|
-
|
311
|
-
should "handle number only" do
|
312
|
-
text = "#123 #456"
|
313
|
-
parser = Ping::Parser.new(text)
|
314
|
-
|
315
|
-
result = parser.replace_issue_references do |phrase, reference|
|
316
|
-
reference.tap do |r|
|
317
|
-
r.repository = "d/e"
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
assert_equal "d/e#123 d/e#456", result
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
context "given a string replacement" do
|
326
|
-
should "replace references" do
|
327
|
-
text = "Fixes a/b#123 fixes #456"
|
328
|
-
parser = Ping::Parser.new(text)
|
329
|
-
|
330
|
-
result = parser.replace_issue_references do |phrase, reference|
|
331
|
-
phrase + " bar"
|
332
|
-
end
|
333
|
-
|
334
|
-
assert_equal "Fixes a/b#123 bar fixes #456 bar", result
|
335
|
-
end
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
context "#size" do
|
340
|
-
should "extract the last point value" do
|
341
|
-
text = "Is this size:12 or size:14?"
|
342
|
-
parser = Ping::Parser.new(text)
|
343
|
-
assert_equal 14, parser.size.points
|
344
|
-
end
|
345
|
-
|
346
|
-
should "be indifferent to keyword casing" do
|
347
|
-
text = "SiZe:12"
|
348
|
-
parser = Ping::Parser.new(text)
|
349
|
-
assert_equal 12, parser.size.points
|
350
|
-
end
|
351
|
-
|
352
|
-
should "return nil if there is no size" do
|
353
|
-
text = "No size here"
|
354
|
-
parser = Ping::Parser.new(text)
|
355
|
-
assert_nil parser.size.points
|
356
|
-
end
|
357
|
-
end
|
358
4
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require 'ping'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'shoulda-context'
|
6
|
+
require 'mocha/setup'
|
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
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derrick Reimer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: A little library for parsing GitHub @mentions and issue references
|
84
98
|
email:
|
85
99
|
- derrickreimer@gmail.com
|
@@ -88,21 +102,22 @@ extensions: []
|
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
104
|
- .gitignore
|
105
|
+
- .rubocop.yml
|
106
|
+
- .rubocop_todo.yml
|
91
107
|
- Gemfile
|
92
108
|
- LICENSE.txt
|
93
109
|
- README.md
|
94
110
|
- Rakefile
|
111
|
+
- circle.yml
|
95
112
|
- lib/ping.rb
|
96
113
|
- lib/ping/issue_reference.rb
|
97
114
|
- lib/ping/mention.rb
|
98
115
|
- lib/ping/parser.rb
|
99
|
-
- lib/ping/size.rb
|
100
116
|
- lib/ping/version.rb
|
101
117
|
- ping.gemspec
|
102
118
|
- test/ping/issue_reference_test.rb
|
103
119
|
- test/ping/mention_test.rb
|
104
120
|
- test/ping/parser_test.rb
|
105
|
-
- test/ping/size_test.rb
|
106
121
|
- test/test_helper.rb
|
107
122
|
homepage: https://github.com/codetree/ping
|
108
123
|
licenses:
|
@@ -132,6 +147,5 @@ test_files:
|
|
132
147
|
- test/ping/issue_reference_test.rb
|
133
148
|
- test/ping/mention_test.rb
|
134
149
|
- test/ping/parser_test.rb
|
135
|
-
- test/ping/size_test.rb
|
136
150
|
- test/test_helper.rb
|
137
151
|
has_rdoc:
|
data/lib/ping/size.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module Ping
|
2
|
-
class Size
|
3
|
-
attr_accessor :points
|
4
|
-
|
5
|
-
Pattern = /
|
6
|
-
(?:^|\W) # beginning of string or non-word char
|
7
|
-
(?:size|points): # keyword
|
8
|
-
(\d+) # point value
|
9
|
-
(?=
|
10
|
-
\.+[ \t\W]| # dots followed by space or non-word character
|
11
|
-
\.+$| # dots at end of line
|
12
|
-
[^0-9a-zA-Z_.]| # non-word character except dot
|
13
|
-
$ # end of line
|
14
|
-
)
|
15
|
-
/ix
|
16
|
-
|
17
|
-
# See http://rubular.com/r/7u67dIwXuk
|
18
|
-
|
19
|
-
def self.extract(text)
|
20
|
-
matches = text.scan(Pattern)
|
21
|
-
matches.any? ? self.new(matches.last.first.to_i) : self.new(nil)
|
22
|
-
end
|
23
|
-
|
24
|
-
def initialize(points)
|
25
|
-
@points = points
|
26
|
-
end
|
27
|
-
|
28
|
-
def ==(other)
|
29
|
-
other.to_i == to_i
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_i
|
33
|
-
points.to_i
|
34
|
-
end
|
35
|
-
|
36
|
-
def to_s
|
37
|
-
points.to_s
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/test/ping/size_test.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
-
|
3
|
-
class Ping::SizeTest < MiniTest::Test
|
4
|
-
context "#==" do
|
5
|
-
should "compare with integers" do
|
6
|
-
size = Ping::Size.new(10)
|
7
|
-
assert size == 10
|
8
|
-
end
|
9
|
-
|
10
|
-
should "compare with nil" do
|
11
|
-
size = Ping::Size.new(10)
|
12
|
-
assert !(size == nil)
|
13
|
-
|
14
|
-
size = Ping::Size.new(0)
|
15
|
-
assert size == nil
|
16
|
-
|
17
|
-
size = Ping::Size.new(nil)
|
18
|
-
assert size == nil
|
19
|
-
end
|
20
|
-
|
21
|
-
should "compare with other sizes" do
|
22
|
-
size = Ping::Size.new(10)
|
23
|
-
assert Ping::Size.new(10) == size
|
24
|
-
assert !(Ping::Size.new(11) == size)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "#to_s" do
|
29
|
-
should "return the points as a string" do
|
30
|
-
size = Ping::Size.new(10)
|
31
|
-
assert_equal "10", size.to_s
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "#to_i" do
|
36
|
-
should "return the integer points" do
|
37
|
-
size = Ping::Size.new(10)
|
38
|
-
assert_equal 10, size.to_i
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|