pronto 0.0.2 → 0.1.0
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 +4 -4
- data/README.md +3 -0
- data/lib/pronto.rb +20 -8
- data/lib/pronto/cli.rb +23 -12
- data/lib/pronto/formatter/formatter.rb +18 -0
- data/lib/pronto/formatter/github_formatter.rb +42 -0
- data/lib/pronto/formatter/json_formatter.rb +18 -0
- data/lib/pronto/message.rb +4 -0
- data/lib/pronto/runner.rb +7 -42
- data/lib/pronto/version.rb +1 -1
- data/lib/rugged/diff/delta.rb +3 -15
- data/lib/rugged/diff/line.rb +9 -0
- data/lib/rugged/diff/patch.rb +23 -0
- data/lib/rugged/remote.rb +8 -0
- data/lib/rugged/repository.rb +11 -0
- metadata +40 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd8b0fda3d023e477bd597284d3e03929203c630
|
4
|
+
data.tar.gz: c288acc2abfe04edfaf9019ab9a88e6e31ff1546
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb4693ed64d9c46496d2df7414613609120b56dc3673b97729dd4dcb6fc2866624f1b49c800575562634fff7e7dc824a0bf22db2f77c7766d2a205828a4695ce
|
7
|
+
data.tar.gz: ea08d936438b0af186d709736166b88043a0487acf100ca6f0af2d51a5b4b676f3e2ba537c1ed2e83eb3afb7f01d679546198c11e95dee8d29f4852dff201a51
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# pronto
|
2
2
|
|
3
|
+
[](https://codeclimate.com/github/mmozuras/pronto)
|
3
4
|
[](http://travis-ci.org/mmozuras/pronto)
|
5
|
+
[](https://gemnasium.com/mmozuras/pronto)
|
6
|
+
|
4
7
|
|
5
8
|
## Usage
|
6
9
|
|
data/lib/pronto.rb
CHANGED
@@ -1,19 +1,28 @@
|
|
1
1
|
require 'rugged'
|
2
2
|
require_relative 'rugged/diff'
|
3
|
-
require_relative 'rugged/tree'
|
4
3
|
require_relative 'rugged/diff/delta'
|
4
|
+
require_relative 'rugged/diff/patch'
|
5
|
+
require_relative 'rugged/diff/line'
|
6
|
+
require_relative 'rugged/tree'
|
7
|
+
require_relative 'rugged/remote'
|
8
|
+
require_relative 'rugged/repository'
|
5
9
|
|
6
10
|
require 'pronto/plugin'
|
7
11
|
require 'pronto/message'
|
8
12
|
require 'pronto/runner'
|
9
13
|
|
10
14
|
require 'pronto/formatter/text_formatter'
|
15
|
+
require 'pronto/formatter/json_formatter'
|
16
|
+
require 'pronto/formatter/github_formatter'
|
17
|
+
require 'pronto/formatter/formatter'
|
11
18
|
|
12
19
|
module Pronto
|
13
|
-
def self.run(
|
14
|
-
patches = diff(repo_path,
|
20
|
+
def self.run(commit = 'master', repo_path = '.', formatter = nil)
|
21
|
+
patches = diff(repo_path, commit)
|
15
22
|
result = run_all_runners(patches)
|
16
|
-
|
23
|
+
|
24
|
+
formatter ||= default_formatter
|
25
|
+
formatter.format(result)
|
17
26
|
end
|
18
27
|
|
19
28
|
def self.gem_names
|
@@ -33,11 +42,10 @@ module Pronto
|
|
33
42
|
|
34
43
|
private
|
35
44
|
|
36
|
-
def self.diff(repo_path,
|
45
|
+
def self.diff(repo_path, commit)
|
37
46
|
repo = Rugged::Repository.new(repo_path)
|
38
|
-
|
39
|
-
|
40
|
-
repo.diff(commit1, commit2)
|
47
|
+
commit ||= 'master'
|
48
|
+
repo.diff(commit, repo.head.target)
|
41
49
|
end
|
42
50
|
|
43
51
|
def self.run_all_runners(patches)
|
@@ -45,4 +53,8 @@ module Pronto
|
|
45
53
|
runner.new.run(patches)
|
46
54
|
end.flatten.compact
|
47
55
|
end
|
56
|
+
|
57
|
+
def default_formatter
|
58
|
+
Formatter::TextFormatter.new
|
59
|
+
end
|
48
60
|
end
|
data/lib/pronto/cli.rb
CHANGED
@@ -7,17 +7,11 @@ module Pronto
|
|
7
7
|
|
8
8
|
desc 'exec', 'Run Pronto'
|
9
9
|
|
10
|
-
method_option :
|
10
|
+
method_option :commit,
|
11
11
|
type: :string,
|
12
12
|
default: nil,
|
13
|
-
aliases: '-
|
14
|
-
banner: '
|
15
|
-
|
16
|
-
method_option :commit2,
|
17
|
-
type: :string,
|
18
|
-
default: nil,
|
19
|
-
aliases: '-s',
|
20
|
-
banner: 'Second commit for the diff, defaults to master'
|
13
|
+
aliases: '-c',
|
14
|
+
banner: 'Commit for the diff, defaults to master'
|
21
15
|
|
22
16
|
method_option :runner,
|
23
17
|
type: :array,
|
@@ -25,17 +19,34 @@ module Pronto
|
|
25
19
|
aliases: '-r',
|
26
20
|
banner: 'Run only the passed runners'
|
27
21
|
|
22
|
+
method_option :formatter,
|
23
|
+
type: :string,
|
24
|
+
default: nil,
|
25
|
+
aliases: '-f',
|
26
|
+
banner: "Formatter, defaults to text. Available: #{::Pronto::Formatter.names.join(', ')}"
|
27
|
+
|
28
|
+
method_option :access_token,
|
29
|
+
type: :string,
|
30
|
+
default: nil,
|
31
|
+
aliases: '-t',
|
32
|
+
banner: 'Github access token, used for github formatter'
|
33
|
+
|
28
34
|
def exec
|
29
35
|
gem_names = options[:runner].any? ? options[:runner]
|
30
36
|
: ::Pronto.gem_names
|
31
37
|
gem_names.each do |gem_name|
|
32
38
|
require "pronto/#{gem_name}"
|
33
39
|
end
|
34
|
-
|
40
|
+
|
41
|
+
formatter = ::Pronto::Formatter.get(options[:formatter])
|
42
|
+
if formatter.is_a? ::Pronto::Formatter::GithubFormatter
|
43
|
+
access_token = options[:access_token]
|
44
|
+
formatter.client = Octokit::Client.new(access_token: access_token)
|
45
|
+
end
|
46
|
+
|
47
|
+
puts ::Pronto.run(options[:commit], '.', formatter)
|
35
48
|
rescue Rugged::RepositoryError
|
36
49
|
puts '"pronto" should be run from a git repository'
|
37
|
-
rescue => e
|
38
|
-
puts e.message
|
39
50
|
end
|
40
51
|
|
41
52
|
desc 'list', 'Lists pronto runners that are available to be used'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Pronto
|
2
|
+
module Formatter
|
3
|
+
def self.get(name)
|
4
|
+
formatter = FORMATTERS[name.to_s] || TextFormatter
|
5
|
+
formatter.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.names
|
9
|
+
FORMATTERS.keys
|
10
|
+
end
|
11
|
+
|
12
|
+
FORMATTERS = {
|
13
|
+
'github' => GithubFormatter,
|
14
|
+
'json' => JsonFormatter,
|
15
|
+
'text' => TextFormatter
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
|
3
|
+
module Pronto
|
4
|
+
module Formatter
|
5
|
+
class GithubFormatter
|
6
|
+
attr_writer :client
|
7
|
+
|
8
|
+
def format(messages)
|
9
|
+
messages.each do |message|
|
10
|
+
@client.create_commit_comment(github_slug(message),
|
11
|
+
sha(message),
|
12
|
+
message.msg,
|
13
|
+
message.path,
|
14
|
+
message.line.new_lineno)
|
15
|
+
end
|
16
|
+
|
17
|
+
"#{messages.count} pronto messages posted to GitHub"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def github_slug(message)
|
23
|
+
message.repo.remotes.map(&:github_slug).compact.first
|
24
|
+
end
|
25
|
+
|
26
|
+
def sha(message)
|
27
|
+
blamelines = blame(message).lines
|
28
|
+
lineno = message.line.new_lineno
|
29
|
+
|
30
|
+
blameline = blamelines.detect { |line| line.lineno == lineno }
|
31
|
+
|
32
|
+
blameline.commit.id if blameline
|
33
|
+
end
|
34
|
+
|
35
|
+
def blame(message)
|
36
|
+
@blames ||= {}
|
37
|
+
@blames[message.path] ||= message.repo.blame(message.path)
|
38
|
+
@blames[message.path]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Pronto
|
4
|
+
module Formatter
|
5
|
+
class JsonFormatter
|
6
|
+
def format(messages)
|
7
|
+
messages.map do |message|
|
8
|
+
{
|
9
|
+
path: message.path,
|
10
|
+
line: message.line.new_lineno,
|
11
|
+
level: message.level[0].upcase,
|
12
|
+
message: message.msg
|
13
|
+
}
|
14
|
+
end.to_json
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/pronto/message.rb
CHANGED
data/lib/pronto/runner.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
|
3
1
|
module Pronto
|
4
2
|
class Runner
|
5
3
|
include Plugin
|
@@ -8,50 +6,17 @@ module Pronto
|
|
8
6
|
repository
|
9
7
|
end
|
10
8
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
files = blobs.map { |blob| write(blob) }.compact
|
15
|
-
return [] if files.empty?
|
16
|
-
|
17
|
-
begin
|
18
|
-
if block_given?
|
19
|
-
files.each(&:flush)
|
20
|
-
yield(files)
|
21
|
-
else
|
22
|
-
files
|
23
|
-
end
|
24
|
-
ensure
|
25
|
-
files.each do |file|
|
26
|
-
file.close unless file.closed?
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def create_tempfile(blob)
|
32
|
-
file = write(blob)
|
33
|
-
return if file.nil?
|
34
|
-
|
35
|
-
begin
|
36
|
-
if block_given?
|
37
|
-
file.flush
|
38
|
-
yield(file)
|
39
|
-
else
|
40
|
-
file
|
41
|
-
end
|
42
|
-
ensure
|
43
|
-
file.close if file && !file.closed?
|
44
|
-
end
|
9
|
+
def ruby_file?(path)
|
10
|
+
File.extname(path) == '.rb' || ruby_executable?(path)
|
45
11
|
end
|
46
12
|
|
47
13
|
private
|
48
14
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
file
|
15
|
+
def ruby_executable?(path)
|
16
|
+
line = File.open(path) { |file| file.readline }
|
17
|
+
line =~ /#!.*ruby/
|
18
|
+
rescue ArgumentError, EOFError
|
19
|
+
false
|
55
20
|
end
|
56
21
|
end
|
57
22
|
end
|
data/lib/pronto/version.rb
CHANGED
data/lib/rugged/diff/delta.rb
CHANGED
@@ -1,25 +1,13 @@
|
|
1
1
|
module Rugged
|
2
2
|
class Diff
|
3
3
|
class Delta
|
4
|
-
def new_blob
|
5
|
-
blob(new_file)
|
6
|
-
end
|
7
|
-
|
8
|
-
def old_blob
|
9
|
-
blob(old_file)
|
10
|
-
end
|
11
|
-
|
12
4
|
def repo
|
13
5
|
diff.tree.repo
|
14
6
|
end
|
15
7
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
return if file.nil?
|
20
|
-
return if file[:oid] == '0000000000000000000000000000000000000000'
|
21
|
-
|
22
|
-
repo.lookup(file[:oid])
|
8
|
+
def new_file_full_path
|
9
|
+
repo_path = Pathname.new(repo.path).parent
|
10
|
+
repo_path.join(new_file[:path])
|
23
11
|
end
|
24
12
|
end
|
25
13
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rugged
|
2
|
+
class Diff
|
3
|
+
class Patch
|
4
|
+
def added_lines
|
5
|
+
lines.select(&:addition?)
|
6
|
+
end
|
7
|
+
|
8
|
+
def deleted_lines
|
9
|
+
lines.select(&:deletion?)
|
10
|
+
end
|
11
|
+
|
12
|
+
def new_file_full_path
|
13
|
+
delta.new_file_full_path
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def lines
|
19
|
+
map(&:lines).flatten.compact
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pronto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mindaugas Mozūras
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rugged
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.18.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: octokit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.1.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.1.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: grit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.5.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.5.0
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rake
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +86,14 @@ dependencies:
|
|
58
86
|
requirements:
|
59
87
|
- - ~>
|
60
88
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2.
|
89
|
+
version: 2.14.0
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
94
|
- - ~>
|
67
95
|
- !ruby/object:Gem::Version
|
68
|
-
version: 2.
|
96
|
+
version: 2.14.0
|
69
97
|
description: pronto
|
70
98
|
email: mindaugas.mozuras@gmail.com
|
71
99
|
executables:
|
@@ -74,6 +102,9 @@ extensions: []
|
|
74
102
|
extra_rdoc_files: []
|
75
103
|
files:
|
76
104
|
- lib/pronto/cli.rb
|
105
|
+
- lib/pronto/formatter/formatter.rb
|
106
|
+
- lib/pronto/formatter/github_formatter.rb
|
107
|
+
- lib/pronto/formatter/json_formatter.rb
|
77
108
|
- lib/pronto/formatter/text_formatter.rb
|
78
109
|
- lib/pronto/message.rb
|
79
110
|
- lib/pronto/plugin.rb
|
@@ -81,7 +112,11 @@ files:
|
|
81
112
|
- lib/pronto/version.rb
|
82
113
|
- lib/pronto.rb
|
83
114
|
- lib/rugged/diff/delta.rb
|
115
|
+
- lib/rugged/diff/line.rb
|
116
|
+
- lib/rugged/diff/patch.rb
|
84
117
|
- lib/rugged/diff.rb
|
118
|
+
- lib/rugged/remote.rb
|
119
|
+
- lib/rugged/repository.rb
|
85
120
|
- lib/rugged/tree.rb
|
86
121
|
- LICENSE
|
87
122
|
- README.md
|
@@ -111,3 +146,4 @@ signing_key:
|
|
111
146
|
specification_version: 4
|
112
147
|
summary: pronto
|
113
148
|
test_files: []
|
149
|
+
has_rdoc:
|