8000 add the commit_changes role by fredericlepied · Pull Request #686 · redhatci/ansible-collection-redhatci-ocp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add the commit_changes role #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

add the commit_changes role #686

wants to merge 1 commit into from

Conversation

fredericlepied
Copy link
Contributor
SUMMARY
ISSUE TYPE
  • New role
Tests

Test-Hint: no-check
Depends-on: #676

@fredericlepied fredericlepied requested review from a team as code owners May 22, 2025 13:43
@dcibot
Copy link
Collaborator
dcibot commented May 22, 2025

from change #686:

  • no check (not a code change)

1 similar comment
@dcibot
Copy link
Collaborator
dcibot commented May 22, 2025

from change #686:

  • no check (not a code change)

Copy link
Contributor
coderabbitai bot commented May 22, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This change introduces a new Ansible role, commit_changes, designed to automate staging and committing file changes within a specified directory in a git repository. Documentation, default variables, tasks, and a comprehensive integration test suite—including configuration, inventory, playbooks, and scripts—have been added to support and verify the new role.

Changes

Files/Paths Change Summary
README.md Added a new entry for the redhatci.ocp.commit_changes role, describing its purpose and functionality.
roles/commit_changes/README.md New documentation file detailing the commit_changes role, its variables, usage, and license.
roles/commit_changes/defaults/main.yml Introduced default variables for optional git author name and email overrides.
roles/commit_changes/tasks/main.yml Added tasks for asserting required variables, configuring git author info, staging, and committing changes in a git repository.
tests/integration/integration_config.yml New integration test configuration file specifying directory, commit message, and author details for tests.
tests/integration/inventory Added test inventory defining a local test host and connection parameters for integration testing.
tests/integration/targets/commit_changes/commit_changes.yml New integration test playbook that imports a task file to execute the role under test.
tests/integration/targets/commit_changes/runme.sh New shell script to execute the integration test playbook with specified inventory and variables.
tests/integration/targets/commit_changes/tasks/main.yml New playbook that sets up a git repo, applies the role, and verifies results as part of integration testing.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging github.com/redhatci/ansible-collection-redhatci-ocp for 686,030e2ad5a4572b816added62b831aeff82d6aa19

@fredericlepied fredericlepied marked this pull request as draft May 22, 2025 13:44
Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🔭 Outside diff range comments (1)
roles/commit_changes/tasks/main.yml (1)

30-37: 🛠️ Refactor suggestion

Avoid shell‐splitting issues by using list/argv form.
Passing the commit message as a single argument prevents injection and ensures messages with spaces work:

- name: Commit changes
  ansible.builtin.command:
    argv:
      - git
      - commit
      - -m
      - "{{ commit_message }}"
  args:
    chdir: "{{ commit_directory }}"
  register: commit_result
  failed_when: commit_result.rc > 1
  changed_when: commit_result.rc == 0
🧹 Nitpick comments (7)
tests/integration/inventory (1)

2-2: Avoid hardcoding local paths in inventory
The ansible_python_interpreter is pointed at a user-specific venv path. For portability, consider using a generic interpreter (e.g. /usr/bin/env python3) or parameterizing via an environment variable or inventory var.

roles/commit_changes/defaults/main.yml (1)

1-4: Add newline at end of file
YAML lint flagged a missing newline at EOF. Please ensure there’s a trailing newline to comply with common YAML style guidelines.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 4-4: no new line character at the end of file

(new-line-at-end-of-file)

tests/integration/integration_config.yml (1)

1-7: Ensure trailing newline for YAML file
Add a newline at the end of this file to satisfy YAML style checks and avoid “no new line at end of file” warnings.

tests/integration/targets/commit_changes/commit_changes.yml (1)

1-7: Optimize playbook for speed
Since this integration test doesn’t need facts, you could add gather_facts: no under the play to reduce runtime.

roles/commit_changes/README.md (1)

