Skip to content

Fixes #38547 - Add job template clone command to expose clone API endpoint#55

Merged
stejskalleos merged 2 commits into
theforeman:masterfrom
Gauravtalreja1:expose-jobtemplate-clone
Jan 21, 2026
Merged

Fixes #38547 - Add job template clone command to expose clone API endpoint#55
stejskalleos merged 2 commits into
theforeman:masterfrom
Gauravtalreja1:expose-jobtemplate-clone

Conversation

@Gauravtalreja1

Copy link
Copy Markdown
Contributor

Description:

Exposeing the POST /api/job_templates/:id/clone API endpoint that was previously unavailable in the Hammer CLI

Test Results:

[root@foreman ~]# hammer job-template list | grep -i "ansible role"
233 | Ansible Roles - Ansible Default                            | Ansible Playbook           | Ansible  | job_template
234 | Ansible Roles - Install from Galaxy                        | Ansible Galaxy             | Ansible  | job_template
235 | Ansible Roles - Install from git                           | Ansible Roles Installation | Ansible  | job_template
[root@foreman ~]# hammer job-template clone --id 233 --name "Clone Ansible Roles - Ansible Default"
Job template cloned
[root@foreman ~]# hammer job-template list | grep -i "clone"
262 | Clone Ansible Roles - Ansible Default                      | Ansible Playbook           | Ansible  | job_template
[root@foreman ~]#  hammer job-template info --id 262
ID:                         262
Name:                       Clone Ansible Roles - Ansible Default
Job Category:               Ansible Playbook
Provider:                   Ansible
Type:                       job_template
Ansible Callback Enabled:   no
Ansible Check Mode Enabled: no
Description:

Inputs:

Locations:
    Default Location
    test_loc
Organizations:
    Default Organization
    test_org

@Gauravtalreja1 Gauravtalreja1 force-pushed the expose-jobtemplate-clone branch from 4b846e4 to a3c7794 Compare July 13, 2025 14:18

@adamruzicka adamruzicka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have the same interface as hammer template clone - --name (and --id) should identify the source template (the one being cloned), --new-name should be the name for the clone

@nacoool

nacoool commented Jul 17, 2025

Copy link
Copy Markdown

Tested the changes and everything works as expected

@ofedoren

Copy link
Copy Markdown
Member

Here is the command Adam was referring to https://github.com/theforeman/hammer-cli-foreman/blob/master/lib/hammer_cli_foreman/template.rb#L190-L218

@stejskalleos stejskalleos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment to address.
Redmine Check CI is failing, but looking at the git log, nobody bothers anymore about it :D

Comment thread test/unit/job_template_test.rb Outdated
let(:cmd) { HammerCLIForemanRemoteExecution::JobTemplate::CloneCommand.new('', ctx) }

describe 'parameters' do
it_should_accept 'id and name', ['--id=1', '--name=Cloned Template']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The be bin/hammer template clone --new-name "clone_wars" --id 150 command uses --new-name param, we should do the same here, as mentioned by other reviewers.

@Gauravtalreja1

Copy link
Copy Markdown
Contributor Author

@adamruzicka @stejskalleos Updated, Thank you! Could you please take another look at this PR?

@nacoool

nacoool commented Jan 19, 2026

Copy link
Copy Markdown

Tested using packit, Works as expected.

@stejskalleos stejskalleos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gauravtalreja1 Rubocop CI is failing, please fix it so we can merge it.

…point

Exposes the POST /api/job_templates/:id/clone API endpoint
that was previously unavailable in the Hammer CLI.

Signed-off-by: Gaurav Talreja <gtalreja@redhat.com>
Signed-off-by: Gaurav Talreja <gtalreja@redhat.com>

@stejskalleos stejskalleos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍏 LGTM

hammer job-template clone --new-name "clone_wars" --id 150
Job template cloned

@stejskalleos stejskalleos merged commit 9c63757 into theforeman:master Jan 21, 2026
10 of 11 checks passed
@Gauravtalreja1 Gauravtalreja1 deleted the expose-jobtemplate-clone branch January 21, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants