geet 0.27.1 → 0.27.3
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/.rubocop.yml +79 -58
- data/Gemfile +9 -9
- data/Rakefile +2 -2
- data/bin/geet +7 -7
- data/geet.gemspec +19 -19
- data/lib/geet/commandline/commands.rb +16 -15
- data/lib/geet/commandline/configuration.rb +97 -93
- data/lib/geet/commandline/editor.rb +13 -7
- data/lib/geet/git/repository.rb +75 -6
- data/lib/geet/github/abstract_issue.rb +7 -7
- data/lib/geet/github/api_interface.rb +23 -23
- data/lib/geet/github/gist.rb +8 -8
- data/lib/geet/github/issue.rb +6 -6
- data/lib/geet/github/label.rb +5 -5
- data/lib/geet/github/milestone.rb +10 -10
- data/lib/geet/github/pr.rb +25 -25
- data/lib/geet/github/remote_repository.rb +1 -1
- data/lib/geet/github/user.rb +5 -5
- data/lib/geet/gitlab/api_interface.rb +13 -13
- data/lib/geet/gitlab/issue.rb +3 -3
- data/lib/geet/gitlab/label.rb +4 -4
- data/lib/geet/gitlab/milestone.rb +4 -4
- data/lib/geet/gitlab/pr.rb +4 -4
- data/lib/geet/gitlab/user.rb +2 -2
- data/lib/geet/helpers/json_helper.rb +1 -1
- data/lib/geet/helpers/os_helper.rb +5 -5
- data/lib/geet/helpers/services_workflow_helper.rb +4 -4
- data/lib/geet/services/abstract_create_issue.rb +3 -3
- data/lib/geet/services/add_upstream_repo.rb +1 -1
- data/lib/geet/services/close_milestones.rb +9 -2
- data/lib/geet/services/comment_pr.rb +11 -0
- data/lib/geet/services/create_gist.rb +18 -4
- data/lib/geet/services/create_issue.rb +14 -8
- data/lib/geet/services/create_label.rb +22 -3
- data/lib/geet/services/create_milestone.rb +7 -1
- data/lib/geet/services/create_pr.rb +98 -23
- data/lib/geet/services/list_issues.rb +4 -3
- data/lib/geet/services/list_labels.rb +7 -0
- data/lib/geet/services/list_milestones.rb +35 -6
- data/lib/geet/services/list_prs.rb +7 -0
- data/lib/geet/services/merge_pr.rb +20 -2
- data/lib/geet/services/open_pr.rb +2 -2
- data/lib/geet/services/open_repo.rb +7 -1
- data/lib/geet/shared/repo_permissions.rb +4 -4
- data/lib/geet/shared/selection.rb +2 -2
- data/lib/geet/utils/attributes_selection_manager.rb +30 -10
- data/lib/geet/utils/git_client.rb +74 -33
- data/lib/geet/utils/manual_list_selection.rb +23 -11
- data/lib/geet/utils/string_matching_selection.rb +22 -6
- data/lib/geet/version.rb +2 -1
- data/lib/geet.rb +2 -2
- data/spec/integration/comment_pr_spec.rb +10 -10
- data/spec/integration/create_gist_spec.rb +12 -12
- data/spec/integration/create_issue_spec.rb +21 -21
- data/spec/integration/create_label_spec.rb +33 -33
- data/spec/integration/create_milestone_spec.rb +9 -9
- data/spec/integration/create_pr_spec.rb +120 -134
- data/spec/integration/list_issues_spec.rb +25 -25
- data/spec/integration/list_labels_spec.rb +15 -15
- data/spec/integration/list_milestones_spec.rb +15 -15
- data/spec/integration/list_prs_spec.rb +10 -10
- data/spec/integration/merge_pr_spec.rb +18 -18
- data/spec/integration/open_pr_spec.rb +18 -20
- data/spec/integration/open_repo_spec.rb +18 -18
- data/spec/spec_helper.rb +10 -10
- data/spec/unit/github/pr_spec.rb +91 -91
- metadata +2 -3
- data/.rubocop_todo.yml +0 -466
data/lib/geet/github/pr.rb
CHANGED
|
@@ -36,21 +36,21 @@ module Geet
|
|
|
36
36
|
).returns(Geet::Github::PR)
|
|
37
37
|
}
|
|
38
38
|
def self.create(title, description, head, api_interface, base, draft: false)
|
|
39
|
-
api_path =
|
|
39
|
+
api_path = "pulls"
|
|
40
40
|
|
|
41
41
|
if api_interface.upstream?
|
|
42
42
|
authenticated_user = Geet::Github::User.authenticated(api_interface).username
|
|
43
43
|
head = "#{authenticated_user}:#{head}"
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
request_data = {
|
|
46
|
+
request_data = {title:, body: description, head:, base:, draft:}
|
|
47
47
|
|
|
48
48
|
response = T.cast(api_interface.send_request(api_path, data: request_data), T::Hash[String, T.untyped])
|
|
49
49
|
|
|
50
|
-
number = T.cast(response.fetch(
|
|
51
|
-
title = T.cast(response.fetch(
|
|
52
|
-
link = T.cast(response.fetch(
|
|
53
|
-
node_id = T.cast(response[
|
|
50
|
+
number = T.cast(response.fetch("number"), Integer)
|
|
51
|
+
title = T.cast(response.fetch("title"), String)
|
|
52
|
+
link = T.cast(response.fetch("html_url"), String)
|
|
53
|
+
node_id = T.cast(response["node_id"], T.nilable(String))
|
|
54
54
|
|
|
55
55
|
new(number, api_interface, title, link, node_id:)
|
|
56
56
|
end
|
|
@@ -74,7 +74,7 @@ module Geet
|
|
|
74
74
|
check_list_params!(milestone, assignee, head)
|
|
75
75
|
|
|
76
76
|
if head
|
|
77
|
-
api_path =
|
|
77
|
+
api_path = "pulls"
|
|
78
78
|
|
|
79
79
|
# Technically, the upstream approach could be used for both, but it's actually good to have
|
|
80
80
|
# both of them as reference.
|
|
@@ -96,13 +96,13 @@ module Geet
|
|
|
96
96
|
# For this reason, we can't use that param, and have to filter manually.
|
|
97
97
|
#
|
|
98
98
|
unfiltered_response.select do |pr_data|
|
|
99
|
-
pr_head = T.cast(pr_data.fetch(
|
|
100
|
-
label = T.cast(pr_head.fetch(
|
|
99
|
+
pr_head = T.cast(pr_data.fetch("head"), T::Hash[String, T.untyped])
|
|
100
|
+
label = T.cast(pr_head.fetch("label"), String)
|
|
101
101
|
|
|
102
102
|
label == "#{owner}:#{head}"
|
|
103
103
|
end
|
|
104
104
|
else
|
|
105
|
-
request_params = {
|
|
105
|
+
request_params = {head: "#{owner}:#{head}"}
|
|
106
106
|
|
|
107
107
|
T.cast(
|
|
108
108
|
api_interface.send_request(api_path, params: request_params, multipage: true),
|
|
@@ -111,15 +111,15 @@ module Geet
|
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
response.map do |pr_data|
|
|
114
|
-
number = T.cast(pr_data.fetch(
|
|
115
|
-
title = T.cast(pr_data.fetch(
|
|
116
|
-
link = T.cast(pr_data.fetch(
|
|
114
|
+
number = T.cast(pr_data.fetch("number"), Integer)
|
|
115
|
+
title = T.cast(pr_data.fetch("title"), String)
|
|
116
|
+
link = T.cast(pr_data.fetch("html_url"), String)
|
|
117
117
|
|
|
118
118
|
new(number, api_interface, title, link)
|
|
119
119
|
end
|
|
120
120
|
else
|
|
121
121
|
result = super(api_interface, milestone:, assignee:) do |issue_data|
|
|
122
|
-
issue_data.key?(
|
|
122
|
+
issue_data.key?("pull_request")
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
T.cast(result, T::Array[Geet::Github::PR])
|
|
@@ -135,7 +135,7 @@ module Geet
|
|
|
135
135
|
}
|
|
136
136
|
def merge(merge_method: nil)
|
|
137
137
|
api_path = "pulls/#{number}/merge"
|
|
138
|
-
request_data = {
|
|
138
|
+
request_data = {merge_method:} if merge_method
|
|
139
139
|
|
|
140
140
|
@api_interface.send_request(api_path, http_method: :put, data: request_data)
|
|
141
141
|
end
|
|
@@ -147,7 +147,7 @@ module Geet
|
|
|
147
147
|
}
|
|
148
148
|
def request_review(reviewers)
|
|
149
149
|
api_path = "pulls/#{number}/requested_reviewers"
|
|
150
|
-
request_data = {
|
|
150
|
+
request_data = {reviewers:}
|
|
151
151
|
|
|
152
152
|
@api_interface.send_request(api_path, data: request_data)
|
|
153
153
|
end
|
|
@@ -175,7 +175,7 @@ module Geet
|
|
|
175
175
|
}
|
|
176
176
|
GRAPHQL
|
|
177
177
|
|
|
178
|
-
variables = {
|
|
178
|
+
variables = {pullRequestId: @node_id, mergeMethod: merge_method}
|
|
179
179
|
|
|
180
180
|
@api_interface.send_graphql_request(query, variables:)
|
|
181
181
|
|
|
@@ -207,22 +207,22 @@ module Geet
|
|
|
207
207
|
}
|
|
208
208
|
GRAPHQL
|
|
209
209
|
|
|
210
|
-
owner, name = T.must(@api_interface.repository_path).split(
|
|
210
|
+
owner, name = T.must(@api_interface.repository_path).split("/")
|
|
211
211
|
|
|
212
212
|
response = @api_interface.send_graphql_request(query, variables: {owner:, name:, number:})
|
|
213
|
-
repo_data = response[
|
|
214
|
-
commit_count = repo_data[:pullRequest][
|
|
213
|
+
repo_data = response["repository"].transform_keys(&:to_sym)
|
|
214
|
+
commit_count = repo_data[:pullRequest]["commits"]["totalCount"]
|
|
215
215
|
|
|
216
216
|
if commit_count == 1 && repo_data[:squashMergeAllowed]
|
|
217
|
-
|
|
217
|
+
"SQUASH"
|
|
218
218
|
elsif repo_data[:mergeCommitAllowed]
|
|
219
|
-
|
|
219
|
+
"MERGE"
|
|
220
220
|
elsif repo_data[:squashMergeAllowed]
|
|
221
|
-
|
|
221
|
+
"SQUASH"
|
|
222
222
|
elsif repo_data[:rebaseMergeAllowed]
|
|
223
|
-
|
|
223
|
+
"REBASE"
|
|
224
224
|
else
|
|
225
|
-
raise
|
|
225
|
+
raise "No merge methods are allowed on this repository"
|
|
226
226
|
end
|
|
227
227
|
end
|
|
228
228
|
|
|
@@ -43,7 +43,7 @@ module Geet
|
|
|
43
43
|
|
|
44
44
|
response = T.cast(api_interface.send_request(api_path), T::Hash[String, T.untyped])
|
|
45
45
|
|
|
46
|
-
parent_hash = T.cast(response[
|
|
46
|
+
parent_hash = T.cast(response["parent"], T.nilable(T::Hash[String, T.untyped]))
|
|
47
47
|
parent_path = T.cast(parent_hash&.fetch("full_name)"), T.nilable(String))
|
|
48
48
|
|
|
49
49
|
new(api_interface, parent_path:)
|
data/lib/geet/github/user.rb
CHANGED
|
@@ -63,11 +63,11 @@ module Geet
|
|
|
63
63
|
).returns(Geet::Github::User)
|
|
64
64
|
}
|
|
65
65
|
def self.authenticated(api_interface)
|
|
66
|
-
api_path =
|
|
66
|
+
api_path = "/user"
|
|
67
67
|
|
|
68
68
|
response = T.cast(api_interface.send_request(api_path), T::Hash[String, T.untyped])
|
|
69
69
|
|
|
70
|
-
login = T.cast(response.fetch(
|
|
70
|
+
login = T.cast(response.fetch("login"), String)
|
|
71
71
|
|
|
72
72
|
new(login, api_interface)
|
|
73
73
|
end
|
|
@@ -78,11 +78,11 @@ module Geet
|
|
|
78
78
|
).returns(T::Array[Geet::Github::User])
|
|
79
79
|
}
|
|
80
80
|
def self.list_collaborators(api_interface)
|
|
81
|
-
api_path =
|
|
81
|
+
api_path = "collaborators"
|
|
82
82
|
response = T.cast(api_interface.send_request(api_path, multipage: true), T::Array[T::Hash[String, T.untyped]])
|
|
83
83
|
|
|
84
84
|
response.map do |user_entry|
|
|
85
|
-
login = T.cast(user_entry.fetch(
|
|
85
|
+
login = T.cast(user_entry.fetch("login"), String)
|
|
86
86
|
new(login, api_interface)
|
|
87
87
|
end
|
|
88
88
|
end
|
|
@@ -100,7 +100,7 @@ module Geet
|
|
|
100
100
|
|
|
101
101
|
response = T.cast(api_interface.send_request(api_path), T::Hash[String, T.untyped])
|
|
102
102
|
|
|
103
|
-
permission = T.cast(response.fetch(
|
|
103
|
+
permission = T.cast(response.fetch("permission"), String)
|
|
104
104
|
|
|
105
105
|
check_permission!(permission)
|
|
106
106
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# typed: strict
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
4
|
+
require "cgi"
|
|
5
|
+
require "uri"
|
|
6
|
+
require "net/http"
|
|
7
|
+
require "json"
|
|
8
8
|
|
|
9
9
|
module Geet
|
|
10
10
|
module Gitlab
|
|
11
11
|
class ApiInterface
|
|
12
12
|
extend T::Sig
|
|
13
13
|
|
|
14
|
-
API_BASE_URL =
|
|
14
|
+
API_BASE_URL = "https://gitlab.com/api/v4"
|
|
15
15
|
|
|
16
16
|
sig { returns(T.nilable(String)) }
|
|
17
17
|
attr_reader :repository_path
|
|
@@ -126,7 +126,7 @@ module Geet
|
|
|
126
126
|
Net::HTTP.start(uri.host, use_ssl: true) do |http|
|
|
127
127
|
request = http_class.new(uri)
|
|
128
128
|
|
|
129
|
-
request[
|
|
129
|
+
request["Private-Token"] = @api_token
|
|
130
130
|
request.body = URI.encode_www_form(data) if data
|
|
131
131
|
|
|
132
132
|
http.request(request)
|
|
@@ -140,7 +140,7 @@ module Geet
|
|
|
140
140
|
).returns(URI::Generic)
|
|
141
141
|
}
|
|
142
142
|
def encode_uri(address, params)
|
|
143
|
-
address +=
|
|
143
|
+
address += "?" + URI.encode_www_form(params) if params
|
|
144
144
|
|
|
145
145
|
URI(address)
|
|
146
146
|
end
|
|
@@ -151,7 +151,7 @@ module Geet
|
|
|
151
151
|
).returns(T::Boolean)
|
|
152
152
|
}
|
|
153
153
|
def error?(response)
|
|
154
|
-
!response.code.start_with?(
|
|
154
|
+
!response.code.start_with?("2")
|
|
155
155
|
end
|
|
156
156
|
|
|
157
157
|
sig {
|
|
@@ -160,10 +160,10 @@ module Geet
|
|
|
160
160
|
).returns(String)
|
|
161
161
|
}
|
|
162
162
|
def decode_and_format_error(parsed_response)
|
|
163
|
-
if parsed_response.key?(
|
|
164
|
-
parsed_response.fetch(
|
|
165
|
-
elsif parsed_response.key?(
|
|
166
|
-
parsed_response.fetch(
|
|
163
|
+
if parsed_response.key?("error")
|
|
164
|
+
parsed_response.fetch("error")
|
|
165
|
+
elsif parsed_response.key?("message")
|
|
166
|
+
parsed_response.fetch("message")
|
|
167
167
|
else
|
|
168
168
|
"Unrecognized response: #{parsed_response}"
|
|
169
169
|
end
|
|
@@ -176,7 +176,7 @@ module Geet
|
|
|
176
176
|
}
|
|
177
177
|
def link_next_page(response_headers)
|
|
178
178
|
# An array (or nil) is returned.
|
|
179
|
-
link_header = Array(response_headers[
|
|
179
|
+
link_header = Array(response_headers["link"])
|
|
180
180
|
|
|
181
181
|
return nil if link_header.empty?
|
|
182
182
|
|
data/lib/geet/gitlab/issue.rb
CHANGED
|
@@ -50,9 +50,9 @@ module Geet
|
|
|
50
50
|
)
|
|
51
51
|
|
|
52
52
|
response.map do |issue_data, result|
|
|
53
|
-
number = T.cast(issue_data.fetch(
|
|
54
|
-
title = T.cast(issue_data.fetch(
|
|
55
|
-
link = T.cast(issue_data.fetch(
|
|
53
|
+
number = T.cast(issue_data.fetch("iid"), Integer)
|
|
54
|
+
title = T.cast(issue_data.fetch("title"), String)
|
|
55
|
+
link = T.cast(issue_data.fetch("web_url"), String)
|
|
56
56
|
|
|
57
57
|
new(number, title, link)
|
|
58
58
|
end
|
data/lib/geet/gitlab/label.rb
CHANGED
|
@@ -36,10 +36,10 @@ module Geet
|
|
|
36
36
|
)
|
|
37
37
|
|
|
38
38
|
response.map do |label_entry|
|
|
39
|
-
name = T.cast(label_entry.fetch(
|
|
40
|
-
color = T.cast(label_entry.fetch(
|
|
39
|
+
name = T.cast(label_entry.fetch("name"), String)
|
|
40
|
+
color = T.cast(label_entry.fetch("color"), String)
|
|
41
41
|
|
|
42
|
-
color = color.sub(
|
|
42
|
+
color = color.sub("#", "") # normalize
|
|
43
43
|
|
|
44
44
|
new(name, color)
|
|
45
45
|
end
|
|
@@ -55,7 +55,7 @@ module Geet
|
|
|
55
55
|
}
|
|
56
56
|
def self.create(name, color, api_interface)
|
|
57
57
|
api_path = "projects/#{api_interface.path_with_namespace(encoded: true)}/labels"
|
|
58
|
-
request_data = {
|
|
58
|
+
request_data = {name:, color: "##{color}"}
|
|
59
59
|
|
|
60
60
|
api_interface.send_request(api_path, data: request_data)
|
|
61
61
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# typed: strict
|
|
3
3
|
|
|
4
|
-
require
|
|
4
|
+
require "date"
|
|
5
5
|
|
|
6
6
|
module Geet
|
|
7
7
|
module Gitlab
|
|
@@ -49,10 +49,10 @@ module Geet
|
|
|
49
49
|
)
|
|
50
50
|
|
|
51
51
|
response.map do |milestone_data|
|
|
52
|
-
number = T.cast(milestone_data.fetch(
|
|
53
|
-
title = T.cast(milestone_data.fetch(
|
|
52
|
+
number = T.cast(milestone_data.fetch("iid"), Integer)
|
|
53
|
+
title = T.cast(milestone_data.fetch("title"), String)
|
|
54
54
|
due_on = parse_due_date(
|
|
55
|
-
T.cast(milestone_data.fetch(
|
|
55
|
+
T.cast(milestone_data.fetch("due_date"), T.nilable(String))
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
new(number, title, due_on, api_interface)
|
data/lib/geet/gitlab/pr.rb
CHANGED
|
@@ -59,9 +59,9 @@ module Geet
|
|
|
59
59
|
)
|
|
60
60
|
|
|
61
61
|
response.map do |issue_data, result|
|
|
62
|
-
number = T.cast(issue_data.fetch(
|
|
63
|
-
title = T.cast(issue_data.fetch(
|
|
64
|
-
link = T.cast(issue_data.fetch(
|
|
62
|
+
number = T.cast(issue_data.fetch("iid"), Integer)
|
|
63
|
+
title = T.cast(issue_data.fetch("title"), String)
|
|
64
|
+
link = T.cast(issue_data.fetch("web_url"), String)
|
|
65
65
|
|
|
66
66
|
new(number, api_interface, title, link)
|
|
67
67
|
end
|
|
@@ -72,7 +72,7 @@ module Geet
|
|
|
72
72
|
sig { params(comment: String).void }
|
|
73
73
|
def comment(comment)
|
|
74
74
|
api_path = "projects/#{@api_interface.path_with_namespace(encoded: true)}/merge_requests/#{number}/notes"
|
|
75
|
-
request_data = {
|
|
75
|
+
request_data = {body: comment}
|
|
76
76
|
|
|
77
77
|
@api_interface.send_request(api_path, data: request_data)
|
|
78
78
|
end
|
data/lib/geet/gitlab/user.rb
CHANGED
|
@@ -41,8 +41,8 @@ module Geet
|
|
|
41
41
|
)
|
|
42
42
|
|
|
43
43
|
response.map do |user_entry|
|
|
44
|
-
id = T.cast(user_entry.fetch(
|
|
45
|
-
username = T.cast(user_entry.fetch(
|
|
44
|
+
id = T.cast(user_entry.fetch("id"), Integer)
|
|
45
|
+
username = T.cast(user_entry.fetch("username"), String)
|
|
46
46
|
|
|
47
47
|
new(id, username, api_interface)
|
|
48
48
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# typed: true
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
4
|
+
require "English"
|
|
5
|
+
require "open3"
|
|
6
|
+
require "shellwords"
|
|
7
7
|
|
|
8
8
|
module Geet
|
|
9
9
|
module Helpers
|
|
@@ -17,7 +17,7 @@ module Geet
|
|
|
17
17
|
open_command = case
|
|
18
18
|
when ENV["WSL_DISTRO_NAME"]
|
|
19
19
|
"wslview"
|
|
20
|
-
when `uname`.strip ==
|
|
20
|
+
when `uname`.strip == "Darwin"
|
|
21
21
|
"open"
|
|
22
22
|
else
|
|
23
23
|
"xdg-open"
|
|
@@ -61,7 +61,7 @@ module Geet
|
|
|
61
61
|
stdout_content = stdout.read
|
|
62
62
|
stderr_content = stderr.read
|
|
63
63
|
|
|
64
|
-
puts stderr_content if stderr_content !=
|
|
64
|
+
puts stderr_content if stderr_content != "" && !silent_stderr
|
|
65
65
|
|
|
66
66
|
if !wait_thread.value.success? && !allow_error
|
|
67
67
|
error_message = stderr_content.lines.first&.strip || "Error running command #{command.inspect}"
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
4
|
+
require "English"
|
|
5
|
+
require "open3"
|
|
6
|
+
require "shellwords"
|
|
7
7
|
|
|
8
8
|
module Geet
|
|
9
9
|
module Helpers
|
|
@@ -40,7 +40,7 @@ module Geet
|
|
|
40
40
|
|
|
41
41
|
raise "Expected to find only one PR for the current branch; found: #{prs.size}" if prs.size != 1
|
|
42
42
|
|
|
43
|
-
prs[0]
|
|
43
|
+
T.must(prs[0])
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# typed: strict
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
4
|
+
require "stringio"
|
|
5
|
+
require "tmpdir"
|
|
6
6
|
|
|
7
7
|
module Geet
|
|
8
8
|
module Services
|
|
@@ -11,7 +11,7 @@ module Geet
|
|
|
11
11
|
|
|
12
12
|
include Geet::Helpers::OsHelper
|
|
13
13
|
|
|
14
|
-
sig { params(repository:
|
|
14
|
+
sig { params(repository: Git::Repository, out: T.any(IO, StringIO)).void }
|
|
15
15
|
def initialize(repository, out: $stdout)
|
|
16
16
|
@repository = repository
|
|
17
17
|
@out = out
|
|
@@ -10,7 +10,7 @@ module Geet
|
|
|
10
10
|
|
|
11
11
|
DEFAULT_GIT_CLIENT = Utils::GitClient.new
|
|
12
12
|
|
|
13
|
-
sig { params(repository:
|
|
13
|
+
sig { params(repository: Git::Repository, out: T.any(IO, StringIO), git_client: Utils::GitClient).void }
|
|
14
14
|
def initialize(repository, out: $stdout, git_client: DEFAULT_GIT_CLIENT)
|
|
15
15
|
@repository = repository
|
|
16
16
|
@out = out
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: strict
|
|
2
3
|
|
|
3
4
|
module Geet
|
|
4
5
|
module Services
|
|
5
6
|
class CloseMilestones
|
|
7
|
+
extend T::Sig
|
|
8
|
+
|
|
6
9
|
include Geet::Shared::Selection
|
|
7
10
|
|
|
11
|
+
sig { params(repository: Git::Repository, out: T.any(IO, StringIO)).void }
|
|
8
12
|
def initialize(repository, out: $stdout)
|
|
9
13
|
@repository = repository
|
|
10
14
|
@out = out
|
|
11
15
|
end
|
|
12
16
|
|
|
17
|
+
sig { params(numbers: T.nilable(String)).void }
|
|
13
18
|
def execute(numbers: nil)
|
|
14
19
|
numbers = find_and_select_milestone_numbers(numbers)
|
|
15
20
|
|
|
@@ -20,16 +25,18 @@ module Geet
|
|
|
20
25
|
|
|
21
26
|
private
|
|
22
27
|
|
|
28
|
+
sig { params(numbers: T.nilable(String)).returns(T::Array[Integer]) }
|
|
23
29
|
def find_and_select_milestone_numbers(numbers)
|
|
24
30
|
selection_manager = Geet::Utils::AttributesSelectionManager.new(@repository, out: @out)
|
|
25
31
|
|
|
26
|
-
selection_manager.add_attribute(:milestones,
|
|
32
|
+
selection_manager.add_attribute(:milestones, "milestone", numbers, SELECTION_MULTIPLE, name_method: :title)
|
|
27
33
|
|
|
28
|
-
milestones = selection_manager.select_attributes[0]
|
|
34
|
+
milestones = T.cast(selection_manager.select_attributes[0], T::Array[T.any(Github::Milestone, Gitlab::Milestone)])
|
|
29
35
|
|
|
30
36
|
milestones.map(&:number)
|
|
31
37
|
end
|
|
32
38
|
|
|
39
|
+
sig { params(numbers: T::Array[Integer]).returns(T::Array[Thread]) }
|
|
33
40
|
def close_milestones(numbers)
|
|
34
41
|
@out.puts "Closing milestones #{numbers.join(', ')}..."
|
|
35
42
|
|
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: strict
|
|
2
3
|
|
|
3
4
|
module Geet
|
|
4
5
|
module Services
|
|
5
6
|
# Add a comment to the PR for the current branch.
|
|
6
7
|
#
|
|
7
8
|
class CommentPr
|
|
9
|
+
extend T::Sig
|
|
10
|
+
|
|
8
11
|
include Geet::Helpers::OsHelper
|
|
9
12
|
include Geet::Helpers::ServicesWorkflowHelper
|
|
10
13
|
|
|
11
14
|
DEFAULT_GIT_CLIENT = Geet::Utils::GitClient.new
|
|
12
15
|
|
|
16
|
+
sig { params(repository: Git::Repository, out: T.any(IO, StringIO), git_client: Utils::GitClient).void }
|
|
13
17
|
def initialize(repository, out: $stdout, git_client: DEFAULT_GIT_CLIENT)
|
|
14
18
|
@repository = repository
|
|
15
19
|
@out = out
|
|
16
20
|
@git_client = git_client
|
|
17
21
|
end
|
|
18
22
|
|
|
23
|
+
sig {
|
|
24
|
+
params(
|
|
25
|
+
comment: String,
|
|
26
|
+
open_browser: T::Boolean
|
|
27
|
+
)
|
|
28
|
+
.returns(T.any(Github::PR, Gitlab::PR))
|
|
29
|
+
}
|
|
19
30
|
def execute(comment, open_browser: false)
|
|
20
31
|
pr = checked_find_branch_pr
|
|
21
32
|
pr.comment(comment)
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: strict
|
|
2
3
|
|
|
3
4
|
module Geet
|
|
4
5
|
module Services
|
|
5
6
|
class CreateGist
|
|
7
|
+
extend T::Sig
|
|
8
|
+
|
|
6
9
|
include Geet::Helpers::OsHelper
|
|
7
10
|
|
|
8
|
-
API_TOKEN_KEY =
|
|
11
|
+
API_TOKEN_KEY = "GITHUB_API_TOKEN"
|
|
9
12
|
DEFAULT_GIT_CLIENT = Geet::Utils::GitClient.new
|
|
10
13
|
|
|
14
|
+
sig { params(out: T.any(IO, StringIO)).void }
|
|
11
15
|
def initialize(out: $stdout)
|
|
12
|
-
@out = out
|
|
16
|
+
@out = T.let(out, T.any(IO, StringIO))
|
|
13
17
|
|
|
14
18
|
api_token = extract_env_api_token
|
|
15
|
-
@api_interface = Geet::Github::ApiInterface.new(api_token)
|
|
19
|
+
@api_interface = T.let(Geet::Github::ApiInterface.new(api_token), Geet::Github::ApiInterface)
|
|
16
20
|
end
|
|
17
21
|
|
|
18
22
|
# options:
|
|
@@ -20,10 +24,19 @@ module Geet
|
|
|
20
24
|
# :publik: defaults to false
|
|
21
25
|
# :open_browser defaults to true
|
|
22
26
|
#
|
|
27
|
+
sig {
|
|
28
|
+
params(
|
|
29
|
+
full_filename: String,
|
|
30
|
+
stdin: T::Boolean,
|
|
31
|
+
description: T.nilable(String),
|
|
32
|
+
publik: T::Boolean,
|
|
33
|
+
open_browser: T::Boolean
|
|
34
|
+
).void
|
|
35
|
+
}
|
|
23
36
|
def execute(full_filename, stdin: false, description: nil, publik: false, open_browser: false)
|
|
24
37
|
content = stdin ? $stdin.read : IO.read(full_filename)
|
|
25
38
|
|
|
26
|
-
gist_access = publik ?
|
|
39
|
+
gist_access = publik ? "public" : "private"
|
|
27
40
|
@out.puts "Creating a #{gist_access} gist..."
|
|
28
41
|
|
|
29
42
|
filename = File.basename(full_filename)
|
|
@@ -38,6 +51,7 @@ module Geet
|
|
|
38
51
|
|
|
39
52
|
private
|
|
40
53
|
|
|
54
|
+
sig { returns(String) }
|
|
41
55
|
def extract_env_api_token
|
|
42
56
|
ENV[API_TOKEN_KEY] || raise("#{API_TOKEN_KEY} not set!")
|
|
43
57
|
end
|
|
@@ -62,17 +62,23 @@ module Geet
|
|
|
62
62
|
).returns([
|
|
63
63
|
T.nilable(T::Array[T.any(Github::Label, Gitlab::Label)]),
|
|
64
64
|
T.nilable(T.any(Github::Milestone, Gitlab::Milestone)),
|
|
65
|
-
T.nilable(T::Array[T.any(Github::User, Gitlab::User)])
|
|
65
|
+
T.nilable(T::Array[T.any(Github::User, Gitlab::User)]),
|
|
66
66
|
])
|
|
67
67
|
}
|
|
68
68
|
def find_and_select_attributes(labels, milestone, assignees)
|
|
69
69
|
selection_manager = Geet::Utils::AttributesSelectionManager.new(@repository, out: @out)
|
|
70
70
|
|
|
71
|
-
selection_manager.add_attribute(:labels,
|
|
72
|
-
selection_manager.add_attribute(:milestones,
|
|
73
|
-
selection_manager.add_attribute(:collaborators,
|
|
71
|
+
selection_manager.add_attribute(:labels, "label", labels, SELECTION_MULTIPLE, name_method: :name) if labels
|
|
72
|
+
selection_manager.add_attribute(:milestones, "milestone", milestone, SELECTION_SINGLE, name_method: :title) if milestone
|
|
73
|
+
selection_manager.add_attribute(:collaborators, "assignee", assignees, SELECTION_MULTIPLE, name_method: :username) if assignees
|
|
74
74
|
|
|
75
|
-
selection_manager.select_attributes
|
|
75
|
+
selected_attributes = selection_manager.select_attributes
|
|
76
|
+
|
|
77
|
+
selected_labels = T.cast(selected_attributes.shift, T.nilable(T::Array[T.any(Github::Label, Gitlab::Label)])) if labels
|
|
78
|
+
selected_milestone = T.cast(selected_attributes.shift, T.nilable(T.any(Github::Milestone, Gitlab::Milestone))) if milestone
|
|
79
|
+
selected_assignees = T.cast(selected_attributes.shift, T.nilable(T::Array[T.any(Github::User, Gitlab::User)])) if assignees
|
|
80
|
+
|
|
81
|
+
[selected_labels, selected_milestone, selected_assignees]
|
|
76
82
|
end
|
|
77
83
|
|
|
78
84
|
sig {
|
|
@@ -82,7 +88,7 @@ module Geet
|
|
|
82
88
|
).returns(T.any(Github::Issue, Gitlab::Issue))
|
|
83
89
|
}
|
|
84
90
|
def create_issue(title, description)
|
|
85
|
-
@out.puts
|
|
91
|
+
@out.puts "Creating the issue..."
|
|
86
92
|
|
|
87
93
|
issue = @repository.create_issue(title, description)
|
|
88
94
|
end
|
|
@@ -122,7 +128,7 @@ module Geet
|
|
|
122
128
|
def add_labels(issue, selected_labels)
|
|
123
129
|
raise "Functionality unsupported on GitLab!" if issue.is_a?(Gitlab::Issue)
|
|
124
130
|
|
|
125
|
-
labels_list = selected_labels.map(&:name).join(
|
|
131
|
+
labels_list = selected_labels.map(&:name).join(", ")
|
|
126
132
|
|
|
127
133
|
@out.puts "Adding labels #{labels_list}..."
|
|
128
134
|
|
|
@@ -173,7 +179,7 @@ module Geet
|
|
|
173
179
|
def assign_authenticated_user(issue)
|
|
174
180
|
raise "Functionality unsupported on GitLab!" if issue.is_a?(Gitlab::Issue)
|
|
175
181
|
|
|
176
|
-
@out.puts
|
|
182
|
+
@out.puts "Assigning authenticated user..."
|
|
177
183
|
|
|
178
184
|
Thread.new do
|
|
179
185
|
issue.assign_users(@repository.authenticated_user.username)
|