1-3: Unify Markdown heading style.
Currently the top-level header uses Setext while the others use ATX, which triggers MD003. For consistency, convert to ATX:

- commit_changes
- ===============
+ # commit_changes
roles/commit_changes/tasks/main.yml (1)

1-7: Add a check that the directory is a Git repo.
Right now we only assert the variables exist. It’s safer to verify that commit_directory/.git actually exists before proceeding:

- name: Check for Git repository
  ansible.builtin.stat:
    path: "{{ commit_directory }}/.git"
  register: git_dir

- name: Fail if not a Git repository
  ansible.builtin.assert:
    that:
      - git_dir.exists
    fail_msg: "Directory {{ commit_directory }} is not a Git repository"
tests/integration/targets/commit_changes/tasks/main.yml (1)

3-7: Ensure directory removal is recursive if needed.
To guarantee cleanup of non-empty dirs, add recurse: yes:

- name: Cleanup target directory
  ansible.builtin.file:
    path: "{{ commit_directory }}"
    state: absent
    recurse: yes
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b938589 and 030e2ad.

📒 Files selected for processing (9)
  • README.md (1 hunks)
  • roles/commit_changes/README.md (1 hunks)
  • roles/commit_changes/defaults/main.yml (1 hunks)
  • roles/commit_changes/tasks/main.yml (1 hunks)
  • tests/integration/integration_config.yml (1 hunks)
  • tests/integration/inventory (1 hunks)
  • tests/integration/targets/commit_changes/commit_changes.yml (1 hunks)
  • tests/integration/targets/commit_changes/runme.sh (1 hunks)
  • tests/integration/targets/commit_changes/tasks/main.yml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
roles/commit_changes/defaults/main.yml

[error] 4-4: no new line character at the end of file

(new-line-at-end-of-file)

🪛 markdownlint-cli2 (0.17.2)
roles/commit_changes/README.md

6-6: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


15-15: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


19-19: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

🔇 Additional comments (5)
README.md (1)

50-50: Role entry added correctly
The commit_changes role is listed in the Roles table with an accurate link and description. Positioning and formatting match existing entries.

roles/commit_changes/README.md (3)

6-14: Variables section is clear and accurate.
The table correctly documents required and optional inputs.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

6-6: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


15-18: Dependencies section is correct.
No external requirements—documentation matches implementation.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

15-15: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


19-21: License section is appropriate.
GNU GPLv3 is properly declared.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

19-19: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

roles/commit_changes/tasks/main.yml (1)

25-29: Staging changes looks good.
Using git add --all . with chdir correctly stages all file states.

Comment on lines 3 to 6
dir=$(dirname "$0")

exec ansible-playbook -i $dir/../../inventory -e @$dir/../../integration_config.yml commit_changes.yml

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure playbook path and variables are quoted and correctly referenced.
The script determines its own directory but then runs commit_changes.yml relative to the current working directory, which may cause “file not found” errors if you invoke the script from elsewhere. Also, the inventory and vars paths should be quoted to handle spaces.
Apply this diff:

- dir=$(dirname "$0")
- 
- exec ansible-playbook -i $dir/../../inventory -e @$dir/../../integration_config.yml commit_changes.yml
+ dir="$(dirname "$0")"
+
+ # run from the role’s test directory
+ cd "$dir"
+
+ exec ansible-playbook \
+   "$dir/commit_changes.yml" \
+   -i "$dir/../../inventory" \
+   -e "@$dir/../../integration_config.yml"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dir=$(dirname "$0")
exec ansible-playbook -i $dir/../../inventory -e @$dir/../../integration_config.yml commit_changes.yml
dir="$(dirname "$0")"
# run from the role’s test directory
cd "$dir"
exec ansible-playbook \
"$dir/commit_changes.yml" \
-i "$dir/../../inventory" \
-e "@$dir/../../integration_config.yml"
🤖 Prompt for AI Agents
In tests/integration/targets/commit_changes/runme.sh around lines 3 to 6, the
ansible-playbook command uses unquoted paths and references the playbook
relative to the current directory instead of the script directory. To fix this,
quote all path variables to handle spaces and reference commit_changes.yml using
the script directory variable to ensure the correct file is found regardless of
the current working directory.

