Module: Issuesrc
- Defined in:
- lib/issuesrc.rb,
lib/issuesrc/tag.rb,
lib/issuesrc/file.rb,
lib/issuesrc/config.rb,
lib/issuesrc/version.rb,
lib/issuesrc/event_loop.rb,
lib/sourcers/git_sourcer.rb,
lib/issuers/github_issuer.rb,
lib/issuesrc/tag_extractor.rb,
lib/sourcers/github_sourcer.rb,
lib/tag_finders/blunt_tag_finder.rb
Defined Under Namespace
Modules: Config, Issuers, Sourcers, TagFinders
Classes: EventLoop, FSFile, GitFile, IssuesrcError, SequentialEventLoop, Tag, TagExtractor
Constant Summary
collapse
- DEFAULT_SOURCER =
'github'
- DEFAULT_ISSUER =
'github'
- DEFAULT_TAG_FINDERS =
['blunt']
- SOURCERS =
{
'git' => ['sourcers/git_sourcer', 'GitSourcer'],
'github' => ['sourcers/github_sourcer', 'GithubSourcer'],
}
- ISSUERS =
{
'github' => ['issuers/github_issuer', 'GithubIssuer'],
}
- TAG_FINDERS =
{
'blunt' => ['tag_finders/blunt_tag_finder', 'BluntTagFinder'],
}
- VERSION =
"0.0.3"
[
{
'regexp' => /(?<type>TODO|FIXME|BUG)\s*(\(\s*(?<author>[^)#\s]+)?\s*(#\s*(?<issue_id>[^)\s]+))?\s*\))?\s*:?\s*(?<title>[^\s].*)?/,
}
]
Class Method Summary
collapse
Instance Method Summary
collapse
-
#classify_tags(tags, file) ⇒ Object
-
#do_require(path) ⇒ Object
-
#init_files_offsets ⇒ Object
-
#load_component(config_key, arg_key, default, options) ⇒ Object
-
#load_component_by_type(type, options) ⇒ Object
-
#load_issuer(event_loop) ⇒ Object
Like load_sourcer, but for the issuer.
-
#load_sourcer ⇒ Object
Creates the instance of the sourcer that should be used for the current execution of issuesrc.
-
#load_tag_finders ⇒ Object
Like load_sourcer but for the tag finders.
-
#load_tag_finders_by_types(types) ⇒ Object
-
#make_issuer(cls, event_loop) ⇒ Object
-
#make_sourcer(cls) ⇒ Object
-
#make_tag_finder(cls, tag_extractor) ⇒ Object
-
#save_tag_in_file(tag) ⇒ Object
-
#select_tag_finder_for(file, tag_finders) ⇒ Object
-
#set_config(args, config) ⇒ Object
Class Method Details
.exec_fail(feedback) ⇒ Object
202
203
204
|
# File 'lib/issuesrc.rb', line 202
def self.exec_fail(feedback)
raise IssuesrcError, feedback
end
|
.run(args, config) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/issuesrc.rb', line 30
def self.run(args, config)
program = Class.new { include Issuesrc }.new
program.set_config(args, config)
program.init_files_offsets()
event_loop = Issuesrc::SequentialEventLoop.new()
sourcer = program.load_sourcer()
tag_finders = program.load_tag_finders()
issuer = program.load_issuer(event_loop)
issues = issuer.async_load_issues()
created_tags, updated_tags, closed_issues = [], [], []
sourcer.retrieve_files().each do |file|
if Issuesrc::Config::option_from_args(:verbose, args)
puts file.path
end
tag_finder = program.select_tag_finder_for(file, tag_finders)
if tag_finder.nil?
next
end
tags = []
tag_finder.find_tags(file) { |tag| tags << tag }
tags_by_issue_id, new_tags = program.classify_tags(tags, file)
new_tags.each do |tag|
created_tags << tag
issuer.async_create_issue(tag) do |tag|
program.save_tag_in_file(tag)
end
end
issuer.async_update_or_close_issues(issues, tags_by_issue_id) do
|issue_id, tag, action|
case action
when :updated
program.save_tag_in_file(tag)
updated_tags << tag
when :closed
closed_issues << issue_id
end
end
end
event_loop.wait_for_pending()
if sourcer.respond_to? :finish
sourcer.finish(created_tags, updated_tags, closed_issues)
end
end
|
Instance Method Details
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/issuesrc.rb', line 183
def classify_tags(tags, file)
tags_by_issue = {}
new_tags = []
tags.each do |tag|
if tag.issue_id.nil?
new_tags << tag
else
tags_by_issue[tag.issue_id] = tag
end
end
[tags_by_issue, new_tags]
end
|
#do_require(path) ⇒ Object
206
207
208
|
# File 'lib/issuesrc.rb', line 206
def do_require(path)
require path
end
|
#init_files_offsets ⇒ Object
90
91
92
|
# File 'lib/issuesrc.rb', line 90
def init_files_offsets
@files_offsets = {}
end
|
#load_component(config_key, arg_key, default, options) ⇒ Object
130
131
132
133
134
135
136
|
# File 'lib/issuesrc.rb', line 130
def load_component(config_key, arg_key, default, options)
type = Config::option_from_both(arg_key, config_key, @args, @config)
if type.nil?
type = default
end
load_component_by_type(type, options)
end
|
#load_component_by_type(type, options) ⇒ Object
138
139
140
141
142
143
144
|
# File 'lib/issuesrc.rb', line 138
def load_component_by_type(type, options)
if !options.include?(type)
exec_fail 'Unrecognized sourcer type: #{type}'
end
options[type]
end
|
#load_issuer(event_loop) ⇒ Object
Like load_sourcer, but for the issuer. It first looks at :issuer from the command line arguments, then ‘[issuer] issuer = …` from the config file.
116
117
118
119
120
121
122
123
124
|
# File 'lib/issuesrc.rb', line 116
def load_issuer(event_loop)
path, cls = load_component(
['issuer', 'issuer'],
:issuer,
DEFAULT_ISSUER,
ISSUERS)
do_require(path)
make_issuer(cls, event_loop)
end
|
#load_sourcer ⇒ Object
Creates the instance of the sourcer that should be used for the current execution of issuesrc. It looks first at the :sourcer command line argument, then ‘[sourcer] sourcer = …` from the config file. If those are not present, DEFAULT_SOURCER will be used. If the selected sourcer is not implemented, ie. is not a key of SOURCERS, the execution will fail.
99
100
101
102
103
104
105
106
107
|
# File 'lib/issuesrc.rb', line 99
def load_sourcer
path, cls = load_component(
['sourcer', 'sourcer'],
:sourcer,
DEFAULT_SOURCER,
SOURCERS)
do_require(path)
make_sourcer(cls)
end
|
#load_tag_finders ⇒ Object
Like load_sourcer but for the tag finders. It only looks at ‘[tag_finders] tag_finders = […]` from the config file.
148
149
150
151
152
153
154
155
|
# File 'lib/issuesrc.rb', line 148
def load_tag_finders
tag_finders = Config::option_from_config(
['tag_finders', 'tag_finders'], @config)
if tag_finders.nil?
tag_finders = DEFAULT_TAG_FINDERS
end
load_tag_finders_by_types(tag_finders)
end
|
#load_tag_finders_by_types(types) ⇒ Object
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/issuesrc.rb', line 157
def load_tag_finders_by_types(types)
= Issuesrc::TagExtractor.new(@args, @config)
tag_finders = []
types.each do |type|
path, cls = load_component_by_type(type, TAG_FINDERS)
do_require(path)
tag_finders << make_tag_finder(cls, )
end
tag_finders
end
|
#make_issuer(cls, event_loop) ⇒ Object
126
127
128
|
# File 'lib/issuesrc.rb', line 126
def make_issuer(cls, event_loop)
Issuesrc::Issuers.const_get(cls).new(@args, @config, event_loop)
end
|
#make_sourcer(cls) ⇒ Object
109
110
111
|
# File 'lib/issuesrc.rb', line 109
def make_sourcer(cls)
Issuesrc::Sourcers.const_get(cls).new(@args, @config)
end
|
#make_tag_finder(cls, tag_extractor) ⇒ Object
168
169
170
|
# File 'lib/issuesrc.rb', line 168
def make_tag_finder(cls, )
Issuesrc::TagFinders.const_get(cls).new(, @args, @config)
end
|
#save_tag_in_file(tag) ⇒ Object
196
197
198
199
200
|
# File 'lib/issuesrc.rb', line 196
def save_tag_in_file(tag)
offsets = @files_offsets.fetch(tag.file.path, [])
offsets = tag.write_in_file(offsets)
@files_offsets[tag.file.path] = offsets
end
|
#select_tag_finder_for(file, tag_finders) ⇒ Object
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/issuesrc.rb', line 172
def select_tag_finder_for(file, tag_finders)
ret = nil
tag_finders.each do |tag_finder|
if tag_finder.accepts? file
ret = tag_finder
break
end
end
ret
end
|
#set_config(args, config) ⇒ Object
85
86
87
88
|
# File 'lib/issuesrc.rb', line 85
def set_config(args, config)
@args = args
@config = config
end
|