geet 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5179b22079f6fef1c7bc0d4559cedea9f7ce8b5c
4
- data.tar.gz: ef9fd7a82c156274908dab31008c31f90096ce49
3
+ metadata.gz: 033e3851278fd2e0b27bbf58ed7b4fe63f1dc293
4
+ data.tar.gz: 5a89dbdd4d43594638e67453d9cdaab7c64bfcf4
5
5
  SHA512:
6
- metadata.gz: 64834768832dfcffe28ff36e43fc8c453667be6032049f2dd34ed655da38f0b0e7c8840bf634b24467c154052026edd44ce34cd71a9c634969c13d07671227e0
7
- data.tar.gz: c0d92c7037c183cc614144bf18551268eb682e99122c5e930685bdf0839d579d599770e7f56645dc2a01f876b4e80920417507a75c809616df7155f6763a0044
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
- $ geet pr 'PR Title' 'PR Description
13
+ $ geet issue create 'Issue Title' 'Issue Description'
14
+
15
+ $ geet pr create 'PR Title' 'Multi-line
15
16
  >
16
- > Closes #1' --label-patterns "code review" --reviewer-patterns john,tom,adrian
17
+ > description'
17
18
 
18
- Create an issue, adding the label matching `bug`, and assigning it to the collaborators matching `john`, `tom`, `kevin`:
19
+ More advanced issue/PR creation, with label, reviewers and assignees:
19
20
 
20
- $ geet issue 'Issue Title' 'Issue Description' --label-patterns "code review" --assignee-patterns john,tom,kevin
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
- Create a PR, adding the label matching `code review`, and requesting reviews from the collaborators matching `john`, `tom`, `adrian`:
25
+ patterns are partial matches, so, for example, `johncarmack` will be matched as assignee in the first case.
23
26
 
24
- $ geet pr 'PR Title' 'PR Description
25
- >
26
- > Closes #1' --label-patterns "code review" --reviewer-patterns john,tom,adrian
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
- command = %(curl --verbose --silent --user "#{@user}:#{@api_token}" #{data_option} #{address})
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(response_body)
38
+ parsed_response = JSON.parse(response.body)
57
39
 
58
- if error?(response_metadata)
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(response_metadata)
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 decode_and_format_error(response)
76
- message = response['message']
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 response.key?('errors')
82
+ if parsed_response.key?('errors')
79
83
  message += ':'
80
84
 
81
- error_details = response['errors'].map do |error_data|
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 error?(response_metadata)
98
- status_header = find_header_content(response_metadata, 'Status')
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
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # require_relative '../helpers/os_helper.rb'
4
- # require_relative '../git/repository.rb'
5
-
6
3
  module Geet
7
4
  module Services
8
5
  class ListIssues
@@ -1,3 +1,3 @@
1
1
  module Geet
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saverio Miroddi