inspected_by 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.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle
2
+ /coverage
3
+ /db/*.sqlite3
4
+ /db/*.sqlite3-journal
5
+ /log/*.log
6
+ /tmp
7
+ *.gem
8
+ .DS_Store
9
+ .coco
10
+ .rbenv*
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ inspected_by (0.0.1)
5
+ grit
6
+ simple_uuid
7
+ sinatra
8
+ sinatra-partial
9
+ slim
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ coderay (1.0.7)
15
+ diff-lcs (1.1.3)
16
+ grit (2.5.0)
17
+ diff-lcs (~> 1.1)
18
+ mime-types (~> 1.15)
19
+ posix-spawn (~> 0.3.6)
20
+ method_source (0.8)
21
+ mime-types (1.19)
22
+ posix-spawn (0.3.6)
23
+ pry (0.9.10)
24
+ coderay (~> 1.0.5)
25
+ method_source (~> 0.8)
26
+ slop (~> 3.3.1)
27
+ rack (1.4.1)
28
+ rack-protection (1.2.0)
29
+ rack
30
+ rake (0.9.2.2)
31
+ simple_uuid (0.2.0)
32
+ sinatra (1.3.3)
33
+ rack (~> 1.3, >= 1.3.6)
34
+ rack-protection (~> 1.2)
35
+ tilt (~> 1.3, >= 1.3.3)
36
+ sinatra-partial (0.3.2)
37
+ sinatra
38
+ slim (1.3.3)
39
+ temple (~> 0.5.5)
40
+ tilt (~> 1.3.3)
41
+ slop (3.3.3)
42
+ temple (0.5.5)
43
+ tilt (1.3.3)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ inspected_by!
50
+ pry
51
+ rake
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Inspected By
2
+
3
+ This is a Sinatra-based experiment for Inspected By.
4
+
5
+ The Junto will attempt to make it entirely Git-centric without need of a database.
6
+
7
+ ## Learn
8
+
9
+ Inspected By uses the [git-notes](http://www.kernel.org/pub/software/scm/git/docs/git-notes.html) feature of Git.
10
+
11
+ Here are some resources to get up to speed:
12
+
13
+ * [Note to Self](http://git-scm.com/2010/08/25/notes.html)
14
+ * [Git Notes & GitHub](https://vimeo.com/34273537)
15
+ * [Git Notes Display](https://github.com/blog/707-git-notes-display)
16
+ * [Git Tip of the Week: Git Notes](http://alblue.bandlem.com/2011/11/git-tip-of-week-git-notes.html)
17
+ * [git-notes Manual Page](http://www.kernel.org/pub/software/scm/git/docs/git-notes.html)
18
+
19
+ ## Development
20
+
21
+ ### Dependencies
22
+
23
+ * Ruby
24
+ * Bundler
25
+
26
+ ### Getting started
27
+
28
+ ```sh
29
+ git clone git@github.com:highgroove/inspected-by.git
30
+ cd inspected-by
31
+ bundle install
32
+ ```
33
+
34
+ ### Starting up
35
+
36
+ ```sh
37
+ bin/inspected_by --server [PORT] [--repo /Path/to/repo]
38
+ ```
39
+
40
+ Visit http://localhost:4000
41
+
42
+ ### Console
43
+
44
+ ```sh
45
+ irb -r ./lib/inspected_by.rb
46
+ ```
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ task default: :test
2
+ require 'rake/testtask'
3
+ Rake::TestTask.new(:test) do |test|
4
+ test.libs += %w(lib test .)
5
+ test.pattern = 'test/**/*_test.rb'
6
+ test.verbose = true
7
+ end
data/bin/inspected_by ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w(.. lib))
4
+
5
+ require 'optparse'
6
+ require 'inspected_by'
7
+
8
+ options = {
9
+ port: 4000
10
+ }
11
+
12
+ option_parser = OptionParser.new do |opts|
13
+ opts.on('--repo PATH', 'Repository path') do |repo_path|
14
+ ENV['INSPECTED_BY_REPO_PATH'] = repo_path
15
+ end
16
+
17
+ opts.on('--server [PORT]', 'Start web server (default port 4000)') do |port|
18
+ options[:server] = true
19
+ options[:port] = port unless port.nil?
20
+ end
21
+ end
22
+
23
+ option_parser.parse!
24
+
25
+ InspectedBy::Server.run!(port: options[:port]) if options[:server]
@@ -0,0 +1,45 @@
1
+ $LOAD_PATH.unshift 'lib'
2
+ require 'inspected_by/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'inspected_by'
6
+ s.version = InspectedBy::VERSION.dup
7
+ s.summary = 'Code reviews using Git'
8
+ s.description = 'InspectedBy is a code review tool based on Git'
9
+ s.homepage = 'http://inspected.by'
10
+ s.email = 'hello@inspected.by'
11
+ s.authors = ['Zac Stewart', 'Brandon Beacher']
12
+
13
+ s.require_paths = ['lib']
14
+ s.executables = ['inspected_by']
15
+
16
+ s.add_runtime_dependency 'grit'
17
+ s.add_runtime_dependency 'simple_uuid'
18
+ s.add_runtime_dependency 'slim'
19
+ s.add_runtime_dependency 'sinatra'
20
+ s.add_runtime_dependency 'sinatra-partial'
21
+
22
+ s.add_development_dependency 'rake'
23
+ s.add_development_dependency 'pry'
24
+
25
+ s.files = %w(
26
+ .gitignore
27
+ Gemfile
28
+ Gemfile.lock
29
+ README.md
30
+ Rakefile
31
+ bin/inspected_by
32
+ inspected_by.gemspec
33
+ lib/inspected_by.rb
34
+ lib/inspected_by/core.rb
35
+ lib/inspected_by/server.rb
36
+ lib/inspected_by/server/views/branches.slim
37
+ lib/inspected_by/server/views/commit.slim
38
+ lib/inspected_by/server/views/commits.slim
39
+ lib/inspected_by/server/views/layout.slim
40
+ lib/inspected_by/server/views/note.slim
41
+ lib/inspected_by/version.rb
42
+ test/helper.rb
43
+ test/inspection_test.rb
44
+ )
45
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ # default to current dir for repo
4
+ ENV['INSPECTED_BY_REPO_PATH'] ||= File.expand_path('.')
5
+
6
+ require 'rubygems'
7
+
8
+ # internals
9
+ require 'inspected_by/version'
10
+ require 'inspected_by/core'
11
+ require 'inspected_by/server'
12
+
13
+ module InspectedBy
14
+ end
@@ -0,0 +1,109 @@
1
+ # stdlib
2
+ require 'json'
3
+
4
+ # 3rd party
5
+ require 'grit'
6
+ require 'simple_uuid'
7
+
8
+ module InspectedBy
9
+ REPO = Grit::Repo.new(ENV['INSPECTED_BY_REPO_PATH'])
10
+
11
+ class Decorator
12
+ def initialize(object)
13
+ @object = object
14
+ end
15
+
16
+ def self.decorates(klass)
17
+ define_method(klass) { @object }
18
+ end
19
+
20
+ def self.decorate(objects)
21
+ objects.map(&method(:new))
22
+ end
23
+
24
+ def self.method_missing(method, *args, &block)
25
+ @object.send method, *args, &block
26
+ end
27
+
28
+ def method_missing(method, *args, &block)
29
+ @object.send method, *args, &block
30
+ end
31
+ end
32
+
33
+ class DiffDecorator < Decorator
34
+ decorates :diff
35
+
36
+ def lines
37
+ lines = diff.diff.split("\n").drop(2)
38
+ LineDecorator.decorate(lines)
39
+ end
40
+ end
41
+
42
+ class LineDecorator < Decorator
43
+ decorates :line
44
+
45
+ def type
46
+ case line
47
+ when /^@@.*@@$/
48
+ 'context'
49
+ when /^\+/
50
+ 'add'
51
+ when /^-/
52
+ 'remove'
53
+ end
54
+ end
55
+
56
+ def to_s
57
+ line.force_encoding('UTF-8')
58
+ end
59
+ end
60
+
61
+ class Inspection
62
+ attr_reader :comment, :inspected_at, :inspector_email, :inspector_name, :guid, :sha
63
+
64
+ def initialize(repo, params)
65
+ @repo = repo
66
+ @comment = params['comment']
67
+ @inspected_at = params['inspected_at']
68
+ @inspector_email = params['inspector_email']
69
+ @inspector_name = params['inspector_name']
70
+ @guid = params['guid']
71
+ @sha = params['sha']
72
+ end
73
+
74
+ def self.find_all(repo, sha)
75
+ repo.git.notes({raise: true, ref: 'inspected-by'}, ['show', sha]).
76
+ split("\n").
77
+ map {|note| Inspection.new(repo, JSON.parse(note)) }
78
+ rescue Grit::Git::CommandFailed => e
79
+ if /No note found for object/ === e.message
80
+ []
81
+ else
82
+ raise e
83
+ end
84
+ end
85
+
86
+ def append
87
+ @repo.git.notes({raise: true, ref: 'inspected-by'},
88
+ ['append', "--message=#{shell_escaped_message}", @sha])
89
+ end
90
+
91
+ private
92
+
93
+ def shell_escaped_message
94
+ @repo.git.shell_escape(message)
95
+ end
96
+
97
+ def message
98
+ JSON.generate(
99
+ 'inspected_by' => true,
100
+ 'inspected_at' => Time.now.utc,
101
+ 'inspector_email' => @repo.config['user.email'],
102
+ 'inspector_name' => @repo.config['user.name'],
103
+ 'guid' => @guid || SimpleUUID::UUID.new.to_guid,
104
+ 'inspected_sha' => @sha,
105
+ 'comment' => @comment
106
+ )
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,47 @@
1
+ require 'sinatra/base'
2
+ require 'sinatra/partial'
3
+ require 'slim'
4
+
5
+ module InspectedBy
6
+ class Server < Sinatra::Base
7
+ dir = File.dirname(File.expand_path(__FILE__))
8
+ set :views, File.join(dir, %w(server views))
9
+
10
+ register Sinatra::Partial
11
+ set :partial_template_engine, :slim
12
+
13
+ def repo
14
+ @_repo ||= REPO
15
+ end
16
+
17
+ get '/' do
18
+ redirect to('/branches/master/commits')
19
+ end
20
+
21
+ get '/branches' do
22
+ @branches = repo.branches
23
+ slim :branches
24
+ end
25
+
26
+ get '/branches/:branch/commits' do
27
+ @commits = repo.commits(params[:branch])
28
+ slim :commits
29
+ end
30
+
31
+ get '/branches/:branch/commits/:sha' do
32
+ @commit = repo.commit(params[:sha])
33
+ @notes = Inspection.find_all(repo, @commit.sha)
34
+ @diffs = DiffDecorator.decorate(@commit.diffs)
35
+ slim :commit
36
+ end
37
+
38
+ post '/branches/:branch/commits/:sha/notes' do
39
+ inspection = Inspection.new(repo, params[:inspection])
40
+ inspection.append
41
+
42
+ redirect "/branches/#{params[:branch]}/commits/#{params[:sha]}"
43
+ end
44
+
45
+ run! if app_file == $0
46
+ end
47
+ end
@@ -0,0 +1,6 @@
1
+ h1 Branches
2
+ ul
3
+ - @branches.each do |branch|
4
+ li
5
+ h2
6
+ a(href="/branches/#{branch.name}/commits")= branch.name
@@ -0,0 +1,31 @@
1
+ h2
2
+ a(href="/branches") Branches
3
+ | /
4
+ a(href="/branches/#{params[:branch]}/commits")= params[:branch]
5
+ header
6
+ h1= @commit.sha
7
+ h2 #{@commit.date} by #{@commit.author}
8
+
9
+ section.message
10
+ p= @commit.message
11
+
12
+ section.diffs
13
+ h3 Diffs
14
+ ul
15
+ - @diffs.each do |diff|
16
+ li
17
+ #{diff.a_path} → #{diff.b_path}
18
+ pre.diff
19
+ - diff.lines.each do |line|
20
+ .line(class=line.type)= line
21
+
22
+ section.commit_notes
23
+ h3 Notes
24
+ == partial :note, collection: @notes
25
+
26
+ form action="/branches/#{params[:branch]}/commits/#{@commit.sha}/notes" method="post"
27
+ input type="hidden" name="inspection[sha]" value=params[:sha]
28
+ p
29
+ textarea name="inspection[comment]" cols="40" rows="5"
30
+ p
31
+ input type="submit"
@@ -0,0 +1,11 @@
1
+ h2
2
+ a(href="/branches") Branches
3
+ | /
4
+ span= params[:branch]
5
+ h1 Commits
6
+ ul
7
+ - @commits.each do |commit|
8
+ li
9
+ h2 #{commit.date} by #{commit.author}
10
+ a(href="/branches/#{params[:branch]}/commits/#{commit.sha}")= commit.sha
11
+ blockquote= commit.message
@@ -0,0 +1,9 @@
1
+ html
2
+ head
3
+ title Inspected By
4
+ style
5
+ | .diff .add { color: green; }
6
+ | .diff .remove { color: red; }
7
+ | .diff .context { color: blue; }
8
+ body
9
+ == yield
@@ -0,0 +1,6 @@
1
+ article
2
+ header
3
+ datetime= note.inspected_at
4
+ ' by
5
+ em= note.inspector_name
6
+ = note.comment
@@ -0,0 +1,3 @@
1
+ module InspectedBy
2
+ VERSION = '0.0.2'.freeze
3
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'test/unit'
2
+ require 'fileutils'
3
+ require 'pry'
4
+ require File.join(File.dirname(__FILE__), *%w(.. lib inspected_by))
5
+ include InspectedBy
6
+
7
+ class GitFactory
8
+ def self.repo(&block)
9
+ Dir.chdir(Dir.mktmpdir('inspected_by')) do |path|
10
+ repo = Grit::Repo.init(path, template: File.join(*%w('test data repo_template')))
11
+ block.call(repo)
12
+ end
13
+ end
14
+
15
+ def self.commit_with_no_inspections(&block)
16
+ repo do |repo|
17
+ file = File.new('README', 'w')
18
+ file.write('INSPECTED BY TEST REPO')
19
+ file.close
20
+ repo.add('README')
21
+ repo.commit_index('Add project name to repo')
22
+ block.call(repo, repo.commits.first)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ class InspectionTest < Test::Unit::TestCase
4
+ def setup
5
+ end
6
+
7
+ def teardown
8
+ end
9
+
10
+ def test_find_all_on_commit_with_no_notes
11
+ GitFactory.commit_with_no_inspections do |repo, commit|
12
+ inspections = Inspection.find_all(repo, commit.sha)
13
+ assert_equal inspections, []
14
+ end
15
+ end
16
+
17
+ def test_appending_a_note_to_a_commit
18
+ comment = 'You should add more information'
19
+ GitFactory.commit_with_no_inspections do |repo, commit|
20
+ Inspection.new(repo,
21
+ 'sha' => commit.sha,
22
+ 'comment' => comment).append
23
+ assert Inspection.find_all(repo, commit.sha).length > 0
24
+
25
+ inspection = Inspection.find_all(repo, commit.sha).first
26
+ assert_equal inspection.comment, comment
27
+ assert_equal inspection.inspector_email, repo.config['user.email']
28
+ assert_equal inspection.inspector_name, repo.config['user.name']
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inspected_by
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zac Stewart
9
+ - Brandon Beacher
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-10-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: grit
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: simple_uuid
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: slim
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: sinatra
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: sinatra-partial
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :runtime
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rake
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ description: InspectedBy is a code review tool based on Git
128
+ email: hello@inspected.by
129
+ executables:
130
+ - inspected_by
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - README.md
138
+ - Rakefile
139
+ - bin/inspected_by
140
+ - inspected_by.gemspec
141
+ - lib/inspected_by.rb
142
+ - lib/inspected_by/core.rb
143
+ - lib/inspected_by/server.rb
144
+ - lib/inspected_by/server/views/branches.slim
145
+ - lib/inspected_by/server/views/commit.slim
146
+ - lib/inspected_by/server/views/commits.slim
147
+ - lib/inspected_by/server/views/layout.slim
148
+ - lib/inspected_by/server/views/note.slim
149
+ - lib/inspected_by/version.rb
150
+ - test/helper.rb
151
+ - test/inspection_test.rb
152
+ homepage: http://inspected.by
153
+ licenses: []
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 1.8.24
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: Code reviews using Git
176
+ test_files: []
177
+ has_rdoc: