github-pr 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/github-pr +5 -0
- data/lib/github-pr.rb +129 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f9aaddbb357cd774244bccf74c7a7475e36441e5
|
4
|
+
data.tar.gz: 132b9061387599d88f52c0aba2624482a3a2fdc1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 419b05b119119d3d976f74eb05591cfe72262aa3ded6efc2a81ace57ef683546d7a3c17e0e3ff9eb9484b6705d22286c264d61b8934abe88b807ab5da89f355c
|
7
|
+
data.tar.gz: b99f5f812d788b077e55fe9072edd2889749038e4dfbddac2490cb5d5a07a74f8fe1e3cfba7a1a61326f84bcd2529b9295d76c397f3edba6015736f25b88fb32
|
data/bin/github-pr
ADDED
data/lib/github-pr.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
require 'highline'
|
3
|
+
require 'uri'
|
4
|
+
require 'pp'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
|
9
|
+
module GitHubPr
|
10
|
+
|
11
|
+
def self.github_token(regenerate: regenerate = false)
|
12
|
+
token_file_path = File.expand_path '~/.config/gh-pr-token'
|
13
|
+
|
14
|
+
token_dir = File.dirname(token_file_path)
|
15
|
+
unless File.directory?(token_dir)
|
16
|
+
FileUtils.mkdir_p(token_dir)
|
17
|
+
end
|
18
|
+
|
19
|
+
if regenerate
|
20
|
+
FileUtils.rm(token_file_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
token = nil
|
24
|
+
if File.exists? token_file_path
|
25
|
+
token = IO.read(token_file_path)
|
26
|
+
else
|
27
|
+
cli = HighLine.new
|
28
|
+
|
29
|
+
github_username = cli.ask("GitHub Username: ")
|
30
|
+
github_password = cli.ask("GitHub Password(Only one time): ") { |q| q.echo = "*" }
|
31
|
+
|
32
|
+
client = Octokit::Client.new(:login => github_username, :password => github_password)
|
33
|
+
|
34
|
+
note = 'CLI uses'
|
35
|
+
limit_reached = false
|
36
|
+
# trying 9 different notes, if all is failed,
|
37
|
+
# then you have to remove some of them
|
38
|
+
9.times do |i|
|
39
|
+
begin
|
40
|
+
token = client.create_authorization(:scopes => ["repo", "user"], :note => note)[:token]
|
41
|
+
break
|
42
|
+
rescue Exception => e
|
43
|
+
if i == 8
|
44
|
+
raise 'Please remove some personal tokens from your github account, you have too many tokens'
|
45
|
+
end
|
46
|
+
if e.errors[0][:code] != "already_exists" || e.errors[0][:field] != "description"
|
47
|
+
raise e
|
48
|
+
else
|
49
|
+
note = 'CLI uses' + (i + 2).to_s
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
File.open(token_file_path, 'w+') {|file| file.write token}
|
55
|
+
end
|
56
|
+
return token
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def self.create
|
61
|
+
options = {}
|
62
|
+
OptionParser.new do |opts|
|
63
|
+
opts.banner = "Usage: github-pr -b master -f shop-redesign -a hovox"
|
64
|
+
opts.separator ""
|
65
|
+
opts.separator "Your current directory must be your git directory"
|
66
|
+
opts.separator "github-pr -b master -a hovox"
|
67
|
+
opts.separator "Will use current branch as feature branch"
|
68
|
+
opts.separator ""
|
69
|
+
opts.separator "github-pr -a hovox"
|
70
|
+
opts.separator "Will use master branch as base branch and current branch as feature branch"
|
71
|
+
opts.separator ""
|
72
|
+
opts.separator "Command should be run from project's directory"
|
73
|
+
|
74
|
+
|
75
|
+
opts.on("-b", "--base BASE", "Base branch") do |b|
|
76
|
+
options[:base] = b
|
77
|
+
end
|
78
|
+
opts.on("-f", "--feature FEATURE", "Feature branch") do |f|
|
79
|
+
options[:feature] = f
|
80
|
+
end
|
81
|
+
opts.on("-a", "--assign USERNAME", "GitHub user name whom to assign") do |a|
|
82
|
+
options[:assign] = a
|
83
|
+
end
|
84
|
+
opts.on("-t", "--title PULLREQUESTTITLE", "Title of the pull request") do |t|
|
85
|
+
options[:title] = t
|
86
|
+
end
|
87
|
+
end.parse!
|
88
|
+
|
89
|
+
raise 'You must assign to someone' if options[:assign].nil?
|
90
|
+
if options[:base].nil?
|
91
|
+
options[:base] = 'master'
|
92
|
+
end
|
93
|
+
|
94
|
+
# https://github.com/user/reponame cutting path user/reponame
|
95
|
+
repo_url = `git config --get remote.origin.url`.chomp
|
96
|
+
repo = URI::parse(repo_url).path[1..-1]
|
97
|
+
|
98
|
+
# e.g. * master cutting '* ' from begining
|
99
|
+
if options[:feature].nil?
|
100
|
+
options[:feature] = `git branch | grep "^*"`.chomp[2..-1]
|
101
|
+
end
|
102
|
+
if options[:title].nil?
|
103
|
+
options[:title] = options[:feature]
|
104
|
+
end
|
105
|
+
|
106
|
+
puts options
|
107
|
+
|
108
|
+
client = Octokit::Client.new(:access_token => github_token())
|
109
|
+
begin
|
110
|
+
pull_request = client.create_pull_request(repo,
|
111
|
+
options[:base],
|
112
|
+
options[:feature],
|
113
|
+
options[:title], nil)
|
114
|
+
rescue Octokit::Unauthorized => e
|
115
|
+
client = Octokit::Client.new(:access_token => github_token(regenerate: true))
|
116
|
+
pull_request = client.create_pull_request(repo,
|
117
|
+
options[:base],
|
118
|
+
options[:feature],
|
119
|
+
options[:title], nil)
|
120
|
+
end
|
121
|
+
client.post("/repos/#{repo}/issues/#{pull_request['number']}/assignees",
|
122
|
+
assignees: [options[:assign]])
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github-pr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hovhannes Safaryan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Create GitHub pull request and assign from termianl
|
14
|
+
email: hovhannes.safaryan@gmail.com
|
15
|
+
executables:
|
16
|
+
- github-pr
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/github-pr
|
21
|
+
- lib/github-pr.rb
|
22
|
+
homepage: http://rubygems.org/gems/github-pr
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.5.1
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Pull request with and assign with one command
|
46
|
+
test_files: []
|