singularity_dsl 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzJmODVlN2ZlZjk1OTM0YjFmYTlkNTkxMjQyOThiYWRlOTg3YWJiMw==
4
+ MjMyZGI0MWNkZDRhNWZmODhhYzFmZTljZTVjYWQxNWMwOWZhMGJhMQ==
5
5
  data.tar.gz: !binary |-
6
- ODI2MWRkYzdmMDNhNjNjYWYyY2U4OTQ1ODc2MGMxZGYwNmM4OGRkZQ==
6
+ ZjNhNTQ2MjZlNGEyODllYTMxZDE2NjMyYzZjOTU5MGUxZTRlNzk4ZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjRkNmM0ODBmNTc5MWU3ZGU2ZjhiY2QwMTE0MjcxZmQ0MGUxZDA1Y2E2MWIz
10
- NDRlOGZlMWE3NGQ5NzFlNGIxZjBmZDVjMDIwMGZhNDE0NzNmODU3YmQ0YmMw
11
- N2Q4NGVlN2I0MDJkOWNiMTI1M2Y1MGQ1YzdlMGQ2OTQ2ZDk4YzA=
9
+ NmExNWZkNTI1NzVmOGUzZDUyNjQwMTJlMjExNWU5NjNlYTg3MDA2OGMwOTVl
10
+ MzI5NWRhM2MwNDhhZWFlYTBlNWYwNjYzNDMyY2U0YmUxMjFkOTYzZWNkZDE2
11
+ MzIwMWU0Nzg5NmMzNmUwNDA1MTg1MjZkOTgzNWUwNWM3NTlhNGM=
12
12
  data.tar.gz: !binary |-
13
- OTAxODQyZmY5Yjk4Zjc2ZGNiYTIzMTYxN2Q1YWQ4ZjIwZWE3ZGMzODQzNjg0
14
- YWZmMjY5ZjY0ZmE3NGE5YjU5NjFiZTA5N2I2ZWM1OTRlNTU1ZTc3NWZkYTgw
15
- YjEzMjcwMzkyM2U5N2JmMzM1YjZiNjNmNjI4MDY4M2RlZTc2Zjg=
13
+ NWMxYTJjODc0N2I2MjEwMjVlOTIwMTRhNjM5OGMyYmFhOWVkN2Y1ZThmNmUw
14
+ OWFhNDhlYTYwOWYxMDUyNWIwYzMyYTg5M2FmYjg3MjI2MTcyMDU2NzIwZmYz
15
+ OGYxMjdhODRmNzNkYTdhMmQ5YmNkNDM2OGM0MzhlZjVhZjlmM2E=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- singularity_dsl (2.1.1)
4
+ singularity_dsl (2.2.0)
5
5
  coveralls (~> 0.7.9)
6
6
  json (~> 1.0)
7
7
  mixlib-shellout (~> 2.0)
@@ -26,6 +26,14 @@ module SingularityDsl
26
26
  self
27
27
  end
28
28
 
29
+ def set_fork_env(fork_url, branch)
30
+ git.add_remote(fork_url)
31
+ git.checkout_remote(branch, fork_url)
32
+ setup_git_env(branch)
33
+ git.remove_remote(fork_url)
34
+ self
35
+ end
36
+
29
37
  def perform_merge(fork_url, branch, base_branch, repo_url = nil)
30
38
  git.merge_refs fork_url, branch, base_branch, repo_url
31
39
  git.install_submodules
@@ -46,6 +54,22 @@ module SingularityDsl
46
54
 
47
55
  private
48
56
 
57
+ def git_env_flags
58
+ {
59
+ 'GIT_AUTHOR_NAME' => "--pretty=format:'%aN'",
60
+ 'GIT_AUTHOR_EMAIL' => "--pretty=format:'%ae'",
61
+ 'GIT_COMMITTER_NAME' => "--pretty=format:'%cN'",
62
+ 'GIT_COMMITTER_EMAIL' => "--pretty=format:'%ce'",
63
+ 'GIT_ID' => "--pretty=format:'%H'",
64
+ 'GIT_MESSAGE' => "--pretty=format:'%s'"
65
+ }
66
+ end
67
+
68
+ def setup_git_env(branch)
69
+ git_env_flags.each { |k, f| ENV[k] = git.log("-1 #{f}") }
70
+ ENV['GIT_BRANCH'] = branch
71
+ end
72
+
49
73
  def inject_diff_list(app)
50
74
  return if diff_list.empty?
51
75
  info 'Running with diff-list'
@@ -76,6 +76,7 @@ EOD
76
76
  def testmerge(git_fork, branch, base_branch, base_fork = nil)
77
77
  Command::TestMerge.new(options).tap do |cmd|
78
78
  cmd.bootstrap_cwd(base_fork)
79
+ .set_fork_env(git_fork, branch)
79
80
  .perform_merge(git_fork, branch, base_branch, base_fork)
80
81
  .execute
81
82
  end
@@ -15,6 +15,10 @@ module SingularityDsl
15
15
  @verbose = false
16
16
  end
17
17
 
18
+ def log(flags = '')
19
+ exec("git log #{flags}", true)
20
+ end
21
+
18
22
  def cwd_is_git_repo
19
23
  ::File.exist? "#{::Dir.pwd}/.git"
20
24
  end
@@ -114,14 +118,15 @@ module SingularityDsl
114
118
  exec 'git clean -fdx'
115
119
  end
116
120
 
117
- def exec(cmd)
121
+ def exec(cmd, output = false)
118
122
  task = Mixlib::ShellOut.new cmd
