github-pr 0.0.95 → 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.
- checksums.yaml +4 -4
- data/lib/github-pr/poster.rb +5 -4
- data/lib/github-pr/token.rb +4 -1
- data/test/test_poster.rb +15 -10
- data/test/test_token.rb +22 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b50c962c46691c31b5697fe9026cde8721fe655
|
4
|
+
data.tar.gz: e24f063a34c1d4474060d1e67ac237857842b92a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f97e1d0c4d56e0bc73496639b3e7d7de2ccf3b84dd2840c64a0f45bce1fd7679b75c42927b72c4dfa900c5cb8ea2412168e114181dbc94eeb94ff6dce7457224
|
7
|
+
data.tar.gz: 96d9d31fab7b2b37452893b1139163b7e9dedc4786f0585d60db4b06dad87ee0f0a8f04693ea3c5ab96b90804e0aaaa6a12b1f5ccd88c9469dcd8c0ee0ad0f00
|
data/lib/github-pr/poster.rb
CHANGED
@@ -11,14 +11,15 @@ module GitHubPr
|
|
11
11
|
begin
|
12
12
|
postPrivate(client, options)
|
13
13
|
rescue Octokit::Unauthorized
|
14
|
+
puts 'Unauthorized error, revoking access token'
|
14
15
|
client = Octokit::Client.new(:access_token => @token.get(regenerate: true))
|
15
16
|
postPrivate(client, options)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
def postPrivate(client, options)
|
19
|
-
|
20
|
-
repo =
|
21
|
-
pull_request = client.create_pull_request(
|
20
|
+
repo_url = Poster.repo_url()
|
21
|
+
repo = cut_scheme_and_host(repo_url)
|
22
|
+
pull_request = client.create_pull_request(repo,
|
22
23
|
options[:base],
|
23
24
|
options[:feature],
|
24
25
|
options[:title], nil)
|
@@ -30,7 +31,7 @@ module GitHubPr
|
|
30
31
|
def cut_scheme_and_host(url)
|
31
32
|
URI::parse(url).path[1..-1]
|
32
33
|
end
|
33
|
-
def repo_url
|
34
|
+
def self.repo_url
|
34
35
|
`git config --get remote.origin.url`.chomp
|
35
36
|
end
|
36
37
|
end
|
data/lib/github-pr/token.rb
CHANGED
@@ -15,6 +15,7 @@ module GitHubPr
|
|
15
15
|
elsif !direct_token.nil? && direct_token.length > 0
|
16
16
|
tokenObj = FixedToken.new(direct_token)
|
17
17
|
else
|
18
|
+
puts 'filetoken path:' + token_file_path
|
18
19
|
tokenObj = FileToken.new(token_file_path)
|
19
20
|
end
|
20
21
|
return tokenObj
|
@@ -43,7 +44,7 @@ module GitHubPr
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def token_from_file
|
46
|
-
File.
|
47
|
+
File.exist?(@token_file_path) ? IO.read(@token_file_path) : nil
|
47
48
|
end
|
48
49
|
|
49
50
|
def retry_logic(count, initial_note)
|
@@ -93,6 +94,7 @@ module GitHubPr
|
|
93
94
|
create_dir_if_needed()
|
94
95
|
|
95
96
|
if regenerate
|
97
|
+
puts 'Token has been reveked'
|
96
98
|
FileUtils.rm(@token_file_path)
|
97
99
|
end
|
98
100
|
|
@@ -100,6 +102,7 @@ module GitHubPr
|
|
100
102
|
if token
|
101
103
|
return token
|
102
104
|
end
|
105
|
+
puts 'Token is nil regenerating'
|
103
106
|
|
104
107
|
token = token_from_github()
|
105
108
|
File.open(@token_file_path, 'w+') {|file| file.write token}
|
data/test/test_poster.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'github-pr/poster'
|
3
|
+
require 'github-pr/token'
|
3
4
|
|
4
5
|
module GitHubPr
|
5
6
|
|
@@ -9,18 +10,22 @@ module GitHubPr
|
|
9
10
|
it "must return correct path" do
|
10
11
|
poster = Poster.new("token")
|
11
12
|
repo_url = "https://github.com/user/reponame"
|
12
|
-
|
13
|
-
|
13
|
+
repo = poster.cut_scheme_and_host(repo_url)
|
14
|
+
repo.must_equal "user/reponame"
|
14
15
|
end
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
18
|
+
# describe "Pull requesting" do
|
19
|
+
# it "must create git pull request" do
|
20
|
+
# options = {:assign=>"hovox", :base=>"master", :feature=>"some-other-branch-bbb", :title=>"some-other-branch-bbb", :token=>nil}
|
21
|
+
# Poster.stub(:repo_url, "https://github.com/PicsArt/picsart-ios") do
|
22
|
+
# poster = Poster.new(Token.create(token_file_path:File.expand_path('~/.config/gh-pr-token'), direct_token: options[:token]))
|
23
|
+
# puts 'repourl:' + Poster.repo_url
|
24
|
+
# poster.post(options)
|
25
|
+
# end
|
26
|
+
|
27
|
+
# end
|
28
|
+
# end
|
24
29
|
|
25
30
|
end
|
26
31
|
|
data/test/test_token.rb
CHANGED
@@ -17,6 +17,28 @@ module GitHubPr
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
describe "File cache" do
|
21
|
+
it "must present after creation" do
|
22
|
+
path = File.expand_path '~/.config/gh-pr-token'
|
23
|
+
token = Token.create(token_file_path:path)
|
24
|
+
token.create_dir_if_needed()
|
25
|
+
token_dir = File.dirname(path)
|
26
|
+
isDirExist = File.directory?(token_dir)
|
27
|
+
isDirExist.must_equal true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "must return token from file if exists" do
|
31
|
+
some_token = '1aa277306fdadcfd64739a174fc4da09f8ddeea0'
|
32
|
+
path = File.expand_path '~/.config/gh-pr-token'
|
33
|
+
# puts 'cache path is:' + path
|
34
|
+
|
35
|
+
token = Token.create(token_file_path:path, direct_token:nil)
|
36
|
+
token.create_dir_if_needed()
|
37
|
+
token.token_from_file().must_equal some_token
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
20
42
|
# describe "Token object creation" do
|
21
43
|
|
22
44
|
# end
|