ottinfra-codereview 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 68d0838e00866f44102efc32189888ec7e468290
4
+ data.tar.gz: bb29714474d07523ad8a9f7e7b61569e14bd3c7e
5
+ SHA512:
6
+ metadata.gz: 2b70ca32040ede6b08e052e9e088d12a7135759d227185b50d4533290fd21125e04a4352e0cda3272fc85493d281f80d30dbe56e9856a8c70e862fbd2f4d55dc
7
+ data.tar.gz: 57a73769922a8a6ebe51d5642b205264dc8dd79a30baeefec9f6db50351265c1fd45b552b47112794a659390f5ca5e8740a5369c1b6cae8551f2703fac634898
@@ -0,0 +1,13 @@
1
+ *.gem
2
+ .bundle
3
+ .yardoc
4
+ Gemfile.lock
5
+ _yardoc
6
+ coverage
7
+ doc
8
+ pkg
9
+ spec/reports
10
+ tmp
11
+ *.swp
12
+ *.swo
13
+ rspec.xml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.8
4
+ - 2.2.4
5
+ - 2.3.0
6
+ before_install: gem install bundler -v 1.10.6
7
+ addons:
8
+ code_climate:
9
+ repo_token: dc1fbb0bce3076f8cb0fd869e59e95045bac20e983702ad152eafe8e9cdc4166
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'git', git: 'https://github.com/onetwotrip/ruby-git.git'
4
+ gem 'ottinfra-sendmail', git: 'https://github.com/onetwotrip/ott_infra-sendmail.git'
5
+ gem "codeclimate-test-reporter", group: :test, require: nil
6
+
7
+ # Specify your gem's dependencies in ott_infra-codereview.gemspec
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2016 Dmitry Shmelev
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # OttInfra::Codereview
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ott_infra/codereview`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Code Status
6
+
7
+ * [![Build Status](https://travis-ci.org/onetwotrip/ott_infra-codereview.svg?branch=master)](https://travis-ci.org/onetwotrip/ott_infra-codereview)
8
+ * [![Code Climate](https://codeclimate.com/github/onetwotrip/ott_infra-codereview/badges/gpa.svg)](https://codeclimate.com/github/onetwotrip/ott_infra-codereview)
9
+ * [![Test Coverage](https://codeclimate.com/github/onetwotrip/ott_infra-codereview/badges/coverage.svg)](https://codeclimate.com/github/onetwotrip/ott_infra-codereview/coverage)
10
+ * [![Issue Count](https://codeclimate.com/github/onetwotrip/ott_infra-codereview/badges/issue_count.svg)](https://codeclimate.com/github/onetwotrip/ott_infra-codereview)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'ottinfra-codereview'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install ottinfra-codereview
27
+
28
+ ## Usage
29
+
30
+ TODO: Write usage instructions here
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/onetwotrip/ottinfra-codereview.
41
+
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:test) do |t|
5
+ t.pattern = Dir.glob('spec/**/*_spec.rb')
6
+ # t.rcov = true
7
+ end
8
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ottinfra/codereview"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,76 @@
1
+ require 'ottinfra/codereview/version'
2
+ require 'ottinfra/sendmail'
3
+ require 'git'
4
+
5
+ module OttInfra
6
+ class CodeReview
7
+
8
+ def initialize
9
+ @g = Git.open( find_git_root )
10
+ end
11
+
12
+ def self.run
13
+ codereview = self.new
14
+ review = codereview.get_review_info
15
+ unless review[:reviewers].nil?
16
+ OttInfra::SendMail.new.send(
17
+ review[:reviewers],
18
+ subject: "CodeReview",
19
+ message: "Message",
20
+ attach: [review[:patch]] )
21
+ end
22
+ end
23
+
24
+ def get_review_info
25
+ {
26
+ :author => get_author,
27
+ :reviewers => get_reviewers,
28
+ :patch => get_patch
29
+ }
30
+ end
31
+
32
+ private
33
+
34
+ def find_git_root( path = Dir.pwd )
35
+ path = File.expand_path( path )
36
+ # Base Cases
37
+ return nil if path == "/"
38
+ return path if File.exist?( File.join(path,'.git') )
39
+ # Recurse
40
+ return find_git_root( File.dirname(path) )
41
+ end
42
+
43
+ def get_last_changes
44
+ @g.log.first.diff_parent.stats[:files].keys
45
+ end
46
+
47
+ def get_file_attrs( file )
48
+ result = Hash[
49
+ @g.lib.checkattr(file).split("\n").map{ |i| i.split(': ')[1,2] }
50
+ ]
51
+ result.each { |attr, val| result[attr] = val.split(',') }
52
+ end
53
+
54
+ def get_reviewers
55
+ reviewers = []
56
+ get_last_changes.each do |file|
57
+ reviewer = get_file_attrs( file )["owner.mail"]
58
+ reviewers += reviewer
59
+ end
60
+ reviewers.uniq
61
+ end
62
+
63
+ def get_author
64
+ { :name => @g.log.first.author.name,
65
+ :email => @g.log.first.author.email}
66
+ end
67
+
68
+ def get_patch
69
+ patch_path = "/tmp/#{@g.log.first.objectish}.patch"
70
+ diff = @g.lib.diff_full( @g.log.first.parent, @g.log.first )
71
+ File.open(patch_path, 'w') { |file| file.write(diff) }
72
+ patch_path
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,5 @@
1
+ module OttInfra
2
+ module Codereview
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -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 'ottinfra/codereview/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ottinfra-codereview"
8
+ spec.version = OttInfra::Codereview::VERSION
9
+ spec.licenses = ['MIT']
10
+ spec.authors = ["Dmitry Shmelev"]
11
+ spec.email = ["dmitry.shmelev@onetwotrip.com"]
12
+
13
+ spec.summary = %q{OTT Infra CodeReview gem.}
14
+ spec.description = %q{Infrastructure libs for codereview notification.}
15
+ spec.homepage = "https://www.onetwotrip.com"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
25
+ spec.add_development_dependency "rspec_junit_formatter", "~>0.2.3"
26
+ spec.add_development_dependency "simplecov", "~>0.11.1"
27
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ottinfra-codereview
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Shmelev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-21 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.4.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.4'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.4.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec_junit_formatter
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.2.3
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.2.3
75
+ - !ruby/object:Gem::Dependency
76
+ name: simplecov
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.11.1
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.11.1
89
+ description: Infrastructure libs for codereview notification.
90
+ email:
91
+ - dmitry.shmelev@onetwotrip.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".rspec"
98
+ - ".travis.yml"
99
+ - Gemfile
100
+ - LICENSE
101
+ - README.md
102
+ - Rakefile
103
+ - bin/console
104
+ - bin/setup
105
+ - lib/ottinfra/codereview.rb
106
+ - lib/ottinfra/codereview/version.rb
107
+ - ottinfra-codereview.gemspec
108
+ homepage: https://www.onetwotrip.com
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.8
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: OTT Infra CodeReview gem.
132
+ test_files: []