Class: Socialcast::Gitx::CLI
Constant Summary
collapse
- PULL_REQUEST_DESCRIPTION =
"\n\n" + " # Use GitHub flavored Markdown http://github.github.com/github-flavored-markdown/\n # Links to screencasts or screenshots with a desciption of what this is showcasing. For architectual changes please include diagrams that will make it easier for the reviewer to understand the change. Format is .\n # Link to ticket describing feature/bug (plantain, JIRA, bugzilla). Format is [title](url).\n # Brief description of the change, and how it accomplishes the task they set out to do.\n".dedent
DEFAULT_BASE_BRANCH, DEFAULT_LAST_KNOWN_GOOD_STAGING_BRANCH, DEFAULT_PROTOTYPE_BRANCH, DEFAULT_STAGING_BRANCH, VERSION
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ CLI
25
26
27
28
29
|
# File 'lib/socialcast-git-extensions/cli.rb', line 25
def initialize(*args)
super(*args)
RestClient.proxy = ENV['HTTPS_PROXY'] if ENV.has_key?('HTTPS_PROXY')
RestClient.log = Logger.new(STDOUT) if options[:trace]
end
|
Instance Method Details
#backportpr(pull_request_num, maintenance_branch) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/socialcast-git-extensions/cli.rb', line 87
def backportpr(pull_request_num, maintenance_branch)
original_base_branch = ENV['BASE_BRANCH']
ENV['BASE_BRANCH'] = maintenance_branch
repo = current_repo
assignee = github_track_reviewer('Backport')
socialcast_reviewer = socialcast_track_reviewer('Backport')
pull_request_data = github_api_request('GET', "repos/#{repo}/pulls/#{pull_request_num}")
commits_data = github_api_request('GET', pull_request_data['commits_url'])
non_merge_commits_data = commits_data.select { |commit_data| commit_data['parents'].length == 1 }
shas = non_merge_commits_data.map { |commit| commit['sha'] }
backport_branch = "backport_#{pull_request_num}_to_#{maintenance_branch}"
backport_to(backport_branch, shas)
maintenance_branch_url = "https://github.com/#{repo}/tree/#{maintenance_branch}"
description = "Backport ##{pull_request_num} to #{maintenance_branch_url}\n***\n#{pull_request_data['body']}"
pull_request_url = create_pull_request(backport_branch, repo, description, assignee)
review_message = ["#reviewrequest backport ##{pull_request_num} to #{maintenance_branch} in #{current_repo} #scgitx"]
if socialcast_reviewer
review_message << "/cc @#{socialcast_reviewer} for #backport track"
end
review_message << "/cc @#{developer_group}"
post review_message.join("\n\n"), :url => pull_request_url, :message_type => 'review_request'
ensure
ENV['BASE_BRANCH'] = original_base_branch
end
|
#cleanup ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/socialcast-git-extensions/cli.rb', line 135
def cleanup
run_cmd "git checkout #{base_branch}"
run_cmd "git pull"
run_cmd 'git remote prune origin'
say "Deleting branches that have been merged into "
say base_branch, :green
branches(:merged => true, :remote => true).each do |branch|
run_cmd "git push origin --delete #{branch}" unless reserved_branch?(branch)
end
branches(:merged => true).each do |branch|
run_cmd "git branch -d #{branch}" unless reserved_branch?(branch)
end
end
|
#findpr(commit_hash) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/socialcast-git-extensions/cli.rb', line 73
def findpr(commit_hash)
repo = current_repo
data = pull_requests_for_commit(repo, commit_hash)
if data['items']
data['items'].each do |entry|
say "\n" << [entry['html_url'], entry['title'], "#{entry['user'] && entry['user']['login']} #{entry['created_at']}"].join("\n\t")
end
else
say "No results found", :yellow
end
end
|
#integrate(target_branch = prototype_branch) ⇒ Object
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/socialcast-git-extensions/cli.rb', line 186
def integrate(target_branch = prototype_branch)
branch = current_branch
update
integrate_branch(branch, target_branch)
integrate_branch(target_branch, prototype_branch) if target_branch == staging_branch
run_cmd "git checkout #{branch}"
message = " #worklog integrating \#{branch} into \#{target_branch} in \#{current_repo} #scgitx\n /cc @\#{developer_group}\n EOS\n\n post message.strip\nend\n".strip_heredoc
|
#nuke(bad_branch) ⇒ Object
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/socialcast-git-extensions/cli.rb', line 210
def nuke(bad_branch)
default_good_branch = "last_known_good_#{bad_branch}"
good_branch = options[:destination] || ask("What branch do you want to reset #{bad_branch} to? (default: #{default_good_branch})")
good_branch = default_good_branch if good_branch.length == 0
good_branch = "last_known_good_#{good_branch}" unless good_branch.starts_with?('last_known_good_')
removed_branches = nuke_branch(bad_branch, good_branch)
nuke_branch("last_known_good_#{bad_branch}", good_branch)
message = " #worklog resetting \#{bad_branch} branch to \#{good_branch} in \#{current_repo} #scgitx\n /cc @\#{developer_group}\n EOS\n\n if removed_branches.any?\n message += <<-EOS.strip_heredoc\n\n The following branches were affected:\n EOS\n message += removed_branches.map{ |b| ['*', b].join(' ') }.join(\"\\n\")\n end\n\n post message.strip\nend\n".strip_heredoc
|
203
204
205
206
|
# File 'lib/socialcast-git-extensions/cli.rb', line 203
def promote
say "DEPRECATED: Use `git integrate #{staging_branch}` instead", :red
integrate staging_branch
end
|
#release ⇒ Object
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'lib/socialcast-git-extensions/cli.rb', line 236
def release
branch = current_branch
assert_not_protected_branch!(branch, 'release')
if enforce_staging_before_release?
assert_in_last_known_good_staging(branch)
end
return unless yes?("Release #{branch} to production? (y/n)", :green)
update
run_cmd "git checkout #{base_branch}"
run_cmd "git pull origin #{base_branch}"
run_cmd "git pull . #{branch}"
run_cmd "git push origin HEAD"
integrate_branch(base_branch, staging_branch)
cleanup
message = " #worklog releasing \#{branch} to \#{base_branch} in \#{current_repo} #scgitx\n /cc @\#{developer_group}\n EOS\n\n post message.strip\nend\n".strip_heredoc
|
#reviewrequest(*additional_reviewers) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/socialcast-git-extensions/cli.rb', line 36
def reviewrequest(*additional_reviewers)
update
review_mention = if buddy = socialcast_review_buddy(current_user)
"Assigned to @#{buddy}"
end
if !specialty_reviewers.empty? && !options.key?('skip_additional_reviewers')
additional_reviewers = options[:additional_reviewers] || additional_reviewers
if additional_reviewers.empty?
prompt_text = "#{specialty_reviewers.map { |_,v| v['command'] }.join(", ")} or (or hit enter to continue): "
additional_reviewers = $terminal.ask("Notify additional people? #{prompt_text} ")
end
additional_reviewers = additional_reviewers.is_a?(String) ? additional_reviewers.split(" ") : additional_reviewers
(specialty_reviewers.keys & additional_reviewers).each do |command|
reviewer = specialty_reviewers[command]
review_mention = review_mention || ''
review_mention += "\nAssigned additionally to @#{reviewer['socialcast_username']} for #{reviewer['label']} review"
end
end
assignee = github_review_buddy(current_user)
description = options[:description] || editor_input(PULL_REQUEST_DESCRIPTION)
branch = current_branch
repo = current_repo
url = create_pull_request branch, repo, description, assignee
say "Pull request created: #{url}"
review_message = ["#reviewrequest for #{branch} in #{current_repo} #scgitx", "/cc @#{developer_group}", review_mention, description, changelog_summary(branch)].compact.join("\n\n")
post review_message, :url => url, :message_type => 'review_request'
end
|
#share ⇒ Object
181
182
183
|
# File 'lib/socialcast-git-extensions/cli.rb', line 181
def share
share_branch current_branch
end
|
#start(branch_name = nil) ⇒ Object
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/socialcast-git-extensions/cli.rb', line 156
def start(branch_name = nil)
unless branch_name
example_branch = %w{ cpr-3922-api-fix-invalid-auth red-212-desktop-cleanup-avatar-markup red-3212-share-form-add-edit-link }.sample
repo = Grit::Repo.new(Dir.pwd)
remote_branches = repo.remotes.collect {|b| b.name.split('/').last }
branch_name = $terminal.ask("What would you like to name your branch? (ex: #{example_branch})") do |q|
q.validate = lambda { |branch| branch =~ /^[A-Za-z0-9\-_]+$/ && !remote_branches.include?(branch) }
q.responses[:not_valid] = "This branch name is either already taken, or is not a valid branch name"
end
end
run_cmd "git checkout #{base_branch}"
run_cmd 'git pull'
run_cmd "git checkout -b #{branch_name}"
message = " #worklog starting work on \#{branch_name} in \#{current_repo} #scgitx\n /cc @\#{developer_group}\n EOS\n\n post message.strip\nend\n".strip_heredoc
|
#track ⇒ Object
151
152
153
|
# File 'lib/socialcast-git-extensions/cli.rb', line 151
def track
track_branch current_branch
end
|
#update ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/socialcast-git-extensions/cli.rb', line 121
def update
branch = current_branch
say 'updating '
say "#{branch} ", :green
say "to have most recent changes from "
say base_branch, :green
run_cmd "git pull origin #{branch}" rescue nil
run_cmd "git pull origin #{base_branch}"
run_cmd 'git push origin HEAD'
end
|