Class: GithubWorkflow::Cli
- Inherits:
-
Thor
- Object
- Thor
- GithubWorkflow::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/github_workflow/cli.rb
Constant Summary collapse
- PROCEED_TEXT =
"Proceed? [y,yes]: ".freeze
- TRUNCATE_DEFAULT =
50
Instance Method Summary collapse
- #cleanup ⇒ Object
- #create_and_start ⇒ Object
- #create_pr ⇒ Object
- #deploy_diff ⇒ Object
- #deploy_notes ⇒ Object
- #info ⇒ Object
- #open ⇒ Object
- #push_and_pr ⇒ Object
- #reviews ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
Instance Method Details
#cleanup ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/github_workflow/cli.rb', line 91 def cleanup say_info("Checking merge status") merged_pr_branches puts "\n" if merged_pr_branches.any? say_info("Are you sure you want to delete the branches with checkmarks?") if yes?(PROCEED_TEXT) pass("Deleting Branches") merged_pr_branches.each do |branch| `git branch -D #{branch}` end else failure("Cleanup aborted") end else failure("No merged branches to delete") end end |
#create_and_start ⇒ Object
86 87 88 |
# File 'lib/github_workflow/cli.rb', line 86 def create_and_start create_issue end |
#create_pr ⇒ Object
33 34 35 36 |
# File 'lib/github_workflow/cli.rb', line 33 def create_pr ensure_origin_exists convert_issue_to_pr end |
#deploy_diff ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/github_workflow/cli.rb', line 131 def deploy_diff apps = Daisybill::APPS unless [:all] current_repo = github_client.get_repo_info apps.reject! do |a| a[:github_org] != current_repo[:owner] || a[:github_repo] != current_repo[:repo] end end apps.each do |app| owner = app[:github_org] repo = app[:github_repo] puts "\n**** #{owner}/#{repo} ****\n" full_diff = `heroku pipelines:diff -a #{app[:heroku_staging_app]}` puts full_diff revisions = full_diff.split("compare/").last.strip.split("...") latest_commit = github_client.latest_remote_commit(owner: owner, repo: repo) next if revisions.size < 2 if latest_commit != revisions.last puts "WARNING - heroku staging app deploy is behind at commit #{revisions.last}. The repository is at commit #{latest_commit}" end puts formatted_deploy_notes(revisions.join('...'), owner: owner, repo: repo) end end |
#deploy_notes ⇒ Object
165 166 167 168 |
# File 'lib/github_workflow/cli.rb', line 165 def deploy_notes puts formatted_deploy_notes([:commit_range], owner: github_client.get_repo_info[:owner], repo: github_client.get_repo_info[:repo]) puts formatted_deploy_notes end |
#info ⇒ Object
70 71 72 73 74 75 |
# File 'lib/github_workflow/cli.rb', line 70 def info issue = github_client.get_issue(issue_number_from_branch) puts "#{issue["html_url"]}\n\n" puts "[##{issue["number"]}] #{issue["title"]}\n" puts issue["body"] end |
#open ⇒ Object
78 79 80 |
# File 'lib/github_workflow/cli.rb', line 78 def open open_url(github_client.get_issue(issue_number_from_branch)["html_url"]) end |
#push_and_pr ⇒ Object
41 42 43 44 |
# File 'lib/github_workflow/cli.rb', line 41 def push_and_pr push_and_set_upstream convert_issue_to_pr end |
#reviews ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/github_workflow/cli.rb', line 114 def reviews reviewers = github_client.get_prs_list.map { |pr| pr["requested_reviewers"].map { |r| r["login"] } }.flatten reviewer_counts = reviewers.group_by { |i| i }.map { |k, v| [k, v.count] } if reviewer_counts.any? table = Terminal::Table.new(style: { width: 50 }) do |table_rows| table_rows << ["Username", "Requested PRs Count"] table_rows << :separator reviewer_counts.each { |reviewer_count| table_rows << reviewer_count } end puts table end end |
#start ⇒ Object
23 24 25 26 27 28 |
# File 'lib/github_workflow/cli.rb', line 23 def start stash rebase_main create_branch([:no_checkout]) stash_pop end |
#status ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/github_workflow/cli.rb', line 47 def status ensure_origin_exists response = github_client.get_statuses if response.empty? alert "No statuses yet. Have you pushed your branch?" else table = Terminal::Table.new(style: { width: 80 }) do |table_rows| table_rows << %w(CI Status Description) table_rows << :separator response.map { |status| status["context"] }.uniq.map do |status| response.select { |st| st["context"] == status }.sort_by { |st| st["updated_at"] }.last end.each do |status| table_rows << %w(context state description).map { |key| status[key] } end end puts table end end |