github_workflow 0.3.1 → 0.3.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ca781e1f4ca8c31e5bcb694f2d8985c35807fa5410107c8d1f0972c7bdf52c2
4
- data.tar.gz: 2a9b9af7a96c2ddec30758458c704191d0ba3dae33cc2b4545cfc6a1ba2d5eee
3
+ metadata.gz: a0a60797cbf2bf6f2cebff8d0e30c2e58a02d83883fdd2d7dd66bba5db3f8431
4
+ data.tar.gz: 8117d5c0bd7e18db1e2db9c6c255babc07f3d49885a175e358196a036e79b46e
5
5
  SHA512:
6
- metadata.gz: 1c12e1aa74a8c5b8b8186834d6389ac3201ef5770c30685cd027b6be4845ae3acfafe84a883400b4cbddda32c8217fa14eff34bf7476f02925ea7c0e66562ff7
7
- data.tar.gz: f61e626629fabea130fbe8bc5ec0a6e12f7d92546ae5dce0e09f345c7c3a460c5022be8dce190b6d5cff83711d5223700a0ebce5f4e5831e45abddc27363d821
6
+ metadata.gz: bbe5a3c9a0f19b9c09dbc0a74363ab93cb99405700d8497b0fc5f1d9b95cea76f2915afaf2acba3ee9b98a14369c7afd02c97c0c435e932c007557147ce482f3
7
+ data.tar.gz: ed22679d1d03035b21855408e8540d6e242519e275a896ce00f7bf267ce57bfffa2eff9f84377a5a3b77eee866c1f053b8642bcdd779c7f0610edb8e3805ddc9
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.1
1
+ 2.7.2
@@ -1,4 +1,5 @@
1
1
  require "rubygems"
2
+ require "pry"
2
3
  require "faraday"
3
4
  require "thor"
4
5
  require "open3"
@@ -10,17 +11,52 @@ 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
- checkout_main
24
60
  rebase_main
25
61
  create_branch
26
62
  stash_pop
@@ -28,7 +64,6 @@ module GithubWorkflow
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}?access_token=#{oauth_token}").body)
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}?access_token=#{oauth_token}").body)
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_main
148
- rebase_main
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}?access_token=#{oauth_token}").body)
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}?access_token=#{oauth_token}").body)
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?access_token=#{oauth_token}&per_page=100").body)
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,9 +204,12 @@ 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?access_token=#{oauth_token}", issue_params.to_json).body)
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"]
210
+
211
+ github_client.post("/repos/#{user_and_repo}/issues/#{@issue_id}/comments", { body: trello_card.short_url }.to_json)
212
+ trello_card.add_attachment response["html_url"]
191
213
  end
192
214
 
193
215
  def issue_body_from_trello_card
@@ -219,13 +241,20 @@ module GithubWorkflow
219
241
  end
220
242
 
221
243
  def current_github_username
222
- JSON.parse(github_client.get("user?access_token=#{oauth_token}").body)["login"]
244
+ JSON.parse(github_client.get("user").body)["login"]
223
245
  end
224
246
 
225
- def set_trello_card
247
+ def set_trello_card(type:)
226
248
  say_info("Fetching trello card")
227
- trello_board = Trello::Board.find(project_config["trello_board_id"])
228
- @trello_card = trello_board.cards.detect { |card| card.short_id == options["card_number"].to_i }
249
+
250
+ trello_board =
251
+ if type
252
+ Trello::Board.find(project_config["trello_#{type}_board_id"])
253
+ else
254
+ Trello::Board.find(project_config["trello_board_id"])
255
+ end
256
+
257
+ @trello_card = trello_board.find_card(options["card_number"].to_i)
229
258
  end
230
259
 
231
260
  def trello_card
@@ -233,18 +262,8 @@ module GithubWorkflow
233
262
  end
234
263
 
235
264
  def ensure_github_config_present
236
- unless project_config && project_config["oauth_token"] && project_config["user_and_repo"]
237
- failure('Please add `.github` file containing `{ "oauth_token": "TOKEN", "user_and_repo": "user/repo" }`')
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" }`')
265
+ if project_config.nil? || (JSON.parse(GITHUB_CONFIG).keys - project_config.keys).any?
266
+ failure("Please add `.github_workflow` file containing:\n#{GITHUB_CONFIG}")
248
267
  end
