Skip to content

Commit

Permalink
PR/MR: Output PR/MR intent only when relevent in noop
Browse files Browse the repository at this point in the history
This commit removes the outputs like "Would submit PR" when there are no
changes after update (in no-op mode).
  • Loading branch information
neomilium committed Apr 23, 2021
1 parent b5cb6ec commit c7aaa21
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
82 changes: 77 additions & 5 deletions features/update/pull_request.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ Feature: Create a pull-request/merge-request after update
puppet-test:
github: {}
"""
And a directory named "moduleroot"
And I set the environment variables to:
| variable | value |
| GITHUB_TOKEN | foobar |
And a file named "config_defaults.yml" with:
"""
---
test:
name: aruba
"""
And a file named "moduleroot/test.erb" with:
"""
<%= @configs['name'] %>
"""
When I run `msync update --noop --branch managed_update --pr`
Then the output should contain "Would submit PR "
And the exit status should be 0
And the puppet module "puppet-test" from "fakenamespace" should have no commits made by "Aruba"

Scenario: Run update in no-op mode and ask for GitLab MR
Given a basic setup with a puppet module "puppet-test" from "fakenamespace"
And a directory named "moduleroot"
And a file named "managed_modules.yml" with:
"""
---
Expand All @@ -29,11 +37,38 @@ Feature: Create a pull-request/merge-request after update
And I set the environment variables to:
| variable | value |
| GITLAB_TOKEN | foobar |
And a file named "config_defaults.yml" with:
"""
---
test:
name: aruba
"""
And a file named "moduleroot/test.erb" with:
"""
<%= @configs['name'] %>
"""
When I run `msync update --noop --branch managed_update --pr`
Then the output should contain "Would submit MR "
And the exit status should be 0
And the puppet module "puppet-test" from "fakenamespace" should have no commits made by "Aruba"

Scenario: Run update without changes in no-op mode and ask for GitLab MR
Given a basic setup with a puppet module "puppet-test" from "fakenamespace"
And a directory named "moduleroot"
And a file named "managed_modules.yml" with:
"""
---
puppet-test:
gitlab: {}
"""
And I set the environment variables to:
| variable | value |
| GITLAB_TOKEN | foobar |
When I run `msync update --noop --branch managed_update --pr`
Then the output should not contain "Would submit MR "
And the exit status should be 0
And the puppet module "puppet-test" from "fakenamespace" should have no commits made by "Aruba"

Scenario: Ask for PR without credentials
Given a basic setup with a puppet module "puppet-test" from "fakenamespace"
And a file named "managed_modules.yml" with:
Expand All @@ -42,7 +77,16 @@ Feature: Create a pull-request/merge-request after update
puppet-test:
gitlab: {}
"""
And a directory named "moduleroot"
And a file named "config_defaults.yml" with:
"""
---
test:
name: aruba
"""
And a file named "moduleroot/test.erb" with:
"""
<%= @configs['name'] %>
"""
When I run `msync update --noop --pr`
Then the stderr should contain "No GitLab token specified to create a merge request"
And the exit status should be 1
Expand All @@ -61,7 +105,16 @@ Feature: Create a pull-request/merge-request after update
gitlab:
token: 'secret'
"""
And a directory named "moduleroot"
And a file named "config_defaults.yml" with:
"""
---
test:
name: aruba
"""
And a file named "moduleroot/test.erb" with:
"""
<%= @configs['name'] %>
"""
When I run `msync update --noop --branch managed_update --pr`
Then the exit status should be 0
And the output should contain "Would submit PR "
Expand All @@ -78,7 +131,16 @@ Feature: Create a pull-request/merge-request after update
gitlab:
token: 'secret'
"""
And a directory named "moduleroot"
And a file named "config_defaults.yml" with:
"""
---
test:
name: aruba
"""
And a file named "moduleroot/test.erb" with:
"""
<%= @configs['name'] %>
"""
When I run `msync update --noop --branch managed_update --pr --pr-target-branch managed_update`
Then the stderr should contain "Unable to open a pull request with the same source and target branch: 'managed_update'"
And the exit status should be 1
Expand All @@ -94,6 +156,16 @@ Feature: Create a pull-request/merge-request after update
github:
token: 'secret'
"""
And a file named "config_defaults.yml" with:
"""
---
test:
name: aruba
"""
And a file named "moduleroot/test.erb" with:
"""
<%= @configs['name'] %>
"""
And a directory named "moduleroot"
When I run `msync update --noop --pr`
Then the stderr should contain "Unable to open a pull request with the same source and target branch: 'custom_default_branch'"
Expand Down
4 changes: 2 additions & 2 deletions lib/modulesync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def self.manage_module(puppet_module, module_files, defaults)

if options[:noop]
puts "Using no-op. Files in '#{puppet_module.given_name}' may be changed but will not be committed."
puppet_module.repository.show_changes(options)
options[:pr] && puppet_module.open_pull_request
changed = puppet_module.repository.show_changes(options)
changed && options[:pr] && puppet_module.open_pull_request
elsif !options[:offline]
pushed = puppet_module.repository.submit_changes(files_to_manage, options)
# Only bump/tag if pushing didn't fail (i.e. there were changes)
Expand Down
2 changes: 2 additions & 0 deletions lib/modulesync/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def show_changes(options)

puts "\n\n"
puts '--------------------------------'

git.diff('HEAD', '--').any? || untracked_unignored_files.any?
end
end
end

0 comments on commit c7aaa21

Please sign in to comment.