github_workflow 0.1.5 → 0.1.7

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
  SHA1:
3
- metadata.gz: 2acbeaea7ef1702cbba7fe6faac3aafac225f964
4
- data.tar.gz: 3b99436e66d84ecc2064dbae8630a486675b6e49
3
+ metadata.gz: 841c480ec29b5078ab1c744ff47f4a90a86294d9
4
+ data.tar.gz: 65d669c742921894020f471129538bd906c15dd7
5
5
  SHA512:
6
- metadata.gz: aa3ef7a77775f0c6ab062f452cbe1c31226187beeb2d67c723208cba95a509e707c83f21774a51e7b55afa3c743bcf3ee81278ece31eca530f772a1c8d0a6143
7
- data.tar.gz: ff00ad848f3235710e104465a344f5ff0763f3ce117bbe7f19c95633c871f4d6a820a67994190970019b0e8ccdbc13c51f24e421928b597662996978a7c61b0d
6
+ metadata.gz: 651f25d8f43973820c995c9c8f5d1242ffa2533d682d724d7fc714d91d899f1effcf17933b9ca9f1fb6f42a819cde933c634593a1e44c944abc1b4c6fc96a35f
7
+ data.tar.gz: 5e76c09c4f3d29d3cc5138f264f4d2630230b9cec51199d60f46af041ca563e12cd2fe79bf30b9d41d22f21896801ac7f5c6b79ed3833a9a34435ad73622c659
@@ -7,6 +7,8 @@ require "terminal-table"
7
7
 
8
8
  module GithubWorkflow
9
9
  class Cli < Thor
10
+ PROCEED_TEXT = "Proceed? [y,yes]: ".freeze
11
+
10
12
  include Thor::Actions
11
13
 
12
14
  default_task :start
@@ -24,7 +26,6 @@ module GithubWorkflow
24
26
  end
25
27
 
26
28
  desc "create_pr", "Convert Issue to Pull Request"
27
-
28
29
  method_option :base_branch, aliases: "-b", type: :string
29
30
 
30
31
  def create_pr
@@ -34,9 +35,7 @@ module GithubWorkflow
34
35
  end
35
36
 
36
37
  desc "push_and_pr", "Push branch to origin and convert Issue to Pull Request"
37
-
38
38
  method_option :base_branch, aliases: "-b", type: :string
39
-
40
39
  def push_and_pr
41
40
  ensure_github_config_present
42
41
  push_and_set_upstream
@@ -44,7 +43,6 @@ module GithubWorkflow
44
43
  end
45
44
 
46
45
  desc "status", "Check PR CI status"
47
-
48
46
  def status
49
47
  ensure_github_config_present
50
48
  ensure_origin_exists
@@ -69,15 +67,12 @@ module GithubWorkflow
69
67
  end
70
68
 
71
69
  desc "info", "Print out issue description"
72
-
73
70
  def info
74
71
  ensure_github_config_present
75
- response = JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{issue_number_from_branch}?access_token=#{oauth_token}").body)
76
- puts response["body"]
72
+ puts get_issue(issue_number_from_branch)["body"]
77
73
  end
78
74
 
79
75
  desc "open", "Open issue or PR in browser"
80
-
81
76
  def open
82
77
  ensure_github_config_present
83
78
  response = JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{issue_number_from_branch}?access_token=#{oauth_token}").body)
@@ -85,15 +80,44 @@ module GithubWorkflow
85
80
  end
86
81
 
87
82
  desc "create_and_start", "Create and start issue"
88
-
89
83
  method_option :name, aliases: "-m", type: :string, required: true
90
-
91
84
  def create_and_start
92
85
  ensure_github_config_present
93
86
  create_issue
94
87
  end
95
88
 
89
+ desc "cleanup", "Remove merged PR branches"
90
+ def cleanup
91
+ say_info("Checking merge status")
92
+ merged_pr_branches
93
+ puts "\n"
94
+
95
+ if merged_pr_branches.any?
96
+ say_info("Are you sure you want to delete the branches with checkmarks?")
97
+
98
+ if yes?(PROCEED_TEXT)
99
+ pass("Deleting Branches")
100
+
101
+ merged_pr_branches.each do |branch|
102
+ `git branch -D #{branch}`
103
+ end
104
+ else
105
+ failure("Cleanup aborted")
106
+ end
107
+ else
108
+ failure("No merged branches to delete")
109
+ end
110
+ end
111
+
96
112
  no_tasks do
113
+ def get_issue(id)
114
+ JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{id}?access_token=#{oauth_token}").body)
115
+ end
116
+
117
+ def get_pr(id)
118
+ JSON.parse(github_client.get("repos/#{user_and_repo}/pulls/#{id}?access_token=#{oauth_token}").body)
119
+ end
120
+
97
121
  def create_branch
98
122
  `git checkout -b #{branch_name_for_issue_number}`
99
123
  end
@@ -234,6 +258,21 @@ module GithubWorkflow
234
258
  end
235
259
  end
236
260
 
261
+ def merged_pr_branches
262
+ @merged_pr_branches ||=
263
+ pr_branches.map do |branch|
264
+ id = branch.split("_")[0].to_i
265
+ merged = !!get_pr(id)["merged"]
266
+ print merged ? "✅ " : "❌ "
267
+ puts " #{branch}"
268
+ merged ? branch : nil
269
+ end.compact
270
+ end
271
+
272
+ def pr_branches
273
+ `git branch`.gsub(" ", "").split("\n").select { |br| br.match /^[0-9]/ }
274
+ end
275
+
237
276
  def success?(command)
238
277
  IO.popen(command) do |output|
239
278
  output.each { |line| puts line }
@@ -1,3 +1,3 @@
1
1
  module GithubWorkflow
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.7"
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.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Liscio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-20 00:00:00.000000000 Z
11
+ date: 2018-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor