thegarage-gitx 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80aafd556ae6dca4c266fe24a0bdfb5800b35f14
4
- data.tar.gz: 3832c3bc543af63458d8e3aa903c01f4b6cda9ba
3
+ metadata.gz: 9601c51e9fb7c39a2290715c05e752aeb5898c58
4
+ data.tar.gz: f0947bba05dcedbae40a94a770075b837f0b8fb3
5
5
  SHA512:
6
- metadata.gz: 63a56af292e550422d1cce4160cf4dd85185cb3a7ea0af4c8a56c4f200644e386a3317d17c9c59fc546f937ad207ec38c1f93480a3c582d568bfaa286c07c129
7
- data.tar.gz: 37c2ce8e2a6919ab9f9ea8ab7581e1af0f86d436862763cd59fe68d1703ea0357ef052297c3551d5fc6a9bff2ae09132365edc7372bec1b03ebcecdc0905ab18
6
+ metadata.gz: 8fb42815aa779d1b86f52d5c3c07f34fe1d06a8b97992a950d2e5cb7b1a9ab02d35d8131756cf780193039b5cfaf96bee9256204355878a6a8677a1ec6c07034
7
+ data.tar.gz: 5efd37b850dd801e9dd91537c70dc7e0616f1a4c601407789cf71594e9decbf5d5db221f8b90a4b0cd2b3b46dddc34066c7db7c4bd958c44e31093479fb2dc6f
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # thegarage-gitx
2
2
 
