Skip to content

Rework regenerate-client.sh for OpenapiGen v7#30

Merged
mshriver merged 2 commits into
mainfrom
openapi-gen-7
Sep 18, 2025
Merged

Rework regenerate-client.sh for OpenapiGen v7#30
mshriver merged 2 commits into
mainfrom
openapi-gen-7

Conversation

@mshriver
Copy link
Copy Markdown
Contributor

@mshriver mshriver commented Sep 18, 2025

major version update, drop the old version file and files list

add logic to pick the new version number

use podman to run openapigen

I'm going to merge this separately from a branch that runs the generator against the Ibutsu 2.7.4 release.

Summary by Sourcery

Rework regenerate-client.sh to containerize client generation with OpenAPI Generator v7, automate version detection and bumping, clean up old artifacts, streamline file handling, and enhance the commit and push workflow

New Features:

  • Generate the API client inside a Podman container using OpenAPI Generator v7
  • Automatically detect the current project version from pyproject.toml or hatch and bump the patch version

Bug Fixes:

  • Fix flag handling for branch deletion and provide a fallback for unexpected version formats

Enhancements:

  • Clean up the .openapi-generator folder on major generator version changes
  • Preserve important directories when replacing generated content and remove unwanted files
  • Run post-generation formatting and linting with hatch pre-commit if available
  • Improve branch creation, commit messages, push, and delete workflows

Build:

  • Enforce strict bash settings and add dependency checks for Podman and hatch

Documentation:

  • Update script usage output to list Podman and hatch as requirements

Chores:

  • Remove legacy .openapi-generator/FILES and .openapi-generator/VERSION files

major version update, drop the old version file and files list

add logic to pick the new version number

use podman to run openapigen
Copilot AI review requested due to automatic review settings September 18, 2025 08:47
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Sep 18, 2025

Reviewer's Guide

This PR rewrites the client regeneration script to use OpenAPI Generator v7 via Podman with improved version handling, cleanup logic, structured temporary directories, enhanced post-processing, and robust Git operations.

Sequence diagram for client generation using Podman and OpenAPI Generator v7

sequenceDiagram
    participant Script
    participant Podman
    participant OpenAPI_Generator
    Script->>Podman: Run OpenAPI Generator v7 container
    Podman->>OpenAPI_Generator: Execute code generation with provided OpenAPI spec
    OpenAPI_Generator-->>Podman: Output generated client files
    Podman-->>Script: Return generated files to temp directory
    Script->>Script: Process and copy files, clean up temp
    Script->>Script: Run post-processing (format/lint)
    Script->>Git: Commit, push, and delete branch as requested
Loading

Class diagram for new version extraction and cleanup logic in regenerate-client.sh

classDiagram
    class regenerate-client.sh {
        +get_versions()
        +cleanup_openapi_generator_folder()
        +check_dependencies()
        +print_usage()
        +main logic
    }
    regenerate-client.sh : get_versions() extracts CURRENT_VERSION and NEW_VERSION
    regenerate-client.sh : cleanup_openapi_generator_folder() cleans .openapi-generator on major upgrade
    regenerate-client.sh : check_dependencies() ensures Podman and hatch
    regenerate-client.sh : print_usage() prints usage info
    regenerate-client.sh : main logic orchestrates flow
Loading

Flow diagram for the new client regeneration process in regenerate-client.sh

flowchart TD
    A["Start regenerate-client.sh"] --> B["Parse arguments and options"]
    B --> C["Extract current and new version numbers"]
    C --> D["Check dependencies (Podman, hatch)"]
    D --> E["Clean up .openapi-generator folder if major version upgrade"]
    E --> F["Run OpenAPI Generator v7 in Podman container"]
    F --> G["Process generated files (remove unwanted, add .gitignore)"]
    G --> H["Copy generated files to client directory"]
    H --> I["Clean up temporary directory"]
    I --> J["Run post-processing (formatting/linting with hatch)"]
    J --> K["Commit changes to new branch if requested"]
    K --> L["Push branch and optionally delete local branch"]
    L --> M["Done"]
Loading

File-Level Changes

Change Details Files
Implement strict scripting and dependency checks
  • Enable set -euo pipefail at script top
  • Add check_dependencies function for Podman and hatch
  • Extend print_usage to list requirements
  • Refine flag parsing (fixed delete flag bug)
regenerate-client.sh
Refactor version detection and bump logic
  • Introduce get_versions() using hatch or tomllib to read pyproject.toml
  • Support semantic and fallback version formats
  • Compute and export NEW_VERSION when not provided
  • Update --version flag to display both CURRENT_VERSION and NEW_VERSION
regenerate-client.sh
Clean .openapi-generator folder on major upgrades
  • Add cleanup_openapi_generator_folder() to compare old vs new major version
  • Remove .openapi-generator when major version differs
  • Echo status messages for cleanup actions
regenerate-client.sh
.openapi-generator/FILES
.openapi-generator/VERSION
Switch generation to Podman-based container
  • Replace local openapi-generator-cli invocation with podman run
  • Mount CLIENT_DIR into container and generate into tmp/client
  • Parameterize image version via OPENAPI_GENERATOR_VERSION