119
123
  if @verbose
120
124
  info cmd
121
125
  task.live_stream = STDOUT
122
126
  end
123
127
  task.run_command
124
- task.exitstatus
128
+ return task.stdout if output
129
+ return task.exitstatus unless output
125
130
  end
126
131
  end
127
132
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version const for gem
4
4
  module SingularityDsl
5
- VERSION = '2.1.1'
5
+ VERSION = '2.2.0'
6
6
  end
@@ -3,10 +3,25 @@
3
3
  require 'singularity_dsl/cli/command/test_merge'
4
4
 
5
5
  describe SingularityDsl::Cli::Command::TestMerge do
6
- def create_command(params)
6
+ def create_command(params = {})
7
7
  SingularityDsl::Cli::Command::TestMerge.new params
8
8
  end
9
9
 
10
+ def cmd_double(expected = false)
11
+ mock = double.as_null_object
12
+ allow(mock).to receive(:exitstatus).and_return 0
13
+ allow(mock).to receive(:stdout).and_return expected if expected
14
+ mock
15
+ end
16
+
17
+ def expect_git_cmd(cmd, expected = false)
18
+ mock = cmd_double(expected)
19
+ expect(::Mixlib::ShellOut)
20
+ .to receive(:new).with(cmd)
21
+ .once
22
+ .and_return(mock)
23
+ end
24
+
10
25
  describe '#batch' do
11
26
  context ':run_task given' do
12
27
  let(:cmd) { create_command(run_task: 'foo') }
@@ -38,15 +53,6 @@ describe SingularityDsl::Cli::Command::TestMerge do
38
53
  end
39
54
 
40
55
  context ':bootstrap_cwd is true' do
41
- def expect_git_cmd(cmd)
42
- cmd_double = double.as_null_object
43
- allow(cmd_double).to receive(:exitstatus).and_return 0
44
- expect(::Mixlib::ShellOut)
45
- .to receive(:new).with(cmd)
46
- .once
47
- .and_return(cmd_double)
48
- end
49
-
50
56
  let(:cmd) { create_command(bootstrap_cwd: true) }
51
57
 
52
58
  context 'and the cwd is an empty directory' do
@@ -77,4 +83,40 @@ describe SingularityDsl::Cli::Command::TestMerge do
77
83
  end
78
84
  end
79
85
  end
86
+
87
+ describe '#set_fork_env' do
88
+ let(:cmd) { create_command }
89
+ let(:repo) { 'fakedood/fakerepo' }
90
+ let(:branch) { 'fakedoodbranch' }
91
+
92
+ it 'sets ENV vars correctly' do
93
+ gitid = 'gitid'
94
+ author = 'fakedood'
95
+ author_email = 'fakedood@usa.lan'
96
+ committer = 'fakedoodbro'
97
+ committer_email = 'fakedoodbro@fakedoodsbutt.lan'
98
+ message = 'bro I commit some things tight tight tight'
99
+
100
+ expect_git_cmd("git remote add fakedood_fakerepo #{repo}")
101
+ expect_git_cmd('git fetch --all')
102
+ expect_git_cmd("git checkout fakedood_fakerepo/#{branch}")
103
+ expect_git_cmd('git remote rm fakedood_fakerepo')
104
+ expect_git_cmd("git log -1 --pretty=format:'%H'", gitid)
105
+ expect_git_cmd("git log -1 --pretty=format:'%aN'", author)
106
+ expect_git_cmd("git log -1 --pretty=format:'%ae'", author_email)
107
+ expect_git_cmd("git log -1 --pretty=format:'%cN'", committer)
108
+ expect_git_cmd("git log -1 --pretty=format:'%ce'", committer_email)
109
+ expect_git_cmd("git log -1 --pretty=format:'%s'", message)
110
+
111
+ expect(ENV).to receive(:[]=).with('GIT_ID', gitid)
112
+ expect(ENV).to receive(:[]=).with('GIT_AUTHOR_NAME', author)
113
+ expect(ENV).to receive(:[]=).with('GIT_AUTHOR_EMAIL', author_email)
114
+ expect(ENV).to receive(:[]=).with('GIT_COMMITTER_NAME', committer)
115
+ expect(ENV).to receive(:[]=).with('GIT_COMMITTER_EMAIL', committer_email)
116
+ expect(ENV).to receive(:[]=).with('GIT_MESSAGE', message)
117
+ expect(ENV).to receive(:[]=).with('GIT_BRANCH', branch)
118
+
119
+ cmd.set_fork_env(repo, branch)
120
+ end
121
+ end
80
122
  end
@@ -10,6 +10,26 @@ describe 'GitHelper' do
10
10
  end
11
11
  let(:git) { SingularityDsl::GitHelper.new }
12
12
 
13
+ context '#log' do
14
+ let(:task) { double.as_null_object }
15
+
16
+ it 'passes flags directly to the command' do
17
+ expect(::Mixlib::ShellOut).to receive(:new)
18
+ .with('git log flags!')
19
+ .and_return task
20
+
21
+ git.log('flags!')
22
+ end
23
+
24
+ it 'returns output of the command' do
25
+ log = 'this is a gitlog yo!'
26
+ allow(task).to receive(:stdout).and_return log
27
+ allow(::Mixlib::ShellOut).to receive(:new).and_return task
28
+
29
+ expect(git.log('flags!')).to eql log
30
+ end
31
+ end
32
+
13
33
  context '#initialize' do
14
34
  it 'sets verbose off' do
15
35
  expect(git.verbose).to eql false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singularity_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - chr0n1x