note_tracker 0.0.2
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +17 -0
- data/lib/note_tracker.rb +8 -0
- data/lib/note_tracker/client.rb +12 -0
- data/lib/note_tracker/source_annotation_extractor.rb +134 -0
- data/lib/note_tracker/tracker.rb +51 -0
- data/lib/note_tracker/version.rb +3 -0
- data/note_tracker.gemspec +26 -0
- data/test/minitest_helper.rb +4 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b7363a355b02befe8556d4683c60128bb1e0329a
|
4
|
+
data.tar.gz: 4df89376943d2a2b331d0129a3901e43f6a04793
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e501342a135411edb9a31056b51c707f5034bc4c479292dafc59f0cb91f3e22371c3b9ec366811608e74d046cd9f7e337bcf80ecd052a7093ea236542e67890
|
7
|
+
data.tar.gz: 9e556e89347c2657a33fc041a26f50e943fd71a1337366c944e32c06792ff32c255e8fa25bf5779333109665bc8a7022fda490ca036c500337a36057878be83b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Alfonso Uceda Pompa
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# NoteTracker
|
2
|
+
|
3
|
+
This gem provides the feature to track your notes with pivotal tracker
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'note_tracker'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install note_tracker
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/note_tracker/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require "bundler/setup"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
|
+
end
|
6
|
+
|
7
|
+
require "bundler/gem_tasks"
|
8
|
+
require "rake/testtask"
|
9
|
+
|
10
|
+
Rake::TestTask.new(:test) do |t|
|
11
|
+
t.libs << "lib"
|
12
|
+
t.libs << "test"
|
13
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
14
|
+
t.verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
task default: :test
|
data/lib/note_tracker.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module NoteTracker
|
2
|
+
class Client
|
3
|
+
def initialize(options = {})
|
4
|
+
@tracker_token = options.fetch(:tracker_token)
|
5
|
+
@tracker_project = options.fetch(:tracker_project)
|
6
|
+
end
|
7
|
+
|
8
|
+
def track(options = {})
|
9
|
+
Tracker.new(@tracker_token, @tracker_project, options).perform
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# Class copied from [1] and modified to store pivotal tracker id
|
2
|
+
#
|
3
|
+
# [1]: https://github.com/rails/rails/blob/master/railties/lib/rails/source_annotation_extractor.rb
|
4
|
+
module NoteTracker
|
5
|
+
class SourceAnnotationExtractor
|
6
|
+
class Annotation < Struct.new(:line, :tag, :story_id, :text)
|
7
|
+
def self.directories
|
8
|
+
@@directories ||= %w(app config db lib test) + (ENV['SOURCE_ANNOTATION_DIRECTORIES'] || '').split(',')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.extensions
|
12
|
+
@@extensions ||= {}
|
13
|
+
end
|
14
|
+
|
15
|
+
# Registers new Annotations File Extensions
|
16
|
+
# SourceAnnotationExtractor::Annotation.register_extensions("css", "scss", "sass", "less", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }
|
17
|
+
def self.register_extensions(*exts, &block)
|
18
|
+
extensions[/\.(#{exts.join("|")})$/] = block
|
19
|
+
end
|
20
|
+
|
21
|
+
register_extensions("builder", "rb", "rake", "yml", "yaml", "ruby") { |tag| /#\s*(\[#\d+\])?\s*(#{tag}):?\s*\s*(.*)$/ }
|
22
|
+
register_extensions("css", "js") { |tag| /\/\/\s*(\[#\d+\])?\s*(#{tag}):?\s*\s*(.*)$/ }
|
23
|
+
register_extensions("erb") { |tag| /<%\s*#\s*(\[#\d+\])?\s*(#{tag}):?\s*(.*?)\s*%>/ }
|
24
|
+
|
25
|
+
# Returns a representation of the annotation that looks like this:
|
26
|
+
#
|
27
|
+
# [126] [TODO] This algorithm is simple and clearly correct, make it faster.
|
28
|
+
#
|
29
|
+
# If +options+ has a flag <tt>:tag</tt> the tag is shown as in the example above.
|
30
|
+
# Otherwise the string contains just line and text.
|
31
|
+
def to_s(options={})
|
32
|
+
s = "[#{line.to_s.rjust(options[:indent])}] "
|
33
|
+
s << "[#{tag}] " if options[:tag]
|
34
|
+
s << text
|
35
|
+
end
|
36
|
+
|
37
|
+
def trackered?
|
38
|
+
!!story_id
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Prints all annotations with tag +tag+ under the root directories +app+,
|
43
|
+
# +config+, +db+, +lib+, and +test+ (recursively).
|
44
|
+
#
|
45
|
+
# Additional directories may be added using a comma-delimited list set using
|
46
|
+
# <tt>ENV['SOURCE_ANNOTATION_DIRECTORIES']</tt>.
|
47
|
+
#
|
48
|
+
# Directories may also be explicitly set using the <tt>:dirs</tt> key in +options+.
|
49
|
+
#
|
50
|
+
# SourceAnnotationExtractor.enumerate 'TODO|FIXME', dirs: %w(app lib), tag: true
|
51
|
+
#
|
52
|
+
# If +options+ has a <tt>:tag</tt> flag, it will be passed to each annotation's +to_s+.
|
53
|
+
#
|
54
|
+
# See <tt>#find_in</tt> for a list of file extensions that will be taken into account.
|
55
|
+
#
|
56
|
+
# This class method is the single entry point for the rake tasks.
|
57
|
+
def self.enumerate(tag, options={})
|
58
|
+
extractor = new(tag)
|
59
|
+
dirs = options.delete(:dirs) || Annotation.directories
|
60
|
+
extractor.display(extractor.find(dirs), options)
|
61
|
+
end
|
62
|
+
|
63
|
+
attr_reader :tag
|
64
|
+
|
65
|
+
def initialize(tag)
|
66
|
+
@tag = tag
|
67
|
+
end
|
68
|
+
|
69
|
+
# Returns a hash that maps filenames under +dirs+ (recursively) to arrays
|
70
|
+
# with their annotations.
|
71
|
+
def find(dirs)
|
72
|
+
dirs.inject({}) { |h, dir| h.update(find_in(dir)) }
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns a hash that maps filenames under +dir+ (recursively) to arrays
|
76
|
+
# with their annotations. Only files with annotations are included. Files
|
77
|
+
# with extension +.builder+, +.rb+, +.erb+, +.haml+, +.slim+, +.css+,
|
78
|
+
# +.scss+, +.js+, +.coffee+, +.rake+, +.sass+ and +.less+
|
79
|
+
# are taken into account.
|
80
|
+
def find_in(dir)
|
81
|
+
results = {}
|
82
|
+
p dir
|
83
|
+
p ".. #{Dir.glob("#{dir}/*")}"
|
84
|
+
Dir.glob("#{dir}/*") do |item|
|
85
|
+
p item
|
86
|
+
next if File.basename(item)[0] == ?.
|
87
|
+
|
88
|
+
if File.directory?(item)
|
89
|
+
results.update(find_in(item))
|
90
|
+
else
|
91
|
+
extension = Annotation.extensions.detect do |regexp, _block|
|
92
|
+
regexp.match(item)
|
93
|
+
end
|
94
|
+
|
95
|
+
if extension
|
96
|
+
pattern = extension.last.call(tag)
|
97
|
+
results.update(extract_annotations_from(item, pattern)) if pattern
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
results
|
103
|
+
end
|
104
|
+
|
105
|
+
# If +file+ is the filename of a file that contains annotations this method returns
|
106
|
+
# a hash with a single entry that maps +file+ to an array of its annotations.
|
107
|
+
# Otherwise it returns an empty hash.
|
108
|
+
def extract_annotations_from(file, pattern)
|
109
|
+
lineno = 0
|
110
|
+
result = File.readlines(file).inject([]) do |list, line|
|
111
|
+
lineno += 1
|
112
|
+
next list unless line =~ pattern
|
113
|
+
tag = $2
|
114
|
+
text = $3
|
115
|
+
story_id = $1.to_s.scan(/\d+/).first
|
116
|
+
list << Annotation.new(lineno, tag, story_id, text)
|
117
|
+
end
|
118
|
+
result.empty? ? {} : { file => result }
|
119
|
+
end
|
120
|
+
|
121
|
+
# Prints the mapping from filenames to annotations in +results+ ordered by filename.
|
122
|
+
# The +options+ hash is passed to each annotation's +to_s+.
|
123
|
+
def display(results, options={})
|
124
|
+
options[:indent] = results.flat_map { |f, a| a.map(&:line) }.max.to_s.size
|
125
|
+
results.keys.sort.each do |file|
|
126
|
+
puts "#{file}:"
|
127
|
+
results[file].each do |note|
|
128
|
+
puts " * #{note.to_s(options)}"
|
129
|
+
end
|
130
|
+
puts
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module NoteTracker
|
5
|
+
class Tracker
|
6
|
+
def initialize(token, project, options = {})
|
7
|
+
@token = token
|
8
|
+
@project = project
|
9
|
+
@tags_to_track = options.fetch(:tags) { "OPTIMIZE|FIXME|TODO" }
|
10
|
+
@directories_to_track = options.fetch(:directories) { %w(.) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def perform
|
14
|
+
results_annotation_extractor.each do |file, annotations|
|
15
|
+
temp_file = Tempfile.new('foo')
|
16
|
+
|
17
|
+
File.open(file, 'r') do |file|
|
18
|
+
file.each_line do |line|
|
19
|
+
annotation = annotations.detect { |annotation| annotation.line == file.lineno }
|
20
|
+
if annotation && !annotation.trackered?
|
21
|
+
story_id = create_story(annotation).id
|
22
|
+
line.gsub!("#{annotation.tag}","[##{story_id}] #{annotation.tag}")
|
23
|
+
end
|
24
|
+
temp_file.puts line
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
temp_file.close
|
29
|
+
FileUtils.mv(temp_file.path, file)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def tracker_client
|
36
|
+
@tracker_client ||= TrackerApi::Client.new(token: @token)
|
37
|
+
end
|
38
|
+
|
39
|
+
def tracker_project
|
40
|
+
@tracker_project ||= tracker_client.project(@project)
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_story(annotation)
|
44
|
+
tracker_project.create_story(name: annotation.text)
|
45
|
+
end
|
46
|
+
|
47
|
+
def results_annotation_extractor
|
48
|
+
SourceAnnotationExtractor.new(@tags_to_track).find(@directories_to_track)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'note_tracker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "note_tracker"
|
8
|
+
spec.version = NoteTracker::VERSION
|
9
|
+
spec.authors = ["Alfonso Uceda Pompa"]
|
10
|
+
spec.email = ["uceda73@gmail.com"]
|
11
|
+
spec.summary = %q{Track your notes with Pivotal tracker}
|
12
|
+
spec.description = %q{This gem provides the feature to track your notes with pivotal tracker}
|
13
|
+
spec.homepage = "https://github.com/AlfonsoUceda/note_tracker"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
|
25
|
+
spec.add_dependency "tracker_api"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: note_tracker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alfonso Uceda Pompa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tracker_api
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: This gem provides the feature to track your notes with pivotal tracker
|
70
|
+
email:
|
71
|
+
- uceda73@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/note_tracker.rb
|
82
|
+
- lib/note_tracker/client.rb
|
83
|
+
- lib/note_tracker/source_annotation_extractor.rb
|
84
|
+
- lib/note_tracker/tracker.rb
|
85
|
+
- lib/note_tracker/version.rb
|
86
|
+
- note_tracker.gemspec
|
87
|
+
- test/minitest_helper.rb
|
88
|
+
homepage: https://github.com/AlfonsoUceda/note_tracker
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.2.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Track your notes with Pivotal tracker
|
112
|
+
test_files:
|
113
|
+
- test/minitest_helper.rb
|