github-pr 0.0.4 → 0.0.5

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/github-pr +1 -1
  3. data/lib/github-pr.rb +5 -119
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c74d42e5c2598085921a24a1ae21895b45fb3af
4
- data.tar.gz: 6acbd6a5e151a93e8d9701230016d49b12fb8b69
3
+ metadata.gz: 3fe09fc99ab0eb7a14a246fd5f5dbe5de8a97da6
4
+ data.tar.gz: 885fd69a06a16bf12c975e5f6c9f8962290f3380
5
5
  SHA512:
6
- metadata.gz: e3f193e438b62683e7728a5f9c409f06cab0742451eaa92b31948b42f3c91219d55081bce68e9bc5b1eaaac95cd95e7febbf125510b11ae2513590108f59b4a5
7
- data.tar.gz: de19f6eb2a804273cf371335d8fbec5dc6619e609a3ecc8ec4741dc32244f8feb6270f073367769e51eea97a531a46e27607c83d82b7406b0c443d8ac8387169
6
+ metadata.gz: dc5feec10da90ab57af3d7a3493238730c9a721256c4ee9faf6a3cddf64ef7e5d45772c0852afa0f71b116cd43997f7d6ada9e66e335949e49c9bbc7b434b07f
7
+ data.tar.gz: 312495485804afb77c49244c3f3b75dd53997e6dd7bde09817d3403935a2f6d3797a43e3df3e204b96668bb2c7d495c4d8addc396e50f42426410b7fa469ba7e
data/bin/github-pr CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'github-pr'
4
4
 
5
- GitHubPr::create
5
+ GitHubPr::Runner.run(ARGV)
data/lib/github-pr.rb CHANGED
@@ -1,126 +1,12 @@
1
- require 'octokit'
2
- require 'highline'
3
- require 'uri'
4
- require 'pp'
5
- require 'fileutils'
6
- require 'optparse'
7
1
 
8
2
 
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
3
 
4
+ module GitHubPr
59
5
 
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
6
+ require 'github-pr/cli'
7
+ require 'github-pr/poster'
8
+ require 'github-pr/runner'
9
+ require 'github-pr/token'
124
10
 
125
11
  end
126
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-pr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hovhannes Safaryan