Comment on lines 9 to 15
- name: Set git author name
ansible.builtin.command: git config user.name "{{ commit_author_name }}"
args:
chdir: "{{ commit_directory }}"
when:
- commit_author_name is defined
- commit_author_name | length > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use the idempotent git_config module for author settings.
Replacing raw git config commands with ansible.builtin.git_config improves idempotency and readability:

- name: Set git author name
  ansible.builtin.git_config:
    name: user.name
    value: "{{ commit_author_name }}"
    scope: local
    repo: "{{ commit_directory }}"
  when:
    - commit_author_name is defined
    - commit_author_name | length > 0

- name: Set git author email
  ansible.builtin.git_config:
    name: user.email
    value: "{{ commit_author_email }}"
    scope: local
    repo: "{{ commit_directory }}"
  when:
    - commit_author_email is defined
    - commit_author_email | length > 0

Also applies to: 17-23

🤖 Prompt for AI Agents
In roles/commit_changes/tasks/main.yml lines 9 to 15 and also lines 17 to 23,
replace the ansible.builtin.command tasks that run raw git config commands with
the ansible.builtin.git_config module. Use the git_config module's parameters:
name for the config key (user.name or user.email), value for the corresponding
variable, scope set to local, and repo set to commit_directory. Keep the
existing when conditions to check if the variables are defined and non-empty.
This change ensures idempotency and improves readability.

Comment on lines 52 to 67
8000
- name: Verify that commit was made
ansible.builtin.assert:
that:
- commit_result.changed

- name: Verify commit message is correct
ansible.builtin.command: git log -1 --pretty=%B
args:
chdir: "{{ commit_directory }}"
register: git_log

- name: Assert git log message matches commit_message
ansible.builtin.assert:
that:
- git_log.stdout.strip() == commit_message

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Expand tests to cover author overrides.
We verify that a commit is made and the message matches, but we don’t assert commit_author_name/email behavior. Consider adding:

- name: Get latest commit author name
  ansible.builtin.command:
    argv:
      - git
      - log
      - -1
      - --pretty=%an
  args:
    chdir: "{{ commit_directory }}"
  register: git_author

- name: Assert commit author name
  ansible.builtin.assert:
    that:
      - git_author.stdout.strip() == commit_author_name
  when: commit_author_name is defined

Place these after the message assertion to fully cover optional author overrides.

🤖 Prompt for AI Agents
In tests/integration/targets/commit_changes/tasks/main.yml around lines 52 to
67, the current tests verify commit creation and message correctness but do not
check commit author name or email overrides. Add tasks after the commit message
assertion to run a git command retrieving the latest commit author name,
register its output, and assert that it matches the expected commit_author_name
variable. Include a conditional to run this assertion only if commit_author_name
is defined, ensuring coverage of optional author overrides.

@dcibot
Copy link
Collaborator
dcibot commented May 22, 2025

from change #686:

  • no check (not a code change)

1 similar comment
@dcibot
Copy link
Collaborator
dcibot commented May 22, 2025

from change #686:

  • no check (not a code change)

Copy link

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging github.com/redhatci/ansible-collection-redhatci-ocp for 686,f4c030e0d882f5f1536221488b5bb477c8481696

@dcibot
Copy link
Collaborator
dcibot commented May 22, 2025

from change #686:

  • no check (not a code change)

1 similar comment
@dcibot
Copy link
Collaborator
dcibot commented May 22, 2025

from change #686:

  • no check (not a code change)

Copy link

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging github.com/redhatci/ansible-collection-redhatci-ocp for 686,b429acfaa2dd5f047a0ba13af03eee2c711326b4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0