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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32afa53492ee02c977a4c7def6376ff63f1789af
4
- data.tar.gz: c62b2494b9f26207d368e4788b432e971c0f81c5
3
+ metadata.gz: cd8b0fda3d023e477bd597284d3e03929203c630
4
+ data.tar.gz: c288acc2abfe04edfaf9019ab9a88e6e31ff1546
5
5
  SHA512:
6
- metadata.gz: 4ccaf764dfd8eb44ac04dfd5e48d65c119ef98c0a1388cb2936450bc9d7f644a8c32714b8ee9b8a43d94868ce342aa9553dc834b5952f860737dbf25250ad30b
7
- data.tar.gz: 94ee6628d7ac7443f4992afc3ae0a0694dfa00d16580edd5d86c3a00996dbe1c890de2386e092ed7c7826c50cfe6e62923efeeaec491d7cb121aabe859f82b64
6
+ metadata.gz: fb4693ed64d9c46496d2df7414613609120b56dc3673b97729dd4dcb6fc2866624f1b49c800575562634fff7e7dc824a0bf22db2f77c7766d2a205828a4695ce
7
+ data.tar.gz: ea08d936438b0af186d709736166b88043a0487acf100ca6f0af2d51a5b4b676f3e2ba537c1ed2e83eb3afb7f01d679546198c11e95dee8d29f4852dff201a51
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # pronto
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/mmozuras/pronto.png)](https://codeclimate.com/github/mmozuras/pronto)
3
4
  [![Build Status](https://secure.travis-ci.org/mmozuras/pronto.png)](http://travis-ci.org/mmozuras/pronto)
5
+ [![Dependency Status](https://gemnasium.com/mmozuras/pronto.png)](https://gemnasium.com/mmozuras/pronto)
6
+
4
7
 
5
8
  ## Usage
6
9
 
@@ -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(commit1 = nil, commit2 = 'master', repo_path = '.')
14
- patches = diff(repo_path, commit1, commit2)
20
+ def self.run(commit = 'master', repo_path = '.', formatter = nil)
21
+ patches = diff(repo_path, commit)
15
22
  result = run_all_runners(patches)
16
- Formatter::TextFormatter.new.format(result)
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, commit1, commit2)
45
+ def self.diff(repo_path, commit)
37
46
  repo = Rugged::Repository.new(repo_path)
38
- commit1 ||= repo.head.target
39
- commit2 ||= 'master'
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
@@ -7,17 +7,11 @@ module Pronto
7
7
 
8
8
  desc 'exec', 'Run Pronto'
9
9
 
10
- method_option :commit1,
10
+ method_option :commit,
11
11
  type: :string,
12
12
  default: nil,
13
- aliases: '-f',
14
- banner: 'First commit for the diff, defaults to current HEAD'
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
- puts ::Pronto.run(options[:commit1], options[:commit2])
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
@@ -11,5 +11,9 @@ module Pronto
11
11
 
12
12
  @path, @line, @level, @msg = path, line, level, msg
13
13
  end
14
+
15
+ def repo
16
+ line.patch.delta.repo
17
+ end
14
18
  end
15
19
  end
@@ -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 create_tempfiles(blobs)
12
- return [] if blobs.nil?
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 write(blob)
50
- return if blob.nil?
51
-
52
- file = Tempfile.new(blob.oid)
53
- file.write(blob.text)
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
@@ -1,3 +1,3 @@
1
1
  module Pronto
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -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
- private
17
-
18
- def blob(file)
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,9 @@
1
+ module Rugged
2
+ class Diff
3
+ class Line
4
+ def patch
5
+ hunk.owner
6
+ end
7
+ end
8
+ end
9
+ 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
@@ -0,0 +1,8 @@
1
+ module Rugged
2
+ class Remote
3
+ def github_slug
4
+ match = /.*github.com(:|\/)(?<slug>.*).git/.match(url)
5
+ match[:slug] if match
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ require 'grit'
2
+
3
+ module Rugged
4
+ class Repository
5
+ def blame(filepath)
6
+ # TODO: Using grit blame implementation for now.
7
+ # Replace it with rugged implementation when it's available.
8
+ ::Grit::Repo.new(path).blame(filepath)
9
+ end
10
+ end
11
+ 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.2
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-01 00:00:00.000000000 Z
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.13.0
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.13.0
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: