Skip to content

Commit

Permalink
don't fork when the destination project already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Dec 20, 2023
1 parent 4227ea1 commit b289b41
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion obal/data/modules/copr_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.copr import copr_cli, CoprCliCommandError, full_name # pylint:disable=import-error,no-name-in-module
from ansible.module_utils.copr import copr_cli, CoprCliCommandError, full_name, project_exists # pylint:disable=import-error,no-name-in-module


def main():
Expand All @@ -29,6 +29,9 @@ def main():
delete_after_days = module.params['delete_after_days']
config_file = module.params['config_file']

if project_exists(dest_user, dest_project, module, config_file=config_file):
module.exit_json(changed=False)

command = [
'fork',
full_name(src_user, src_project),
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/mockbin/mockbin
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,9 @@ elif prog in ['copr-cli']:
print("Build was added to foreman-1234:")
print("https://copr.fedorainfracloud.org/coprs/build/5678")
print("Created builds: 5678")
elif args.subcommand == 'list':
if args.project == 'existing-fork':
print("Name: foreman-client")
print(" Description: foreman-client")
else:
print({})
14 changes: 14 additions & 0 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,9 +857,23 @@ def test_copr_project_fork():
assert_obal_success(['copr-project', 'client', '-e copr_project_fork_from=client-test'])

expected_log = [
"copr-cli list example",
"copr-cli fork example/client-test example/foreman-client",
"copr-cli edit-chroot example/foreman-client/rhel-9-x86_64",
"copr-cli edit-chroot example/foreman-client/rhel-8-x86_64",
"copr-cli edit-chroot example/foreman-client/rhel-7-x86_64",
]
assert_mockbin_log(expected_log)


@obal_cli_test(repotype='copr')
def test_copr_project_fork_already_exists():
assert_obal_success(['copr-project', 'client', '-e copr_project_fork_from=client-test', '-e copr_project_user=existing-fork'])

expected_log = [
"copr-cli list existing-fork",
"copr-cli edit-chroot existing-fork/foreman-client/rhel-9-x86_64",
"copr-cli edit-chroot existing-fork/foreman-client/rhel-8-x86_64",
"copr-cli edit-chroot existing-fork/foreman-client/rhel-7-x86_64",
]
assert_mockbin_log(expected_log)

0 comments on commit b289b41

Please sign in to comment.