249
268
  end
250
269
 
@@ -256,7 +275,7 @@ module GithubWorkflow
256
275
  end
257
276
 
258
277
  def project_config
259
- @project_config ||= JSON.parse(File.read(".github")) rescue nil
278
+ @project_config ||= JSON.parse(File.read(".github_workflow")) rescue nil
260
279
  end
261
280
 
262
281
  def oauth_token
@@ -273,7 +292,7 @@ module GithubWorkflow
273
292
 
274
293
  def create_issue
275
294
  github_client.post(
276
- "repos/#{user_and_repo}/issues?access_token=#{oauth_token}",
295
+ "repos/#{user_and_repo}/issues",
277
296
  JSON.generate(
278
297
  {
279
298
  title: options[:name]
@@ -297,7 +316,7 @@ module GithubWorkflow
297
316
 
298
317
  def convert_issue_to_pr
299
318
  github_client.post(
300
- "repos/#{user_and_repo}/pulls?access_token=#{oauth_token}",
319
+ "repos/#{user_and_repo}/pulls",
301
320
  JSON.generate(
302
321
  {
303
322
  head: current_branch,
@@ -329,7 +348,7 @@ module GithubWorkflow
329
348
  end
330
349
 
331
350
  def branch_name_for_issue_number
332
- issue = JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{issue_id}?access_token=#{oauth_token}").body)
351
+ issue = JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{issue_id}").body)
333
352
  "#{issue['number']}_#{issue['title'].strip.downcase.gsub(/[^a-zA-Z0-9]/, '_').squeeze("_")}"
334
353
  end
335
354
 
@@ -337,29 +356,20 @@ module GithubWorkflow
337
356
  Faraday.new(url: "https://api.github.com") do |faraday|
338
357
  faraday.request :url_encoded
339
358
  faraday.adapter Faraday.default_adapter
359
+ faraday.authorization :Bearer, oauth_token
340
360
  end
341
361
  end
342
362
 
343
363
  def rebase_main
344
364
  say_info("Fetching changes and rebasing main")
345
365
 
346
- if success?("git pull --rebase")
366
+ if success?("git pull origin main:main --rebase")
347
367
  pass("Fetched and rebased")
348
368
  else
349
369
  failure("Failed to fetch or rebase")
350
370
  end
351
371
  end
352
372
 
353
- def checkout_main
354
- say_info("Checking out main")
355
-
356
- if success?("git checkout main")
357
- pass("Checked out main")
358
- else
359
- failure("Failed to checkout main")
360
- end
361
- end
362
-
363
373
  def stash
364
374
  `git diff --quiet`
365
375
 
@@ -393,7 +403,7 @@ module GithubWorkflow
393
403
  end
394
404
 
395
405
  def commits_for_range
396
- JSON.parse(github_client.get("repos/#{user_and_repo}/compare/#{options[:commit_range]}?access_token=#{oauth_token}").body)
406
+ JSON.parse(github_client.get("repos/#{user_and_repo}/compare/#{options[:commit_range]}").body)
397
407
  end
398
408
 
399
409
  def pull_request_in_commit_range
@@ -403,10 +413,10 @@ module GithubWorkflow
403
413
 
404
414
  prs = pr_ids.map do |id|
405
415
  say_info("Fetching Pull Request ##{id}")
406
- pr = github_client.get("repos/#{user_and_repo}/pulls/#{id}?access_token=#{oauth_token}")
416
+ pr = github_client.get("repos/#{user_and_repo}/pulls/#{id}")
407
417
 
408
418
  if pr.status == 404
409
- JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{id}?access_token=#{oauth_token}").body)
419
+ JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{id}").body)
410
420
  else
411
421
  JSON.parse(pr.body)
412
422
  end
@@ -1,3 +1,3 @@
1
1
  module GithubWorkflow
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.6"
3
3
  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.1
4
+ version: 0.3.6
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: 2021-02-03 00:00:00.000000000 Z
11
+ date: 2021-06-14 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.2
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: []