tukune 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da8eeb756b92ae9e7bc02d2d46628172de826a24
4
+ data.tar.gz: 1f382801f54a7311e21091ea41baede08179b4d3
5
+ SHA512:
6
+ metadata.gz: 8b6b1afb41a8ad6e67255f9fdf59cc03c76847e054124589fec0f2011a8dd2dad439e4234ee3eda4adc6f08a34a870966bcc0af7ee2c24ab9f6f8f825a0fd920
7
+ data.tar.gz: 34ae658de6d2e7eee6d7d48e8810be478fb8d2b0ec04c03bd17e7c6c72114a603b7f2101717fc81b4c98c7e7084506d6136c5ee78b7c9e8d94862b7e956cd11a
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: tUQCZy4diLdMsQryCwhgtPHrMl1YBBdHK
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Metrics/LineLength:
4
+ Max: 120
5
+
6
+ Style/Documentation:
7
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,18 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-06-30 16:36:27 +0900 using RuboCop version 0.41.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Metrics/AbcSize:
11
+ Exclude:
12
+ - lib/tukune/cli.rb
13
+
14
+ # Offense count: 2
15
+ # Configuration parameters: CountComments.
16
+ Metrics/MethodLength:
17
+ Exclude:
18
+ - lib/tukune/cli.rb
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3.1
6
+ before_install:
7
+ - gem install bundler -v 1.12.5
8
+ - chmod +x bin/tukune
9
+
10
+ script:
11
+ - bundle exec rake
12
+ - bundle exec rubocop
13
+
14
+ after_failure:
15
+ - bundle exec rubocop --auto-correct
16
+ - bin/tukune --title '[BOT]bundle exec rubocop --auto-correct' --body 'This pull request made by tukune'
17
+
18
+ notifications:
19
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tukune.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # [WIP]Tukune
2
+ [![Build Status](https://travis-ci.org/gin0606/tukune.svg?branch=master)](https://travis-ci.org/gin0606/tukune)
3
+ [![Coverage Status](https://coveralls.io/repos/github/gin0606/tukune/badge.svg?branch=master)](https://coveralls.io/github/gin0606/tukune?branch=master)
4
+
5
+ Create a pull request if there is a difference via Github API.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tukune'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```
18
+ $ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```
24
+ $ gem install tukune
25
+ ```
26
+
27
+ ## Required ENV variables
28
+
29
+ `OCTOKIT_ACCESS_TOKEN`
30
+
31
+ Please set your [Githu API Token](https://github.com/settings/tokens)
32
+
33
+ ## Usage
34
+ All commands does not do anything if nothing to commit.
35
+
36
+ `tukune --title "Pull Request Title" --body "Pull Request Body"`
37
+
38
+ Create Pull Request
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ 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).
45
+
46
+ ## Contributing
47
+ 1. Fork it ( https://github.com/gin0606/tukune/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'tukune'
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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/tukune ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'tukune'
5
+ require 'optparse'
6
+
7
+ options = {}
8
+ opt_parser = OptionParser.new do |opt|
9
+ opt.banner = 'Usage: tukune [OPTIONS]'
10
+ opt.separator ''
11
+ opt.separator 'Options'
12
+
13
+ opt.on('-t', '--title TITLE', 'Pull request title') do |title|
14
+ options[:title] = title
15
+ end
16
+
17
+ opt.on('-b', '--body BODY', 'Pull request body') do |body|
18
+ options[:body] = body
19
+ end
20
+
21
+ opt.on('-h', '--help', 'help') do
22
+ puts opt_parser
23
+ end
24
+ end
25
+
26
+ opt_parser.parse!
27
+ Tukune::CLI.start(options)
data/lib/tukune/cli.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Tukune
2
+ class CLI
3
+ class << self
4
+ def start(options)
5
+ if Tukune.configuration.tukune_branch?
6
+ puts 'this branch is tukune'
7
+ return
8
+ end
9
+ unless Tukune.configuration.pull_request?
10
+ puts 'This build is not part of pull request.'
11
+ puts 'If you want to exec tukune, try to use `--enable-all` option.'
12
+ return
13
+ end
14
+ diff = Tukune::Git::Diff.name_status
15
+ if diff.nothing_to_commit?
16
+ puts 'nothing to commit, working directory clean'
17
+ return
18
+ end
19
+ c = Tukune::Git::Commit.new(Tukune.configuration)
20
+ diff.modified_files.each do |f|
21
+ c.add(f)
22
+ puts "Create #{f} blob."
23
+ end
24
+ diff.added_files.each do |f|
25
+ c.add(f)
26
+ puts "Create #{f} blob."
27
+ end
28
+ # diff.deleted_files.each {|f| c.delete(f) }
29
+ c.commit("#{options[:title]}\n\n#{options[:body]}")
30
+ puts 'Create commit'
31
+ c.pull_request(options[:title], options[:body])
32
+ puts 'Create pull request'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ require 'tukune/configuration'
2
+
3
+ module Tukune
4
+ class Configuration
5
+ class CircleCI < Default
6
+ def repository_name
7
+ "#{ENV['CIRCLE_PROJECT_USERNAME']}/#{ENV['CIRCLE_PROJECT_REPONAME']}"
8
+ end
9
+
10
+ def current_branch
11
+ ENV['CIRCLE_BRANCH']
12
+ end
13
+
14
+ def pull_request?
15
+ !ENV['CIRCLE_PR_NUMBER'].nil?
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,35 @@
1
+ require 'mem'
2
+
3
+ module Tukune
4
+ class Configuration
5
+ class Default
6
+ include Mem
7
+
8
+ def repository_name
9
+ raise 'You need to set TUKUNE_REPONAME in environment variables' unless ENV['TUKUNE_REPONAME']
10
+ ENV['TUKUNE_REPONAME']
11
+ end
12
+
13
+ def tukune_branch?
14
+ current_branch.start_with?(feature_branch_prefix)
15
+ end
16
+
17
+ def current_branch
18
+ `git symbolic-ref --short HEAD`.strip
19
+ end
20
+
21
+ def feature_branch_prefix
22
+ 'tukune_'
23
+ end
24
+
25
+ def feature_branch
26
+ feature_branch_prefix + current_branch
27
+ end
28
+ memoize :feature_branch
29
+
30
+ def pull_request?
31
+ false
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ require 'tukune/configuration'
2
+
3
+ module Tukune
4
+ class Configuration
5
+ class TravisCI < Default
6
+ def repository_name
7
+ ENV['TRAVIS_REPO_SLUG']
8
+ end
9
+
10
+ def current_branch
11
+ ENV['TRAVIS_BRANCH']
12
+ end
13
+
14
+ def pull_request?
15
+ ENV['TRAVIS_PULL_REQUEST'] != 'false'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'configuration/default'
2
+ require_relative 'configuration/travis_ci'
3
+ require_relative 'configuration/circle_ci'
4
+
5
+ module Tukune
6
+ def self.configuration
7
+ @configuration ||= if ENV['TRAVIS']
8
+ Configuration::TravisCI.new
9
+ elsif ENV['CIRCLECI']
10
+ Configuration::CircleCI.new
11
+ else
12
+ Configuration::Default.new
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,113 @@
1
+ require 'octokit'
2
+ require 'mem'
3
+
4
+ module Tukune
5
+ module Git
6
+ class Commit
7
+ include Mem
8
+
9
+ def initialize(configuration)
10
+ @repository_name = configuration.repository_name
11
+ @current_branch = configuration.current_branch
12
+ @feature_branch = configuration.feature_branch
13
+ end
14
+
15
+ def add(file_path)
16
+ content = Base64.encode64(File.read(file_path))
17
+ sha = client.create_blob(@repository_name, content, 'base64')
18
+ blobs[file_path] = sha
19
+ end
20
+
21
+ def delete(file_path)
22
+ delete_files << file_path
23
+ end
24
+
25
+ def commit(message)
26
+ tree = if delete_files.empty?
27
+ create_tree(changed_blobs)
28
+ else
29
+ create_tree_with_delete_files(changed_blobs)
30
+ end
31
+
32
+ commits << client.create_commit(@repository_name, message, tree[:sha], current_branch[:object][:sha])
33
+ end
34
+
35
+ def pull_request(title, body)
36
+ create_feature_branch(@feature_branch, commits.last[:sha])
37
+ client.create_pull_request(
38
+ @repository_name,
39
+ @current_branch,
40
+ @feature_branch,
41
+ title,
42
+ body
43
+ )
44
+ end
45
+
46
+ private
47
+
48
+ def create_tree(changed_blobs)
49
+ client.create_tree(@repository_name, changed_blobs, base_tree: current_tree[:sha])
50
+ end
51
+
52
+ # FIXME: can not commit correctly if exist delete_files
53
+ def create_tree_with_delete_files(changed_blobs)
54
+ changed_files = blobs.map { |path, _| path }
55
+
56
+ # trees = current_tree[:tree].map(&:to_h)
57
+ # trees = current_tree[:tree].map(&:to_h).delete_if { |blob| delete_files.include?(blob[:path]) }
58
+ trees = current_tree[:tree].map(&:to_h)
59
+ .delete_if { |blob| delete_files.include?(blob[:path]) }
60
+ .delete_if { |blob| changed_files.include?(blob[:path]) }
61
+ trees += changed_blobs
62
+
63
+ client.create_tree(@repository_name, trees)
64
+ end
65
+
66
+ def current_tree
67
+ commit = client.commit(@repository_name, current_branch[:object][:sha])
68
+ client.tree(@repository_name, commit[:commit][:tree][:sha], recursive: true)
69
+ end
70
+ memoize :current_tree
71
+
72
+ def current_branch
73
+ client.ref(@repository_name, "heads/#{@current_branch}")
74
+ end
75
+ memoize :current_branch
76
+
77
+ def create_feature_branch(name, sha)
78
+ client.create_ref(@repository_name, "heads/#{name}", sha)
79
+ end
80
+
81
+ def commits
82
+ []
83
+ end
84
+ memoize :commits
85
+
86
+ def blobs
87
+ {}
88
+ end
89
+ memoize :blobs
90
+
91
+ def changed_blobs
92
+ blobs.map do |file_path, sha|
93
+ {
94
+ path: file_path,
95
+ mode: '100644',
96
+ type: 'blob',
97
+ sha: sha
98
+ }
99
+ end
100
+ end
101
+
102
+ def delete_files
103
+ []
104
+ end
105
+ memoize :delete_files
106
+
107
+ def client
108
+ ::Octokit::Client.new
109
+ end
110
+ memoize :client
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,34 @@
1
+ module Tukune
2
+ module Git
3
+ class Diff
4
+ attr_reader :changed_files
5
+
6
+ def initialize(changed_files)
7
+ @changed_files = changed_files
8
+ end
9
+
10
+ def nothing_to_commit?
11
+ changed_files.empty?
12
+ end
13
+
14
+ def added_files
15
+ `git ls-files --others --exclude-standard`.strip.split("\n")
16
+ end
17
+
18
+ def modified_files
19
+ changed_files.select { |type, _| type == 'M' }.map { |_, name| name }
20
+ end
21
+
22
+ def deleted_files
23
+ changed_files.select { |type, _| type == 'D' }.map { |_, name| name }
24
+ end
25
+
26
+ class << self
27
+ def name_status
28
+ changed_files ||= `git diff --name-status`.strip.split("\n").map { |e| e.split("\t") }
29
+ Diff.new(changed_files)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Tukune
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/lib/tukune.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'tukune/cli'
2
+ require 'tukune/configuration'
3
+ require 'tukune/git/diff'
4
+ require 'tukune/git/commit'
5
+ require 'tukune/version'
6
+
7
+ module Tukune
8
+ end
data/tukune.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tukune/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'tukune'
8
+ spec.version = Tukune::VERSION
9
+ spec.authors = ['gin0606']
10
+ spec.email = ['kkgn06@gmail.com']
11
+
12
+ spec.summary = 'Create a pull request if there is a difference via Github API'
13
+ spec.description = 'Create a pull request if there is a difference via Github API'
14
+ spec.homepage = 'https://github.com/gin0606/tukune'
15
+ spec.license = 'MIT'
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_dependency 'octokit'
23
+ spec.add_dependency 'mem'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.12'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ spec.add_development_dependency 'coveralls'
29
+ spec.add_development_dependency 'rubocop'
30
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tukune
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - gin0606
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mem
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Create a pull request if there is a difference via Github API
112
+ email:
113
+ - kkgn06@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".coveralls.yml"
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - ".rubocop_todo.yml"
123
+ - ".travis.yml"
124
+ - Gemfile
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - bin/tukune
130
+ - lib/tukune.rb
131
+ - lib/tukune/cli.rb
132
+ - lib/tukune/configuration.rb
133
+ - lib/tukune/configuration/circle_ci.rb
134
+ - lib/tukune/configuration/default.rb
135
+ - lib/tukune/configuration/travis_ci.rb
136
+ - lib/tukune/git/commit.rb
137
+ - lib/tukune/git/diff.rb
138
+ - lib/tukune/version.rb
139
+ - tukune.gemspec
140
+ homepage: https://github.com/gin0606/tukune
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.5.1
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: Create a pull request if there is a difference via Github API
164
+ test_files: []