3
- [![Build Status](https://travis-ci.org/thegarage/thegarage-gitx.png?branch=fix-rspec-mocks)](https://travis-ci.org/thegarage/thegarage-gitx)
3
+ [![Build Status](https://travis-ci.org/thegarage/thegarage-gitx.png?branch=master)](https://travis-ci.org/thegarage/thegarage-gitx)
4
4
 
5
5
  Useful Git eXtensions for Development workflow at The Garage.
6
6
 
@@ -12,13 +12,14 @@ module Thegarage
12
12
  include Thegarage::Gitx::Git
13
13
  include Thegarage::Gitx::Github
14
14
 
15
- PULL_REQUEST_DESCRIPTION = "\n\n" + <<-EOS.dedent
15
+ TAGGABLE_BRANCHES = %w(master staging)
16
+ PULL_REQUEST_FOOTER = <<-EOS.dedent
17
+ # Pull Request Protips
18
+ # Include description of how this change accomplishes the task at hand.
16
19
  # Use GitHub flavored Markdown http://github.github.com/github-flavored-markdown/
17
- # 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 ![title](url).
18
- # Link to ticket describing feature/bug (plantain, JIRA, bugzilla). Format is [title](url).
19
- # Brief description of the change, and how it accomplishes the task they set out to do.
20
+ # Review CONTRIBUTING.md for recommendations of artifacts, links, images, screencasts, etc.
21
+ # NOTE: this footer will automatically be stripped from the pull request.
20
22
  EOS
21
- TAGGABLE_BRANCHES = %w(master staging)
22
23
 
23
24
  method_option :trace, :type => :boolean, :aliases => '-v'
24
25
  def initialize(*args)
@@ -34,11 +35,20 @@ module Thegarage
34
35
  update
35
36
 
36
37
  token = authorization_token
37
- description = options[:description] || editor_input(PULL_REQUEST_DESCRIPTION)
38
+ changelog = run_cmd "git log #{BASE_BRANCH}...#{current_branch} --no-merges --pretty=format:'%ci - %s%n%b'"
39
+ description_template = []
40
+ description_template << options[:description]
41
+ description_template << "\n"
42
+ description_template << '### Changelog'
43
+ description_template << changelog
44
+ description_template << "\n"
45
+ description_template << PULL_REQUEST_FOOTER
46
+
47
+ description = editor_input(description_template.join("\n"))
38
48
  branch = current_branch
39
49
  repo = current_remote_repo
40
50
  url = create_pull_request token, branch, repo, description
41
- say "Pull request created: #{url}"
51
+ say "Pull request created: #{url}", :green
42
52
  end
43
53
 
44
54
  # TODO: use --no-edit to skip merge messages
@@ -117,9 +127,7 @@ module Thegarage
117
127
  good_branch = options[:destination] || ask("What branch do you want to reset #{bad_branch} to? (default: #{bad_branch})")
118
128
  good_branch = bad_branch if good_branch.length == 0
119
129
 
120
- run_cmd "git fetch --tags"
121
- good_tags = run_cmd("git tag -l 'build-#{good_branch}-*'").split
122
- last_known_good_tag = good_tags.sort.last
130
+ last_known_good_tag = build_tags_for_branch(good_branch).last
123
131
  raise "No known good tag found for branch: #{good_branch}. Verify tag exists via `git tag -l 'build-#{good_branch}-*'`" unless last_known_good_tag
124
132
  return unless yes?("Reset #{bad_branch} to #{last_known_good_tag}? (y/n)", :green)
125
133
 
@@ -143,20 +151,18 @@ module Thegarage
143
151
 
144
152
  desc 'buildtag', 'create a tag for the current Travis-CI build and push it back to origin'
145
153
  def buildtag
146
- travis_branch = ENV['TRAVIS_BRANCH']
154
+ branch = ENV['TRAVIS_BRANCH']
147
155
  pull_request = ENV['TRAVIS_PULL_REQUEST']
148
-
149
- raise "Unknown branch. ENV['TRAVIS_BRANCH'] is required." unless travis_branch
150
-
156
+
157
+ raise "Unknown branch. ENV['TRAVIS_BRANCH'] is required." unless branch
158
+
151
159
  if pull_request != 'false'
152
160
  say "Skipping creation of tag for pull request: #{pull_request}"
153
- elsif !TAGGABLE_BRANCHES.include?(travis_branch)
154
- say "Cannot create build tag for branch: #{travis_branch}. Only #{TAGGABLE_BRANCHES} are supported."
161
+ elsif !TAGGABLE_BRANCHES.include?(branch)
162
+ say "Cannot create build tag for branch: #{branch}. Only #{TAGGABLE_BRANCHES} are supported."
155
163
  else
156
- timestamp = Time.now.utc.strftime '%Y-%m-%d-%H-%M-%S'
157
- git_tag = "build-#{travis_branch}-#{timestamp}"
158
- run_cmd "git tag #{git_tag} -a -m 'Generated tag from TravisCI build #{ENV['TRAVIS_BUILD_NUMBER']}'"
159
- run_cmd "git push origin #{git_tag}"
164
+ label = "Generated tag from TravisCI build #{ENV['TRAVIS_BUILD_NUMBER']}"
165
+ create_build_tag(branch, label)
160
166
  end
161
167
  end
162
168
 
@@ -60,19 +60,21 @@ module Thegarage
60
60
  end
61
61
 
62
62
  # reset the specified aggregate branch to the same set of commits as the destination branch
63
- def nuke_branch(branch, head_branch)
64
- return if branch == head_branch
65
- raise "Only aggregate branches are allowed to be reset: #{AGGREGATE_BRANCHES}" unless aggregate_branch?(branch)
63
+ def nuke_branch(outdated_branch, head_branch)
64
+ return if outdated_branch == head_branch
65
+ fail "Only aggregate branches are allowed to be reset: #{AGGREGATE_BRANCHES}" unless aggregate_branch?(outdated_branch)
66
+ return if migrations_need_to_be_reverted?
67
+
66
68
  say "Resetting "
67
- say "#{branch} ", :green
69
+ say "#{outdated_branch} ", :green
68
70
  say "branch to "
69
71
  say head_branch, :green
70
72
 
71
73
  run_cmd "git checkout #{Thegarage::Gitx::BASE_BRANCH}"
72
- run_cmd "git branch -D #{branch}", :allow_failure => true
73
- run_cmd "git push origin --delete #{branch}", :allow_failure => true
74
- run_cmd "git checkout -b #{branch} #{head_branch}"
75
- share_branch branch
74
+ run_cmd "git branch -D #{outdated_branch}", :allow_failure => true
75
+ run_cmd "git push origin --delete #{outdated_branch}", :allow_failure => true
76
+ run_cmd "git checkout -b #{outdated_branch} #{head_branch}"
77
+ share_branch outdated_branch
76
78
  run_cmd "git checkout #{Thegarage::Gitx::BASE_BRANCH}"
77
79
  end
78
80
 
@@ -132,9 +134,36 @@ module Thegarage
132
134
  pid = fork { exec "#{editor} #{flags} #{f.path}" }
133
135
  Process.waitpid(pid)
134
136
  description = File.read(f.path)
135
- description.gsub(/^\#.*/, '').chomp.strip
137
+ description.gsub(CLI::PULL_REQUEST_FOOTER, '').chomp.strip
136
138
  end
137
139
  end
138
140
  end
141
+
142
+ def create_build_tag(branch, label)
143
+ timestamp = Time.now.utc.strftime '%Y-%m-%d-%H-%M-%S'
144
+ git_tag = "build-#{branch}-#{timestamp}"
145
+ run_cmd "git tag #{git_tag} -a -m '#{label}'"
146
+ run_cmd "git push origin #{git_tag}"
147
+ end
148
+
149
+ def build_tags_for_branch(branch)
150
+ run_cmd "git fetch --tags"
151
+ build_tags = run_cmd("git tag -l 'build-#{branch}-*'").split
152
+ build_tags.sort
153
+ end
154
+
155
+ def migrations_need_to_be_reverted?
156
+ return false unless File.exists?('db/migrate')
157
+ outdated_migrations = run_cmd("git diff #{head_branch}...#{outdated_branch} --name-only db/migrate").split
158
+ return false if outdated_migrations.empty?
159
+
160
+ say "#{outdated_branch} contains migrations that may need to be reverted. Ensure any reversable migrations are reverted on affected databases before nuking.", :red
161
+ say 'Example commands to revert outdated migrations:'
162
+ outdated_migrations.reverse.each do |migration|
163
+ version = File.basename(migration).split('_').first
164
+ say "rake db:migrate:down VERSION=#{version}"
165
+ end
166
+ !yes?("Are you sure you want to nuke #{outdated_branch}? (y/n) ", :green)
167
+ end
139
168
  end
140
169
  end
@@ -1,5 +1,5 @@
1
1
  module Thegarage
2
2
  module Gitx
3
- VERSION = '1.2.1'
3
+ VERSION = '1.3.0'
4
4
  end
5
5
  end
@@ -16,7 +16,6 @@ describe Thegarage::Gitx::CLI do
16
16
  allow(cli).to receive(:current_branch).and_return('feature-branch')
17
17
  end
18
18
 
19
-
20
19
  describe '#update' do
21
20
  before do
22
21
  expect(cli).to receive(:run).with('git pull origin feature-branch', capture: true).ordered
@@ -277,7 +276,9 @@ describe Thegarage::Gitx::CLI do
277
276
 
278
277
  describe '#reviewrequest' do
279
278
  context 'when github.user is not configured' do
279
+ let(:current_user) { nil }
280
280
  it 'raises error' do
281
+ allow(cli).to receive(:current_user).and_return(current_user)
281
282
  expect(cli).to receive(:run).with("git pull origin feature-branch", capture: true).ordered
282
283
  expect(cli).to receive(:run).with("git pull origin master", capture: true).ordered
283
284
  expect(cli).to receive(:run).with("git push origin HEAD", capture: true).ordered
@@ -311,9 +312,11 @@ describe Thegarage::Gitx::CLI do
311
312
  expect(cli).to receive(:ask).with('Github password for ryan@codecrate.com: ', {:echo => false}).and_return(github_password)
312
313
  expect(cli).to receive(:github_auth_token=).with(authorization_token)
313
314
 
315
+ expect(cli).to receive(:editor_input).and_return('scrubbed text')
314
316
  expect(cli).to receive(:run).with("git pull origin feature-branch", capture: true).ordered
315
317
  expect(cli).to receive(:run).with("git pull origin master", capture: true).ordered
316
318
  expect(cli).to receive(:run).with("git push origin HEAD", capture: true).ordered
319
+ expect(cli).to receive(:run).with("git log master...feature-branch --no-merges --pretty=format:'%ci - %s%n%b'", capture: true).and_return("2013-01-01 did some stuff").ordered
317
320
 
318
321
  cli.reviewrequest
319
322
  end
@@ -336,9 +339,11 @@ describe Thegarage::Gitx::CLI do
336
339
 
337
340
  expect(cli).to receive(:authorization_token).and_return(authorization_token)
338
341
 
342
+ expect(cli).to receive(:editor_input).and_return('scrubbed text')
339
343
  expect(cli).to receive(:run).with("git pull origin feature-branch", capture: true).ordered
340
344
  expect(cli).to receive(:run).with("git pull origin master", capture: true).ordered
341
345
  expect(cli).to receive(:run).with("git push origin HEAD", capture: true).ordered
346
+ expect(cli).to receive(:run).with("git log master...feature-branch --no-merges --pretty=format:'%ci - %s%n%b'", capture: true).and_return("2013-01-01 did some stuff").ordered
342
347
 
343
348
  cli.reviewrequest
344
349
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thegarage-gitx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Sonnek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-23 00:00:00.000000000 Z
11
+ date: 2014-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grit