priha 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d6d94b62269896e468af7f7b9190c79890c38b30
4
+ data.tar.gz: 190e20b2719caf2f61af0c99569561971b622c92
5
+ SHA512:
6
+ metadata.gz: 4177b3445d5029e39636f94a03239189deaeee72eb99dcb25447bae664e971df6a0700290763508adebea32ab11e3e85897645e0e4461e3fba36c18d5071e6d8
7
+ data.tar.gz: ad012a9b36a3f16de20a96e10aaeb9bc3c2b4fb7417507989866aa64d8d256b5c9ecbe24cba0191e9807e2314b9cd6ae17429eb55658d4705c7a7fd707d7c514
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in priha.gemspec
4
+ gemspec
@@ -0,0 +1,46 @@
1
+ # Priha
2
+
3
+ If you are a guy who always find something wrong only after sending a pull requset, Priha will help you because Priha lets you examine files' diff between the parent branch and HEAD of the current branch in a real GitHub pull request.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem install priha
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ **CAUTION:** **DO NOT** use Priha for your secret repostitory. Since Priha pushes some commits to another repository on GitHub, it easily cause a security incident, espacially the branch you set for Priha is "public". Also, Priha removes all branches on the repository specified in config, so you **MUST** create a new repository for this purpose and **DO NOT** use the existing one.
14
+
15
+ ### Create config file
16
+
17
+ Priha requires a YAML config file (`$HOME/.priha_config.yml` or `$USERPROFILE\.priha_config.yml` for Windows) where your GitHub information is set like the followings.
18
+
19
+ ```yaml
20
+ username: <your github username>
21
+ repo: <your github repository to push for a temporary pull request>
22
+ parent_branch: <default parent branch to merge> (optional)
23
+ access_token: <your github access token> (optional)
24
+ ```
25
+
26
+ Note that you can specify parent_branch by passing that name as an argument, and access_token will be overwritten by "GITHUB_ACCESS_TOKEN" environment variable when exists.
27
+
28
+ ### Let's see files' diff on a GitHub pull request
29
+
30
+ Simply run `priha` when you are in the topic branch which you want to diff with the parent branch.
31
+
32
+ ``` text
33
+ $ priha
34
+ ```
35
+
36
+ Or you can specify the parent branch by passing it as an argument.
37
+
38
+ ``` text
39
+ $ priha develop
40
+ ```
41
+
42
+ Then you can see files' diff in your web browser (OS X only), or copy/paste displayed URL.
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/5t111111/priha.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "priha"
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,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
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+ require 'yaml'
3
+ require 'priha'
4
+
5
+ include Priha
6
+
7
+ config_file = if /mswin|msys|mingw|cygwin|bccwin|wince|emc/ =~ RUBY_PLATFORM
8
+ File.join(ENV['USERPROFILE'], '.priha_config.yml')
9
+ else
10
+ File.join(ENV['HOME'], '.priha_config.yml')
11
+ end
12
+
13
+ unless File.exist?(config_file)
14
+ STDERR.puts <<-EOS
15
+ ERROR: #{config_file} is not found.
16
+
17
+ Priha requires #{config_file} where your GitHub information is set like the followings.
18
+
19
+ -------------------------------------------------------------------------------
20
+ username: <your github username>
21
+ repo: <your github repository to push for a temporary pull request>
22
+ parent_branch: <default parent branch to merge> (optional)
23
+ access_token: <your github access token> (optional)
24
+ -------------------------------------------------------------------------------
25
+
26
+ Note that you can specify parent_branch by passing that name as an argument,
27
+ and access_token will be overwritten by "GITHUB_ACCESS_TOKEN" environment variable when exists.
28
+ EOS
29
+ exit 1
30
+ end
31
+
32
+ config = YAML.load_file(config_file)
33
+
34
+ errors = %w(username repo parent_branch access_token).each_with_object({}) do |i, a|
35
+ a[i] = "not set" unless config.include?(i)
36
+ end
37
+
38
+ if ARGV[0]
39
+ config['parent_branch'] = ARGV[0]
40
+ errors.delete('parent_branch')
41
+ end
42
+
43
+ if ENV['GITHUB_ACCESS_TOKEN']
44
+ config['access_token'] = ENV['GITHUB_ACCESS_TOKEN']
45
+ errors.delete('access_token')
46
+ end
47
+
48
+ unless errors.empty?
49
+ errors.each { |k, v| STDERR.puts "ERROR: #{k} is #{v}" }
50
+ exit 1
51
+ end
52
+
53
+ client = Octokit::Client.new(access_token: config['access_token'])
54
+
55
+ # Remove all branches
56
+ client.branches("#{config['username']}/#{config['repo']}").each do |branch|
57
+ client.delete_branch("#{config['username']}/#{config['repo']}", branch.name)
58
+ end
59
+
60
+ if config['parent_branch'] == current_branch
61
+ STDERR.puts "ERROR: #{config['parent_branch']} and #{current_branch} are identical"
62
+ exit 1
63
+ end
64
+
65
+ puts 'Pushing branches. It may takes a while...'
66
+
67
+ add_remote(config['access_token'], config['username'], config['repo'])
68
+ push(config['parent_branch'], "#{config['parent_branch']}-#{IDENTIFIER}")
69
+ push(current_branch, "#{current_branch}-#{IDENTIFIER}")
70
+ remove_remote
71
+
72
+ client.create_pull_request(
73
+ "#{config['username']}/#{config['repo']}",
74
+ "#{config['parent_branch']}-#{IDENTIFIER}",
75
+ "#{current_branch}-#{IDENTIFIER}",
76
+ "Pull Request Rehearsal",
77
+ "This is a pull request rehearsal for a life."
78
+ )
79
+
80
+ files_url = client.pull_requests("#{config['username']}/#{config['repo']}", state: 'open').first.html_url + '/files'
81
+ puts files_url
82
+
83
+ if /darwin|mac os/ =~ RUBY_PLATFORM
84
+ `open #{files_url}`
85
+ end
@@ -0,0 +1,33 @@
1
+ require 'securerandom'
2
+ require 'octokit'
3
+ require "priha/version"
4
+ require 'priha/git_command'
5
+
6
+ module Priha
7
+ IDENTIFIER = SecureRandom.hex(8)
8
+
9
+ def current_branch
10
+ return @current_branch if @current_branch
11
+ status, result = GitCommand.call_git_name_rev_name_only_head
12
+ return nil unless status == 0
13
+ @current_branch = result.chomp
14
+ end
15
+
16
+ def add_remote(token, username, repository_name)
17
+ status, _result = GitCommand.call_git_remote_add(token, username, repository_name, IDENTIFIER)
18
+ return false unless status == 0
19
+ true
20
+ end
21
+
22
+ def remove_remote
23
+ status, _result = GitCommand.call_git_remote_remove(IDENTIFIER)
24
+ return false unless status == 0
25
+ true
26
+ end
27
+
28
+ def push(local_branch, remote_branch)
29
+ status, _result = GitCommand.call_git_push(IDENTIFIER, local_branch, remote_branch)
30
+ return false unless status == 0
31
+ true
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ module Priha
2
+ module GitCommand
3
+ def call_git_name_rev_name_only_head
4
+ result = `git name-rev --name-only HEAD`
5
+ return $?.exitstatus, result
6
+ rescue => e # catch exception intead of status (a workaround for Windows)
7
+ STDERR.puts e
8
+ return 127, ''
9
+ end
10
+
11
+ def call_git_remote_add(token, username, repository_name, remote_name)
12
+ result = `git remote add #{remote_name} "https://#{token}@github.com/#{username}/#{repository_name}"`
13
+ return $?.exitstatus, result
14
+ rescue => e # catch exception intead of status (a workaround for Windows)
15
+ STDERR.puts e
16
+ return 127, ''
17
+ end
18
+
19
+ def call_git_remote_remove(remote_name)
20
+ result = `git remote remove #{remote_name}`
21
+ return $?.exitstatus, result
22
+ rescue => e # catch exception intead of status (a workaround for Windows)
23
+ STDERR.puts e
24
+ return 127, ''
25
+ end
26
+
27
+ def call_git_push(remote_name, local_branch, remote_branch)
28
+ result = `git push #{remote_name} #{local_branch}:#{remote_branch} --quiet`
29
+ return $?.exitstatus, result
30
+ rescue => e # catch exception intead of status (a workaround for Windows)
31
+ STDERR.puts e
32
+ return 127, ''
33
+ end
34
+
35
+ module_function :call_git_name_rev_name_only_head, :call_git_remote_add,
36
+ :call_git_remote_remove, :call_git_push
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Priha
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'priha/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'priha'
8
+ spec.version = Priha::VERSION
9
+ spec.authors = ['Hirofumi Wakasugi']
10
+ spec.email = ['baenej@gmail.com']
11
+
12
+ spec.summary = %q{Priha is to examine files' diff in a real GitHub pull request}
13
+ spec.description = %q{If you are a guy who always find something wrong only after sending a pull requset, Priha will help you because Priha lets you examine files' diff between the parent branch and HEAD of the current branch in a real GitHub pull request. However, DO NOT use Priha for your secret repostitory. Since Priha pushes some commits to another repository on GitHub, it easily cause a security incident, espacially the branch you set for Priha is "public". Also, Priha removes all branches on the repository specified in config, so you MUST create a new repository for this purpose and DO NOT use the existing one.
14
+ }
15
+ spec.homepage = "https://github.com/5t111111/priha"
16
+
17
+ # # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency "octokit", "~> 4.2"
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.11"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "minitest", "~> 5.0"
35
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: priha
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hirofumi Wakasugi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-28 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: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: 'If you are a guy who always find something wrong only after sending
70
+ a pull requset, Priha will help you because Priha lets you examine files'' diff
71
+ between the parent branch and HEAD of the current branch in a real GitHub pull request.
72
+ However, DO NOT use Priha for your secret repostitory. Since Priha pushes some commits
73
+ to another repository on GitHub, it easily cause a security incident, espacially
74
+ the branch you set for Priha is "public". Also, Priha removes all branches on the
75
+ repository specified in config, so you MUST create a new repository for this purpose
76
+ and DO NOT use the existing one.
77
+
78
+ '
79
+ email:
80
+ - baenej@gmail.com
81
+ executables:
82
+ - priha
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - ".gitignore"
87
+ - ".travis.yml"
88
+ - Gemfile
89
+ - README.md
90
+ - Rakefile
91
+ - bin/console
92
+ - bin/setup
93
+ - exe/priha
94
+ - lib/priha.rb
95
+ - lib/priha/git_command.rb
96
+ - lib/priha/version.rb
97
+ - priha.gemspec
98
+ homepage: https://github.com/5t111111/priha
99
+ licenses: []
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.5.1
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Priha is to examine files' diff in a real GitHub pull request
121
+ test_files: []