Skip to content

Commit a3b07f6

Browse files
committed
PR/MR: Output PR/MR intent only when relevent in noop
This commit removes the outputs like "Would submit PR" when there are no changes after update (in no-op mode).
1 parent c0ced82 commit a3b07f6

File tree

3 files changed

+81
-7
lines changed

3 files changed

+81
-7
lines changed

features/update/pull_request.feature

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,26 @@ Feature: Create a pull-request/merge-request after update
88
puppet-test:
99
github: {}
1010
"""
11-
And a directory named "moduleroot"
1211
And I set the environment variables to:
1312
| variable | value |
1413
| GITHUB_TOKEN | foobar |
14+
And a file named "config_defaults.yml" with:
15+
"""
16+
---
17+
test:
18+
name: aruba
19+
"""
20+
And a file named "moduleroot/test.erb" with:
21+
"""
22+
<%= @configs['name'] %>
23+
"""
1524
When I run `msync update --noop --branch managed_update --pr`
1625
Then the output should contain "Would submit PR "
1726
And the exit status should be 0
1827
And the puppet module "puppet-test" from "fakenamespace" should have no commits made by "Aruba"
1928

2029
Scenario: Run update in no-op mode and ask for GitLab MR
2130
Given a basic setup with a puppet module "puppet-test" from "fakenamespace"
22-
And a directory named "moduleroot"
2331
And a file named "managed_modules.yml" with:
2432
"""
2533
---
@@ -29,11 +37,38 @@ Feature: Create a pull-request/merge-request after update
2937
And I set the environment variables to:
3038
| variable | value |
3139
| GITLAB_TOKEN | foobar |
40+
And a file named "config_defaults.yml" with:
41+
"""
42+
---
43+
test:
44+
name: aruba
45+
"""
46+
And a file named "moduleroot/test.erb" with:
47+
"""
48+
<%= @configs['name'] %>
49+
"""
3250
When I run `msync update --noop --branch managed_update --pr`
3351
Then the output should contain "Would submit MR "
3452
And the exit status should be 0
3553
And the puppet module "puppet-test" from "fakenamespace" should have no commits made by "Aruba"
3654

55+
Scenario: Run update without changes in no-op mode and ask for GitLab MR
56+
Given a basic setup with a puppet module "puppet-test" from "fakenamespace"
57+
And a directory named "moduleroot"
58+
And a file named "managed_modules.yml" with:
59+
"""
60+
---
61+
puppet-test:
62+
gitlab: {}
63+
"""
64+
And I set the environment variables to:
65+
| variable | value |
66+
| GITLAB_TOKEN | foobar |
67+
When I run `msync update --noop --branch managed_update --pr`
68+
Then the output should not contain "Would submit MR "
69+
And the exit status should be 0
70+
And the puppet module "puppet-test" from "fakenamespace" should have no commits made by "Aruba"
71+
3772
Scenario: Ask for PR without credentials
3873
Given a basic setup with a puppet module "puppet-test" from "fakenamespace"
3974
And a file named "managed_modules.yml" with:
@@ -42,7 +77,16 @@ Feature: Create a pull-request/merge-request after update
4277
puppet-test:
4378
gitlab: {}
4479
"""
45-
And a directory named "moduleroot"
80+
And a file named "config_defaults.yml" with:
81+
"""
82+
---
83+
test:
84+
name: aruba
85+
"""
86+
And a file named "moduleroot/test.erb" with:
87+
"""
88+
<%= @configs['name'] %>
89+
"""
4690
When I run `msync update --noop --pr`
4791
Then the stderr should contain "No GitLab token specified to create a merge request"
4892
And the exit status should be 1
@@ -61,7 +105,16 @@ Feature: Create a pull-request/merge-request after update
61105
gitlab:
62106
token: 'secret'
63107
"""
64-
And a directory named "moduleroot"
108+
And a file named "config_defaults.yml" with:
109+
"""
110+
---
111+
test:
112+
name: aruba
113+
"""
114+
And a file named "moduleroot/test.erb" with:
115+
"""
116+
<%= @configs['name'] %>
117+
"""
65118
When I run `msync update --noop --branch managed_update --pr`
66119
Then the exit status should be 0
67120
And the output should contain "Would submit PR "
@@ -78,7 +131,16 @@ Feature: Create a pull-request/merge-request after update
78131
gitlab:
79132
token: 'secret'
80133
"""
81-
And a directory named "moduleroot"
134+
And a file named "config_defaults.yml" with:
135+
"""
136+
---
137+
test:
138+
name: aruba
139+
"""
140+
And a file named "moduleroot/test.erb" with:
141+
"""
142+
<%= @configs['name'] %>
143+
"""
82144
When I run `msync update --noop --branch managed_update --pr --pr-target-branch managed_update`
83145
Then the stderr should contain "Unable to open a pull request with the same source and target branch: 'managed_update'"
84146
And the exit status should be 1
@@ -94,6 +156,16 @@ Feature: Create a pull-request/merge-request after update
94156
github:
95157
token: 'secret'
96158
"""
159+
And a file named "config_defaults.yml" with:
160+
"""
161+
---
162+
test:
163+
name: aruba
164+
"""
165+
And a file named "moduleroot/test.erb" with:
166+
"""
167+
<%= @configs['name'] %>
168+
"""
97169
And a directory named "moduleroot"
98170
When I run `msync update --noop --pr`
99171
Then the stderr should contain "Unable to open a pull request with the same source and target branch: 'custom_default_branch'"

lib/modulesync.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def self.manage_module(puppet_module, module_files, defaults)
133133

134134
if options[:noop]
135135
puts "Using no-op. Files in '#{puppet_module.given_name}' may be changed but will not be committed."
136-
puppet_module.repository.show_changes(options)
137-
options[:pr] && puppet_module.open_pull_request
136+
changed = puppet_module.repository.show_changes(options)
137+
changed && options[:pr] && puppet_module.open_pull_request
138138
elsif !options[:offline]
139139
pushed = puppet_module.repository.submit_changes(files_to_manage, options)
140140
# Only bump/tag if pushing didn't fail (i.e. there were changes)

lib/modulesync/repository.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def show_changes(options)
153153

154154
puts "\n\n"
155155
puts '--------------------------------'
156+
157+
git.diff('HEAD', '--').any? || untracked_unignored_files.any?
156158
end
157159
end
158160
end

0 commit comments

Comments
 (0)