Rework regenerate-client.sh for OpenapiGen v7#30
Conversation
major version update, drop the old version file and files list add logic to pick the new version number use podman to run openapigen
Reviewer's GuideThis 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 v7sequenceDiagram
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
Class diagram for new version extraction and cleanup logic in regenerate-client.shclassDiagram
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
Flow diagram for the new client regeneration process in regenerate-client.shflowchart 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"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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:
Bug Fixes:
Enhancements:
Build:
Documentation:
Chores: