geet 0.1.0 → 0.1.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 +4 -4
- data/README.md +17 -9
- data/lib/geet/git_hub/api_helper.rb +34 -44
- data/lib/geet/services/list_issues.rb +0 -3
- data/lib/geet/version.rb +1 -1
- 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: 033e3851278fd2e0b27bbf58ed7b4fe63f1dc293
|
4
|
+
data.tar.gz: 5a89dbdd4d43594638e67453d9cdaab7c64bfcf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f038e218da489bc3599091209b8241dba8339441144775e8af0193c793a403187ffb14e88aedfcbcdd2fb427da1f7a9556804c9d2c4e54d7585bc3a2bd7232c5
|
7
|
+
data.tar.gz: 0faf78b1473415d7725fe04f561177eb64740158d3f1993b4056f5ec21784998d8dce409df944a43c2555d13dff8b5701e7c353a41353b7d44d76bdfc8b61e35
|
data/README.md
CHANGED
@@ -10,20 +10,28 @@ This tool is very similar to [Hub](https://github.com/github/hub), but it suppor
|
|
10
10
|
|
11
11
|
Basic creation of an issue and a PR (both actions will open the pages with the result in the browser):
|
12
12
|
|
13
|
-
$ geet issue 'Issue Title' 'Issue Description'
|
14
|
-
|
13
|
+
$ geet issue create 'Issue Title' 'Issue Description'
|
14
|
+
|
15
|
+
$ geet pr create 'PR Title' 'Multi-line
|
15
16
|
>
|
16
|
-
>
|
17
|
+
> description'
|
17
18
|
|
18
|
-
|
19
|
+
More advanced issue/PR creation, with label, reviewers and assignees:
|
19
20
|
|
20
|
-
$ geet issue 'Issue Title' 'Issue Description' --label-patterns
|
21
|
+
$ geet issue create 'Issue Title' 'Issue Description' --label-patterns bug,wip --assignee-patterns john
|
22
|
+
|
23
|
+
$ geet pr create 'PR Title' 'Closes #1' --label-patterns "code review" --reviewer-patterns kevin,tom,adrian
|
21
24
|
|
22
|
-
|
25
|
+
patterns are partial matches, so, for example, `johncarmack` will be matched as assignee in the first case.
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
List the open issues, in default order (inverse creation date):
|
28
|
+
|
29
|
+
$ geet issue list
|
30
|
+
> 16. Implement issue opening (https://github.com/saveriomiroddi/geet/issues/16)
|
31
|
+
> 14. Update README (https://github.com/saveriomiroddi/geet/issues/14)
|
32
|
+
> 8. Implement milestones listing/show (https://github.com/saveriomiroddi/geet/issues/8)
|
33
|
+
> 4. Allow writing description in an editor (https://github.com/saveriomiroddi/geet/issues/4)
|
34
|
+
> 2. Support opening PR into other repositories (https://github.com/saveriomiroddi/geet/issues/2)
|
27
35
|
|
28
36
|
For the help:
|
29
37
|
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
3
5
|
require 'json'
|
4
|
-
require 'open3'
|
5
6
|
require 'shellwords'
|
6
7
|
|
7
8
|
module Geet
|
@@ -28,34 +29,15 @@ module Geet
|
|
28
29
|
# return an array, with the concatenated (parsed) responses
|
29
30
|
#
|
30
31
|
def send_request(address, data: nil, multipage: false)
|
31
|
-
# `--data` implies `-X POST`
|
32
|
-
#
|
33
|
-
if data
|
34
|
-
escaped_request_body = JSON.generate(data).shellescape
|
35
|
-
data_option = "--data #{escaped_request_body}"
|
36
|
-
end
|
37
|
-
|
38
32
|
# filled only on :multipage
|
39
33
|
parsed_responses = []
|
40
34
|
|
41
35
|
loop do
|
42
|
-
|
43
|
-
response_metadata, response_body = nil
|
44
|
-
|
45
|
-
Open3.popen3(command) do |_, stdout, stderr, wait_thread|
|
46
|
-
response_metadata = stderr.readlines.join
|
47
|
-
response_body = stdout.readlines.join
|
48
|
-
|
49
|
-
if !wait_thread.value.success?
|
50
|
-
puts response_metadata
|
51
|
-
puts "Error! Command: #{command}"
|
52
|
-
exit
|
53
|
-
end
|
54
|
-
end
|
36
|
+
response = send_http_request(address, data: data)
|
55
37
|
|
56
|
-
parsed_response = JSON.parse(
|
38
|
+
parsed_response = JSON.parse(response.body)
|
57
39
|
|
58
|
-
if error?(
|
40
|
+
if error?(response)
|
59
41
|
formatted_error = decode_and_format_error(parsed_response)
|
60
42
|
raise(formatted_error)
|
61
43
|
end
|
@@ -64,7 +46,7 @@ module Geet
|
|
64
46
|
|
65
47
|
parsed_responses.concat(parsed_response)
|
66
48
|
|
67
|
-
address = link_next_page(
|
49
|
+
address = link_next_page(response.to_hash)
|
68
50
|
|
69
51
|
return parsed_responses if address.nil?
|
70
52
|
end
|
@@ -72,13 +54,35 @@ module Geet
|
|
72
54
|
|
73
55
|
private
|
74
56
|
|
75
|
-
def
|
76
|
-
|
57
|
+
def send_http_request(address, data: nil)
|
58
|
+
uri = URI(address)
|
59
|
+
|
60
|
+
Net::HTTP.start(uri.host, use_ssl: true) do |http|
|
61
|
+
if data
|
62
|
+
request = Net::HTTP::Post.new(uri)
|
63
|
+
request.body = data.to_json
|
64
|
+
else
|
65
|
+
request = Net::HTTP::Get.new(uri)
|
66
|
+
end
|
67
|
+
|
68
|
+
request.basic_auth @user, @api_token
|
69
|
+
request['Accept'] = 'application/vnd.github.v3+json'
|
70
|
+
|
71
|
+
http.request(request)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def error?(response)
|
76
|
+
!response['Status'].start_with?('2')
|
77
|
+
end
|
78
|
+
|
79
|
+
def decode_and_format_error(parsed_response)
|
80
|
+
message = parsed_response['message']
|
77
81
|
|
78
|
-
if
|
82
|
+
if parsed_response.key?('errors')
|
79
83
|
message += ':'
|
80
84
|
|
81
|
-
error_details =
|
85
|
+
error_details = parsed_response['errors'].map do |error_data|
|
82
86
|
error_code = error_data.fetch('code')
|
83
87
|
|
84
88
|
if error_code == 'custom'
|
@@ -94,27 +98,13 @@ module Geet
|
|
94
98
|
message
|
95
99
|
end
|
96
100
|
|
97
|
-
def
|
98
|
-
|
99
|
-
|
100
|
-
!!(status_header =~ /^4\d\d/)
|
101
|
-
end
|
102
|
-
|
103
|
-
def link_next_page(response_metadata)
|
104
|
-
link_header = find_header_content(response_metadata, 'Link')
|
101
|
+
def link_next_page(response_headers)
|
102
|
+
link_header = response_headers['Link']
|
105
103
|
|
106
104
|
return nil if link_header.nil?
|
107
105
|
|
108
106
|
link_header[/<(\S+)>; rel="next"/, 1]
|
109
107
|
end
|
110
|
-
|
111
|
-
def find_header_content(response_metadata, header_name)
|
112
|
-
response_metadata.split("\n").each do |header|
|
113
|
-
return Regexp.last_match(1) if header =~ /^< #{header_name}: (.*)/
|
114
|
-
end
|
115
|
-
|
116
|
-
nil
|
117
|
-
end
|
118
108
|
end
|
119
109
|
end
|
120
110
|
end
|
data/lib/geet/version.rb
CHANGED