adjutant 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0472258513e3c3369e494a58541bf0a188bfdaaa
4
+ data.tar.gz: e243e326b12bda780a2a1e059da94e73c4431744
5
+ SHA512:
6
+ metadata.gz: 164bc49749ec7d44ce8b509d9d9f78f7a511d7531a6a92d8ef6cdb5118e5922067de114020457cc44aabaf7603aa806a1e73cffe2a3ac83af57225223259ad2f
7
+ data.tar.gz: 81578b5de4adae18dfd822a7ac86b3b0f76d47295ccc2d09e043efb902a37732fd6ffbd66cdd7abe836cd6d3b65dbd82fa896259e8eb7e6737e6524fb6613b2a
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .vimrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in adjutant.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Baltazore
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,29 @@
1
+ # Adjutant
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'adjutant'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install adjutant
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/adjutant/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/adjutant.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'adjutant/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "adjutant"
8
+ spec.version = Adjutant::VERSION
9
+ spec.authors = ["Baltazore"]
10
+ spec.email = ["baltazore92@gmail.com"]
11
+ spec.summary = %q{Gem that help parse git patch data}
12
+ spec.description = %q{Ruby Gem that parse patch data for comments and ToDo lists and paste them on GitHub PR.}
13
+ spec.homepage = "http://baltazore.github.io/adjutant"
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_dependency "json", "~> 1.7"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", "~> 3.1"
26
+ spec.add_development_dependency "pry-byebug"
27
+ end
@@ -0,0 +1,30 @@
1
+ module Adjutant
2
+ Comment = Struct.new(:text, :index) do
3
+ def initialize(*)
4
+ super
5
+ self.index ||= 0
6
+ end
7
+
8
+ def add(comment, index)
9
+ self.index = index + 1 if empty?
10
+ self.text =
11
+ if empty?
12
+ comment.to_s
13
+ else
14
+ self.text + "\\n" + comment
15
+ end
16
+ end
17
+
18
+ def empty?
19
+ self.text.nil? || self.text.empty?
20
+ end
21
+
22
+ def reset
23
+ self.text = nil
24
+ end
25
+
26
+ def print
27
+ [ self.text, self.index ]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,50 @@
1
+ module Adjutant
2
+ class FileParser
3
+
4
+ attr_reader :comment
5
+
6
+ def initialize(file)
7
+ @text = file[:patch]
8
+ @comment = Comment.new("")
9
+ @comments = []
10
+ end
11
+
12
+ def detect_comments
13
+ usefull = false
14
+ lines_pushed.each_with_index do |line, index|
15
+ line = Line.new(line)
16
+
17
+ if line.usefull? || usefull
18
+ usefull = true
19
+ parse_line(line, index)
20
+ else
21
+ push_comment
22
+ usefull = false
23
+
24
+ next
25
+ end
26
+ end
27
+ push_comment if usefull
28
+ @comments
29
+ end
30
+
31
+ def push_comment
32
+ @comments << @comment.print
33
+ @comment.reset
34
+ end
35
+
36
+ def parse_line(line, index)
37
+ if line.end_of_comment?
38
+ push_comment
39
+ else
40
+ @comment.add line.usefull_text, index
41
+ end
42
+ end
43
+
44
+ def lines_pushed
45
+ @text
46
+ .split(/(\n)/)
47
+ .delete_if { |e| e[0] != "+" }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,26 @@
1
+ module Adjutant
2
+ Line = Struct.new(:line) do
3
+ COMMENT_SIGN = "#"
4
+ USERNAME_SIGN = "@"
5
+ TODO_LINE = "TODO:"
6
+
7
+ def usefull?() contain_comment? && point_of_interes? && new_added? end
8
+
9
+ def contain_comment?() line.scan(/\+\s*#{COMMENT_SIGN}/).any? end
10
+
11
+ def point_of_interes?() contain_username? || contain_todo? end
12
+ def contain_username?() line.scan(/(#{USERNAME_SIGN}\w+)/).any? end
13
+ def contain_todo?() line.scan(/#{TODO_LINE}/).any? end
14
+
15
+ def new_added?() line[0] == '+' end
16
+
17
+ def end_of_comment?() contain_comment?() ? empty_comment? : true end
18
+ def empty_comment?() line.scan(/\+\s*#{COMMENT_SIGN}\s*(\S+)/).empty? end
19
+
20
+ def usefull_text
21
+ matched = line.scan(/\+\s*#\s*/).first
22
+ line[matched.size .. -1] unless matched.nil?
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Adjutant
2
+ VERSION = "0.1.0"
3
+ end
data/lib/adjutant.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'adjutant/version'
2
+ require 'adjutant/comment'
3
+ require 'adjutant/line'
4
+ require 'adjutant/file_parser'
5
+
6
+ module Adjutant
7
+
8
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Adjutant::Comment do
4
+ let(:message) { "Hey there!" }
5
+ let(:index) { 42 }
6
+
7
+ it 'creates an comment with given text' do
8
+ comment = Adjutant::Comment.new(message)
9
+ expect(comment.text).to eq(message)
10
+ end
11
+
12
+ describe '#empty?' do
13
+ it 'return false if text is present' do
14
+ comment = Adjutant::Comment.new(message)
15
+ expect(comment.empty?).to eq(false)
16
+ end
17
+
18
+ it 'return true if text is nil' do
19
+ comment = Adjutant::Comment.new
20
+ expect(comment.empty?).to eq(true)
21
+ end
22
+
23
+ it 'return true if text is empty' do
24
+ comment = Adjutant::Comment.new("")
25
+ expect(comment.empty?).to eq(true)
26
+ end
27
+ end
28
+
29
+ describe '#add' do
30
+ let(:part1) { "Hello" }
31
+ let(:part2) { "world!" }
32
+ let(:text) { "Hello\\nworld!" }
33
+
34
+ it 'adds new text to empty comment' do
35
+ comment = Adjutant::Comment.new
36
+ comment.add(part1, 0)
37
+ expect(comment.text).to eq(part1)
38
+ end
39
+
40
+ it 'adds new text to comment with adding new line' do
41
+ comment = Adjutant::Comment.new(part1)
42
+ comment.add(part2, 0)
43
+ expect(comment.text).to eq(text)
44
+ end
45
+ end
46
+
47
+ describe '#reset' do
48
+ it 'is able to reset text for comment' do
49
+ comment = Adjutant::Comment.new(message)
50
+ expect(comment.text).to eq(message)
51
+ comment.reset
52
+ expect(comment.text).to eq(nil)
53
+ end
54
+ end
55
+
56
+ describe '#print' do
57
+ let(:message2) { "I'm here" }
58
+ it 'returns comemnt with default index to push as comment' do
59
+ comment = Adjutant::Comment.new(message)
60
+ expect(comment.print).to eq([message, 0])
61
+ end
62
+
63
+ it 'returns comemnt with first index to push as comment' do
64
+ comment = Adjutant::Comment.new
65
+ comment.add(message, index)
66
+ comment.add(message2, index+1)
67
+ expect(comment.print).to eq([message+"\\n"+message2, index+1])
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Adjutant::FileParser do
4
+
5
+ let(:file) do
6
+ { :patch => "@@ -0,0 +1,14 @@\n+# @Baltazore is trying to check first line comment\n+def super_method(such_args)\n \"Doge tutorial\"\nend\n# doing some stuff\n\"hello world\"\n+# @baltazore, Let's check multiline comments,\n+# them really rocks\n#\n+\n+# TODO:\n+# - [ ] This Github flavoured markdown\n+# - [ ] such nice\n+# - [ ] very exciting" }
7
+ end
8
+
9
+ let(:lines) do
10
+ [
11
+ "+# @Baltazore is trying to check first line comment",
12
+ "+def super_method(such_args)",
13
+ "+# @baltazore, Let's check multiline comments,",
14
+ "+# them really rocks",
15
+ "+",
16
+ "+# TODO:",
17
+ "+# - [ ] This Github flavoured markdown",
18
+ "+# - [ ] such nice",
19
+ "+# - [ ] very exciting",
20
+ ]
21
+ end
22
+
23
+ let(:comments) do
24
+ [
25
+ [ "@Baltazore is trying to check first line comment", 1 ],
26
+ [ "@baltazore, Let's check multiline comments,\\nthem really rocks", 3],
27
+ [ "TODO:\\n- [ ] This Github flavoured markdown\\n- [ ] such nice\\n- [ ] very exciting", 6 ]
28
+ ]
29
+ end
30
+ let(:file_parser) { Adjutant::FileParser.new(file) }
31
+
32
+ describe '#detect_comments' do
33
+ context '#lines_pushed' do
34
+ it 'returns all lines that has been pushed in commit' do
35
+ file_parser.lines_pushed.each_with_index do |line, index|
36
+ expect(line).to eq(lines[index])
37
+ end
38
+ end
39
+ end
40
+
41
+ context '#parse_line' do
42
+ it 'should create a comment from pushed lines' do
43
+ line = Adjutant::Line.new(lines[0])
44
+ file_parser.parse_line(line, 0)
45
+ expect(file_parser.comment.text).to eq(comments[0][0])
46
+ end
47
+ end
48
+
49
+ it 'returns all comment, that catch up' do
50
+ file_parser.detect_comments.each_with_index do |comment, index|
51
+ expect(comment).to eq(comments[index])
52
+ end
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Adjutant::Line do
4
+ let(:comment) { "+# @baltazore don't forget to write specs!" }
5
+ let(:todo) { "+ # TODO: write moar specs!" }
6
+ let(:empty) { "+ #" }
7
+ let(:useless) { "class Line" }
8
+
9
+ describe '#usefull?' do
10
+
11
+ context '#contain_comment?' do
12
+ it 'return true if line contain comment' do
13
+ expect(Adjutant::Line.new(comment).contain_comment?).to eq(true)
14
+ expect(Adjutant::Line.new(todo).contain_comment?).to eq(true)
15
+ expect(Adjutant::Line.new(empty).contain_comment?).to eq(true)
16
+ end
17
+
18
+ it 'return false in other cases' do
19
+ expect(Adjutant::Line.new(useless).contain_comment?).to eq(false)
20
+ end
21
+ end
22
+
23
+ describe '#point_of_interes?' do
24
+
25
+ context '#contain_username' do
26
+ it 'return true if line contain username' do
27
+ expect(Adjutant::Line.new(comment).contain_username?).to eq(true)
28
+ end
29
+
30
+ it 'return false in other cases' do
31
+ expect(Adjutant::Line.new(todo).contain_username?).to eq(false)
32
+ expect(Adjutant::Line.new(empty).contain_username?).to eq(false)
33
+ expect(Adjutant::Line.new(useless).contain_username?).to eq(false)
34
+ end
35
+ end
36
+
37
+ context '#contain_todo' do
38
+ it 'return true if line contain todo' do
39
+ expect(Adjutant::Line.new(todo).contain_todo?).to eq(true)
40
+ end
41
+
42
+ it 'return false in other cases' do
43
+ expect(Adjutant::Line.new(comment).contain_todo?).to eq(false)
44
+ expect(Adjutant::Line.new(empty).contain_todo?).to eq(false)
45
+ expect(Adjutant::Line.new(useless).contain_todo?).to eq(false)
46
+ end
47
+ end
48
+
49
+ it 'returns true if line is comment line and interesting for us' do
50
+ expect(Adjutant::Line.new(comment).point_of_interes?).to eq(true)
51
+ expect(Adjutant::Line.new(todo).point_of_interes?).to eq(true)
52
+ end
53
+
54
+ it 'returns false in other cases' do
55
+ expect(Adjutant::Line.new(empty).point_of_interes?).to eq(false)
56
+ expect(Adjutant::Line.new(useless).point_of_interes?).to eq(false)
57
+ end
58
+ end
59
+
60
+ context '#new_added?' do
61
+ it 'returns true if line is new added' do
62
+ expect(Adjutant::Line.new(comment).new_added?).to eq(true)
63
+ expect(Adjutant::Line.new(todo).new_added?).to eq(true)
64
+ expect(Adjutant::Line.new(empty).new_added?).to eq(true)
65
+ end
66
+
67
+ it 'returns false in other cases' do
68
+ expect(Adjutant::Line.new(useless).new_added?).to eq(false)
69
+ end
70
+ end
71
+ end
72
+
73
+ describe '#usefull_text' do
74
+ it 'returns usefull text from line' do
75
+ comment_text = "@baltazore don't forget to write specs!"
76
+ todo_text = "TODO: write moar specs!"
77
+ expect(Adjutant::Line.new(comment).usefull_text).to eq(comment_text)
78
+ expect(Adjutant::Line.new(todo).usefull_text).to eq(todo_text)
79
+ expect(Adjutant::Line.new(empty).usefull_text).to eq("")
80
+ expect(Adjutant::Line.new(useless).usefull_text).to eq(nil)
81
+ end
82
+ end
83
+
84
+ describe '#end_of_comment?' do
85
+ context '#empty_comment?' do
86
+ it 'returns true if comment is empty' do
87
+ expect(Adjutant::Line.new(empty).empty_comment?).to eq(true)
88
+ end
89
+
90
+ it 'returns false in other cases' do
91
+ expect(Adjutant::Line.new(comment).empty_comment?).to eq(false)
92
+ expect(Adjutant::Line.new(todo).empty_comment?).to eq(false)
93
+ end
94
+ end
95
+
96
+ it 'returns true if comment is ended' do
97
+ expect(Adjutant::Line.new(empty).end_of_comment?).to eq(true)
98
+ expect(Adjutant::Line.new(useless).end_of_comment?).to eq(true)
99
+ end
100
+
101
+ it 'returns false in other cases' do
102
+ expect(Adjutant::Line.new(comment).end_of_comment?).to eq(false)
103
+ expect(Adjutant::Line.new(todo).end_of_comment?).to eq(false)
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,19 @@
1
+ require 'adjutant'
2
+
3
+ RSpec.configure do |config|
4
+ if config.files_to_run.one?
5
+ config.default_formatter = 'doc'
6
+ end
7
+
8
+ config.order = :random
9
+
10
+ config.expect_with :rspec do |expectations|
11
+ expectations.syntax = :expect
12
+ end
13
+
14
+ config.mock_with :rspec do |mocks|
15
+ mocks.syntax = :expect
16
+
17
+ mocks.verify_partial_doubles = true
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adjutant
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Baltazore
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby Gem that parse patch data for comments and ToDo lists and paste
84
+ them on GitHub PR.
85
+ email:
86
+ - baltazore92@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - adjutant.gemspec
98
+ - lib/adjutant.rb
99
+ - lib/adjutant/comment.rb
100
+ - lib/adjutant/file_parser.rb
101
+ - lib/adjutant/line.rb
102
+ - lib/adjutant/version.rb
103
+ - spec/adjutant/comment_spec.rb
104
+ - spec/adjutant/file_parser_spec.rb
105
+ - spec/adjutant/line_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: http://baltazore.github.io/adjutant
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Gem that help parse git patch data
131
+ test_files:
132
+ - spec/adjutant/comment_spec.rb
133
+ - spec/adjutant/file_parser_spec.rb
134
+ - spec/adjutant/line_spec.rb
135
+ - spec/spec_helper.rb
136
+ has_rdoc: