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_PROTOTYPE_BRANCH, DEFAULT_STAGING_BRANCH, VERSION
Instance Method Summary
collapse
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
21
22
23
24
25
|
# File 'lib/socialcast-git-extensions/cli.rb', line 21
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
#cleanup ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/socialcast-git-extensions/cli.rb', line 67
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 aggregate_branch?(branch)
end
branches(:merged => true).each do |branch|
run_cmd "git branch -d #{branch}" unless aggregate_branch?(branch)
end
end
|
#integrate(target_branch = prototype_branch) ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/socialcast-git-extensions/cli.rb', line 114
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}"
post "#worklog integrating #{branch} into #{target_branch} #scgitx"
end
|
#nuke(bad_branch) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/socialcast-git-extensions/cli.rb', line 133
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_parts = []
message_parts << "#worklog resetting #{bad_branch} branch to #{good_branch} #scgitx"
message_parts << "/cc @SocialcastDevelopers"
if removed_branches.any?
message_parts << ""
message_parts << "the following branches were affected:"
message_parts += removed_branches.map{|b| ['*', b].join(' ')}
end
post message_parts.join("\n")
end
|
126
127
128
129
|
# File 'lib/socialcast-git-extensions/cli.rb', line 126
def promote
say "DEPRECATED: Use `git integrate #{staging_branch}` instead", :red
integrate staging_branch
end
|
#release ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/socialcast-git-extensions/cli.rb', line 154
def release
branch = current_branch
assert_not_protected_branch!(branch, 'release')
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
post "#worklog releasing #{branch} to #{base_branch} #scgitx"
end
|
#reviewrequest ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/socialcast-git-extensions/cli.rb', line 30
def reviewrequest
token = authorization_token
update
review_mention = if buddy = socialcast_review_buddy(current_user)
"Assigned to @#{buddy}"
end
description = options[:description] || editor_input(PULL_REQUEST_DESCRIPTION)
branch = current_branch
repo = current_repo
url = create_pull_request token, branch, repo, description
say "Pull request created: #{url}"
short_description = description.split("\n").first(5).join("\n")
review_message = ["#reviewrequest for #{branch} #scgitx", "/cc @SocialcastDevelopers", review_mention, short_description, changelog_summary(branch)].compact.join("\n\n")
post review_message, :url => url, :message_type => 'review_request'
end
|
#share ⇒ Object
109
110
111
|
# File 'lib/socialcast-git-extensions/cli.rb', line 109
def share
share_branch current_branch
end
|
#start(branch_name = nil) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/socialcast-git-extensions/cli.rb', line 88
def start(branch_name = nil)
unless branch_name
example_branch = %w{ api-fix-invalid-auth desktop-cleanup-avatar-markup share-form-add-edit-link }.sort_by { rand }.first
repo = Grit::Repo.new(Dir.pwd)
remote_branches = repo.remotes.collect {|b| b.name.split('/').last }
until branch_name = ask("What would you like to name your branch? (ex: #{example_branch})") {|q|
q.validate = Proc.new { |branch|
branch =~ /^[A-Za-z0-9\-_]+$/ && !remote_branches.include?(branch)
}
}
end
end
run_cmd "git checkout #{base_branch}"
run_cmd 'git pull'
run_cmd "git checkout -b #{branch_name}"
post "#worklog starting work on #{branch_name} #scgitx"
end
|
#track ⇒ Object
83
84
85
|
# File 'lib/socialcast-git-extensions/cli.rb', line 83
def track
track_branch current_branch
end
|
#update ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/socialcast-git-extensions/cli.rb', line 53
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
|