github_workflow 0.3.0 → 0.3.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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/lib/github_workflow/cli.rb +70 -63
- data/lib/github_workflow/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bcca8d3fca22bc0cf07160f662201e0908833c9070e2cb2b97403bf82d2419e
|
4
|
+
data.tar.gz: f0b4be844e856e5548ecbafd9b8a2dff22c3f70670ada6d3528575bf61379d10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5094dc1f9323c9b29d901b01929d132a83fc948bfdca53d3acdb367afdc3a7c4a965227e45a4ae52f36a2291defde01be718a96815bc99ef42f54351146f12c5
|
7
|
+
data.tar.gz: d90d5ff5f4cc9617712186a8f07fb65f62b9c0bdb1e270809fbd47d429e5c075497189d2c113513791aadcca8e85613d273fa55cd16bb91ce4b072023ef068d1
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.7.
|
1
|
+
2.7.2
|
data/lib/github_workflow/cli.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "rubygems"
|
2
|
+
require "pry"
|
2
3
|
require "faraday"
|
3
4
|
require "thor"
|
4
5
|
require "open3"
|
@@ -10,25 +11,59 @@ module GithubWorkflow
|
|
10
11
|
class Cli < Thor
|
11
12
|
PROCEED_TEXT = "Proceed? [y,yes]: ".freeze
|
12
13
|
|
14
|
+
GITHUB_CONFIG = <<~TEXT
|
15
|
+
{
|
16
|
+
"oauth_token": "TOKEN",
|
17
|
+
"user_and_repo": "ORG/REPO",
|
18
|
+
"trello_key": "KEY",
|
19
|
+
"trello_token": "TOKEN",
|
20
|
+
"trello_board_id": "BOARD_ID",
|
21
|
+
"trello_platform_board_id": "BOARD_ID"
|
22
|
+
}
|
23
|
+
TEXT
|
24
|
+
|
13
25
|
include Thor::Actions
|
14
26
|
|
15
27
|
default_task :trello
|
16
28
|
|
29
|
+
desc "trello", "Create issue from card"
|
30
|
+
method_option :card_number, aliases: "-i", type: :string, required: true
|
31
|
+
def trello
|
32
|
+
ensure_github_config_present
|
33
|
+
init_trello
|
34
|
+
set_trello_card(type: nil)
|
35
|
+
create_issue_from_trello_card
|
36
|
+
stash
|
37
|
+
rebase_main
|
38
|
+
create_branch
|
39
|
+
stash_pop
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "platform", "Create issue from card"
|
43
|
+
method_option :card_number, aliases: "-i", type: :string, required: true
|
44
|
+
def platform
|
45
|
+
ensure_github_config_present
|
46
|
+
init_trello
|
47
|
+
set_trello_card(type: :platform)
|
48
|
+
create_issue_from_trello_card
|
49
|
+
stash
|
50
|
+
rebase_main
|
51
|
+
create_branch
|
52
|
+
stash_pop
|
53
|
+
end
|
54
|
+
|
17
55
|
desc "start", "Create branch named with issue number and issue title"
|
18
56
|
method_option :issue_id, aliases: "-i", type: :string, required: true
|
19
|
-
|
20
57
|
def start
|
21
58
|
ensure_github_config_present
|
22
59
|
stash
|
23
|
-
|
24
|
-
rebase_master
|
60
|
+
rebase_main
|
25
61
|
create_branch
|
26
62
|
stash_pop
|
27
63
|
end
|
28
64
|
|
29
65
|
desc "create_pr", "Convert Issue to Pull Request"
|
30
66
|
method_option :base_branch, aliases: "-b", type: :string
|
31
|
-
|
32
67
|
def create_pr
|
33
68
|
ensure_github_config_present
|
34
69
|
ensure_origin_exists
|
@@ -47,7 +82,7 @@ module GithubWorkflow
|
|
47
82
|
def status
|
48
83
|
ensure_github_config_present
|
49
84
|
ensure_origin_exists
|
50
|
-
response = JSON.parse(github_client.get("repos/#{user_and_repo}/statuses/#{current_branch}
|
85
|
+
response = JSON.parse(github_client.get("repos/#{user_and_repo}/statuses/#{current_branch}").body)
|
51
86
|
|
52
87
|
if response.empty?
|
53
88
|
alert "No statuses yet. Have you pushed your branch?"
|
@@ -76,7 +111,7 @@ module GithubWorkflow
|
|
76
111
|
desc "open", "Open issue or PR in browser"
|
77
112
|
def open
|
78
113
|
ensure_github_config_present
|
79
|
-
response = JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{issue_number_from_branch}
|
114
|
+
response = JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{issue_number_from_branch}").body)
|
80
115
|
`/usr/bin/open -a "/Applications/Google Chrome.app" '#{response["html_url"]}'`
|
81
116
|
end
|
82
117
|
|
@@ -134,37 +169,21 @@ module GithubWorkflow
|
|
134
169
|
puts formatted_deploy_notes
|
135
170
|
end
|
136
171
|
|
137
|
-
desc "trello", "Create issue from card"
|
138
|
-
method_option :card_number, aliases: "-i", type: :string, required: true
|
139
|
-
|
140
|
-
def trello
|
141
|
-
ensure_github_config_present
|
142
|
-
ensure_trello_config_present
|
143
|
-
init_trello
|
144
|
-
set_trello_card
|
145
|
-
create_issue_from_trello_card
|
146
|
-
stash
|
147
|
-
checkout_master
|
148
|
-
rebase_master
|
149
|
-
create_branch
|
150
|
-
stash_pop
|
151
|
-
end
|
152
|
-
|
153
172
|
no_tasks do
|
154
173
|
def get_issue(id)
|
155
|
-
JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{id}
|
174
|
+
JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{id}").body)
|
156
175
|
end
|
157
176
|
|
158
177
|
def get_pr(id)
|
159
|
-
JSON.parse(github_client.get("repos/#{user_and_repo}/pulls/#{id}
|
178
|
+
JSON.parse(github_client.get("repos/#{user_and_repo}/pulls/#{id}").body)
|
160
179
|
end
|
161
180
|
|
162
181
|
def get_prs_list
|
163
|
-
JSON.parse(github_client.get("repos/#{user_and_repo}/pulls
|
182
|
+
JSON.parse(github_client.get("repos/#{user_and_repo}/pulls&per_page=100").body)
|
164
183
|
end
|
165
184
|
|
166
185
|
def create_branch
|
167
|
-
`git checkout -b #{branch_name_for_issue_number}`
|
186
|
+
`git checkout -b #{branch_name_for_issue_number} main`
|
168
187
|
end
|
169
188
|
|
170
189
|
def ensure_origin_exists
|
@@ -185,7 +204,7 @@ module GithubWorkflow
|
|
185
204
|
labels: trello_card.labels.map(&:name)
|
186
205
|
}
|
187
206
|
|
188
|
-
response = JSON.parse(github_client.post("repos/#{user_and_repo}/issues
|
207
|
+
response = JSON.parse(github_client.post("repos/#{user_and_repo}/issues", issue_params.to_json).body)
|
189
208
|
|
190
209
|
@issue_id = response["number"]
|
191
210
|
end
|
@@ -219,12 +238,19 @@ module GithubWorkflow
|
|
219
238
|
end
|
220
239
|
|
221
240
|
def current_github_username
|
222
|
-
JSON.parse(github_client.get("user
|
241
|
+
JSON.parse(github_client.get("user").body)["login"]
|
223
242
|
end
|
224
243
|
|
225
|
-
def set_trello_card
|
244
|
+
def set_trello_card(type:)
|
226
245
|
say_info("Fetching trello card")
|
227
|
-
|
246
|
+
|
247
|
+
trello_board =
|
248
|
+
if type
|
249
|
+
Trello::Board.find(project_config["trello_#{type}_board_id"])
|
250
|
+
else
|
251
|
+
Trello::Board.find(project_config["trello_board_id"])
|
252
|
+
end
|
253
|
+
|
228
254
|
@trello_card = trello_board.cards.detect { |card| card.short_id == options["card_number"].to_i }
|
229
255
|
end
|
230
256
|
|
@@ -233,18 +259,8 @@ module GithubWorkflow
|
|
233
259
|
end
|
234
260
|
|
235
261
|
def ensure_github_config_present
|
236
|
-
|
237
|
-
failure(
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
def ensure_trello_config_present
|
242
|
-
unless project_config &&
|
243
|
-
project_config["trello_board_id"] &&
|
244
|
-
project_config["trello_key"] &&
|
245
|
-
project_config["trello_token"]
|
246
|
-
|
247
|
-
failure('Please add `.github` file containing `{ "trello_key": "KEY", "trello_token": "TOKEN" }`')
|
262
|
+
if project_config.nil? || (JSON.parse(GITHUB_CONFIG).keys - project_config.keys).any?
|
263
|
+
failure("Please add `.github_workflow` file containing:\n#{GITHUB_CONFIG}")
|
248
264
|
end
|
249
265
|
end
|
250
266
|
|
@@ -256,7 +272,7 @@ module GithubWorkflow
|
|
256
272
|
end
|
257
273
|
|
258
274
|
def project_config
|
259
|
-
@project_config ||= JSON.parse(File.read(".
|
275
|
+
@project_config ||= JSON.parse(File.read(".github_workflow")) rescue nil
|
260
276
|
end
|
261
277
|
|
262
278
|
def oauth_token
|
@@ -273,7 +289,7 @@ module GithubWorkflow
|
|
273
289
|
|
274
290
|
def create_issue
|
275
291
|
github_client.post(
|
276
|
-
"repos/#{user_and_repo}/issues
|
292
|
+
"repos/#{user_and_repo}/issues",
|
277
293
|
JSON.generate(
|
278
294
|
{
|
279
295
|
title: options[:name]
|
@@ -297,11 +313,11 @@ module GithubWorkflow
|
|
297
313
|
|
298
314
|
def convert_issue_to_pr
|
299
315
|
github_client.post(
|
300
|
-
"repos/#{user_and_repo}/pulls
|
316
|
+
"repos/#{user_and_repo}/pulls",
|
301
317
|
JSON.generate(
|
302
318
|
{
|
303
319
|
head: current_branch,
|
304
|
-
base: options[:base_branch] || "
|
320
|
+
base: options[:base_branch] || "main",
|
305
321
|
issue: issue_number_from_branch.to_i
|
306
322
|
}
|
307
323
|
)
|
@@ -329,7 +345,7 @@ module GithubWorkflow
|
|
329
345
|
end
|
330
346
|
|
331
347
|
def branch_name_for_issue_number
|
332
|
-
issue = JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{issue_id}
|
348
|
+
issue = JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{issue_id}").body)
|
333
349
|
"#{issue['number']}_#{issue['title'].strip.downcase.gsub(/[^a-zA-Z0-9]/, '_').squeeze("_")}"
|
334
350
|
end
|
335
351
|
|
@@ -337,29 +353,20 @@ module GithubWorkflow
|
|
337
353
|
Faraday.new(url: "https://api.github.com") do |faraday|
|
338
354
|
faraday.request :url_encoded
|
339
355
|
faraday.adapter Faraday.default_adapter
|
356
|
+
faraday.authorization :Bearer, oauth_token
|
340
357
|
end
|
341
358
|
end
|
342
359
|
|
343
|
-
def
|
344
|
-
say_info("Fetching changes and rebasing
|
360
|
+
def rebase_main
|
361
|
+
say_info("Fetching changes and rebasing main")
|
345
362
|
|
346
|
-
if success?("git pull --rebase")
|
363
|
+
if success?("git pull origin main:main --rebase")
|
347
364
|
pass("Fetched and rebased")
|
348
365
|
else
|
349
366
|
failure("Failed to fetch or rebase")
|
350
367
|
end
|
351
368
|
end
|
352
369
|
|
353
|
-
def checkout_master
|
354
|
-
say_info("Checking out master")
|
355
|
-
|
356
|
-
if success?("git checkout master")
|
357
|
-
pass("Checked out master")
|
358
|
-
else
|
359
|
-
failure("Failed to checkout master")
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
370
|
def stash
|
364
371
|
`git diff --quiet`
|
365
372
|
|
@@ -393,7 +400,7 @@ module GithubWorkflow
|
|
393
400
|
end
|
394
401
|
|
395
402
|
def commits_for_range
|
396
|
-
JSON.parse(github_client.get("repos/#{user_and_repo}/compare/#{options[:commit_range]}
|
403
|
+
JSON.parse(github_client.get("repos/#{user_and_repo}/compare/#{options[:commit_range]}").body)
|
397
404
|
end
|
398
405
|
|
399
406
|
def pull_request_in_commit_range
|
@@ -403,10 +410,10 @@ module GithubWorkflow
|
|
403
410
|
|
404
411
|
prs = pr_ids.map do |id|
|
405
412
|
say_info("Fetching Pull Request ##{id}")
|
406
|
-
pr = github_client.get("repos/#{user_and_repo}/pulls/#{id}
|
413
|
+
pr = github_client.get("repos/#{user_and_repo}/pulls/#{id}")
|
407
414
|
|
408
415
|
if pr.status == 404
|
409
|
-
JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{id}
|
416
|
+
JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{id}").body)
|
410
417
|
else
|
411
418
|
JSON.parse(pr.body)
|
412
419
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_workflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Liscio
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -114,7 +114,7 @@ dependencies:
|
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '10.0'
|
117
|
-
description:
|
117
|
+
description:
|
118
118
|
email:
|
119
119
|
- bliscio@daisybill.com
|
120
120
|
executables:
|
@@ -135,7 +135,7 @@ homepage: https://github.com/daisybill/github_workflow
|
|
135
135
|
licenses:
|
136
136
|
- MIT
|
137
137
|
metadata: {}
|
138
|
-
post_install_message:
|
138
|
+
post_install_message:
|
139
139
|
rdoc_options: []
|
140
140
|
require_paths:
|
141
141
|
- lib
|
@@ -150,8 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: '0'
|
152
152
|
requirements: []
|
153
|
-
rubygems_version: 3.1.
|
154
|
-
signing_key:
|
153
|
+
rubygems_version: 3.1.4
|
154
|
+
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: DaisyBill's internal github workflows
|
157
157
|
test_files: []
|