-
Notifications
You must be signed in to change notification settings - Fork 3
ci: move commit hash retrieval after git commit operation #746
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
Conversation
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
| copier = SafeBuildCopier(repo_root, args.verbose) | ||
| copier.copy_targets(targets) | ||
|
|
||
| # Write metadata for downstream workflows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit hash retrieval logic is duplicated and incorrectly ordered in scripts/release-go.py. The commit hash is captured after git operations but write_metadata_files() is called before this capture, causing metadata to always have None commit hash. Additionally, the git hash retrieval code appears twice in the file (lines 964-968 and 1003-1012) with identical logic.
This issue appears in multiple locations:
- scripts/release-go.py: Lines 964-1020
- scripts/release-go.py: Lines 1003-1012
Please extract the git commit hash retrieval into a shared utility function and ensure write_metadata_files() is called after the commit hash is captured, not before the git operations.
# Write metadata for downstream workflows
modified_apps = copier.get_modified_apps_list(targets)
# Git operations
commit_hash = None
if not args.no_push:
# Stage and commit changes
result = subprocess.run(
["git", "add", "go/"],
cwd=repo_root,
capture_output=True,
text=True
)
if result.returncode != 0:
logger.error(f"Failed to stage changes: {result.stderr}")
return 1
# Check if there are changes to commit
status_result = subprocess.run(
["git", "status", "--porcelain", "go/"],
cwd=repo_root,
capture_output=True,
text=True
)
if status_result.returncode == 0 and status_result.stdout.strip():
logger.info("Changes detected, committing...")
commit_result = subprocess.run(
["git", "commit", "-m", "chore: export app and plugin builds"],
cwd=repo_root,
capture_output=True,
text=True
)
if commit_result.returncode != 0:
logger.error(f"Failed to commit changes: {commit_result.stderr}")
return 1
try:
hash_result = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=repo_root,
capture_output=True,
text=True
)
commit_hash = hash_result.stdout.strip() if hash_result.returncode == 0 else None
except:
commit_hash = None
# Push changes
push_result = subprocess.run(
["git", "push"],
cwd=repo_root,
capture_output=True,
text=True
)
if push_result.returncode != 0:
logger.error(f"Failed to push changes: {push_result.stderr}")
return 1
logger.info("Changes pushed successfully")
else:
logger.info("No changes to commit")
else:
logger.info("Skipping git operations (no-push specified)")
write_metadata_files(modified_apps, commit_hash, args.verbose)Prompt for LLM
File scripts/release-go.py:
Line 964:
I need you to analyze a Python script that handles Git operations and metadata writing. The issue is that the commit hash is only captured after a successful git commit operation, but the write_metadata_files() function is called before this capture happens. This means the metadata file will always have a None commit hash even when a commit was successfully made. Can you identify the exact problem and suggest how to fix the order of operations so that the commit hash is properly captured before writing the metadata files?
Suggested Code:
# Write metadata for downstream workflows
modified_apps = copier.get_modified_apps_list(targets)
# Git operations
commit_hash = None
if not args.no_push:
# Stage and commit changes
result = subprocess.run(
["git", "add", "go/"],
cwd=repo_root,
capture_output=True,
text=True
)
if result.returncode != 0:
logger.error(f"Failed to stage changes: {result.stderr}")
return 1
# Check if there are changes to commit
status_result = subprocess.run(
["git", "status", "--porcelain", "go/"],
cwd=repo_root,
capture_output=True,
text=True
)
if status_result.returncode == 0 and status_result.stdout.strip():
logger.info("Changes detected, committing...")
commit_result = subprocess.run(
["git", "commit", "-m", "chore: export app and plugin builds"],
cwd=repo_root,
capture_output=True,
text=True
)
if commit_result.returncode != 0:
logger.error(f"Failed to commit changes: {commit_result.stderr}")
return 1
try:
hash_result = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=repo_root,
capture_output=True,
text=True
)
commit_hash = hash_result.stdout.strip() if hash_result.returncode == 0 else None
except:
commit_hash = None
# Push changes
push_result = subprocess.run(
["git", "push"],
cwd=repo_root,
capture_output=True,
text=True
)
if push_result.returncode != 0:
logger.error(f"Failed to push changes: {push_result.stderr}")
return 1
logger.info("Changes pushed successfully")
else:
logger.info("No changes to commit")
else:
logger.info("Skipping git operations (no-push specified)")
write_metadata_files(modified_apps, commit_hash, args.verbose)
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
This pull request moves the retrieval of the Git commit hash to occur after the Git commit operation in the release script. Previously, the commit hash was captured before any Git operations were performed. The change ensures that the hash retrieved corresponds to the actual commit that was just created, rather than potentially capturing a different commit state. This modification improves the accuracy of metadata tracking by associating the correct commit hash with the release changes.