regenerate-client.sh
Streamline file post-processing and copying
  • Create TEMP_DIR under CLIENT_DIR/tmp
  • Remove unwanted generated files (.travis.yml, git_push.sh)
  • Append custom entries to .gitignore
  • Selective find/rm to preserve .git, .github, LICENSE, regenerate-client.sh
  • Copy new generated content from tmp and clean up
regenerate-client.sh
Enhance post-generation formatting and Git workflow
  • Run hatch pre-commit hooks if available
  • Build and switch to branch regenerate-$NEW_VERSION for commits
  • Craft detailed commit message including generator and version info
  • Push and optionally delete branch logic with feedback
regenerate-client.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR reworks the client regeneration script to use OpenAPI Generator v7.15.0, replacing the previous version-based approach with a more robust Podman-based solution.

  • Replaces local OpenAPI Generator CLI with Podman container execution for consistency
  • Implements intelligent version detection using hatch or pyproject.toml fallback
  • Adds logic to clean up OpenAPI Generator metadata on major version upgrades

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
regenerate-client.sh Complete rewrite to use Podman, improved version handling, and better error handling
.openapi-generator/VERSION Removed old version file as part of cleanup for v7 upgrade
.openapi-generator/FILES Removed old files list as part of cleanup for v7 upgrade

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread regenerate-client.sh
Comment thread regenerate-client.sh Outdated
Comment thread regenerate-client.sh
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Consider adding support for a Docker fallback (e.g. via an environment variable) in case Podman isn’t available to make the script more portable.
  • Instead of hard-coding NEW_VERSION to "2.3.1" on parse failures, it may be safer to error out or derive a next patch version dynamically to avoid accidental version regressions.
  • The multi-line git commit message passed with a single -m flag can break on some shells—use multiple -m flags or explicit newline escaping to ensure the full message is captured.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding support for a Docker fallback (e.g. via an environment variable) in case Podman isn’t available to make the script more portable.
- Instead of hard-coding NEW_VERSION to "2.3.1" on parse failures, it may be safer to error out or derive a next patch version dynamically to avoid accidental version regressions.
- The multi-line git commit message passed with a single -m flag can break on some shells—use multiple -m flags or explicit newline escaping to ensure the full message is captured.

## Individual Comments

### Comment 1
<location> `regenerate-client.sh:170` </location>
<code_context>
+    -p packageVersion="${NEW_VERSION}" \
     -p packageUrl=https://github.com/ibutsu/ibutsu-client-python \
-    -i $OPENAPI_FILE > $CLIENT_DIR/generate.log 2>&1
+    -p pythonVersion=3.8 \
+    -p generateSourceCodeOnly=false \
+    -p library=urllib3 \
</code_context>

<issue_to_address>
**suggestion:** Hardcoded Python version may not match project requirements.

The generator currently uses Python 3.8. Please update this to reflect the project's required Python version, or make it configurable to avoid compatibility issues.

Suggested implementation:

```
    -p pythonVersion="${PYTHON_VERSION:-3.11}" \

```

To make the Python version configurable, you should document that users can set the `PYTHON_VERSION` environment variable before running the script, e.g.:
```bash
export PYTHON_VERSION=3.10
./regenerate-client.sh
```
If `PYTHON_VERSION` is not set, the script will default to 3.11 (or update this default to match your project's required version).
</issue_to_address>

### Comment 2
<location> `regenerate-client.sh:198` </location>
<code_context>
+# Copy generated files while preserving important directories
+echo "Copying generated files..."
+# Remove old generated content but preserve important directories and files
+find "${CLIENT_DIR}" -mindepth 1 -maxdepth 1 \
+    ! -name '.git' \
+    ! -name '.github' \
</code_context>

<issue_to_address>
**issue (bug_risk):** Aggressive file removal may delete user files unintentionally.

Since only a few names are excluded, any new important files or directories added by users may be deleted. To prevent accidental data loss, consider using a configurable whitelist or adding a confirmation step before deletion.
</issue_to_address>

### Comment 3
<location> `regenerate-client.sh:229-232` </location>
<code_context>
-    git checkout -b $BRANCH_NAME > /dev/null 2>&1
+
+    # Create and switch to new branch
+    git checkout -b "$BRANCH_NAME" > /dev/null 2>&1
     git add . > /dev/null 2>&1
-    git commit -q -m "Regenerated client"
</code_context>

<issue_to_address>
**suggestion:** Branch creation does not check for existing branch.

Handle the case where the branch already exists to prevent command failure and script errors.

```suggestion
    # Create and switch to new branch, or switch if it already exists
    if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then
        echo "Branch $BRANCH_NAME already exists. Switching to it..."
        git checkout "$BRANCH_NAME" > /dev/null 2>&1
    else
        git checkout -b "$BRANCH_NAME" > /dev/null 2>&1
    fi
    git add . > /dev/null 2>&1
    git commit -q -m "Regenerate client with OpenAPI Generator v${OPENAPI_GENERATOR_VERSION}
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread regenerate-client.sh
Comment thread regenerate-client.sh
Comment thread regenerate-client.sh Outdated
@mshriver mshriver added the enhancement New feature or request label Sep 18, 2025
@mshriver mshriver merged commit 8d5b0bb into main Sep 18, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants