Merge branch 'master' of ssh://git.giugl.io/peperunas/nixos

This commit is contained in:
Giulio De Pasquale 2024-12-06 17:34:41 +00:00
commit 586529e23d
2 changed files with 55 additions and 36 deletions

View File

@ -29,6 +29,7 @@ Process:
4. Expand on the most promising thought(s) by generating sub-thoughts. 4. Expand on the most promising thought(s) by generating sub-thoughts.
5. Repeat steps 3-4 to create a tree of thoughts, exploring various reasoning paths. 5. Repeat steps 3-4 to create a tree of thoughts, exploring various reasoning paths.
6. Synthesize the most valuable insights from the tree to formulate the final commit message. 6. Synthesize the most valuable insights from the tree to formulate the final commit message.
7. DO NOT mention "useless" details such as added imports.
For each thought and sub-thought, consider: For each thought and sub-thought, consider:
- The type of change (e.g., feature, bug fix, refactor, style, docs, etc.) - The type of change (e.g., feature, bug fix, refactor, style, docs, etc.)

View File

@ -1,13 +1,31 @@
create_pr_from_files() { create_pr_from_files() {
local origin_branch="development" local TIMESTAMP=$(date +%Y%m%d%H%M%S)
local temp_branch="pr-${TIMESTAMP}-temp"
local pr_branch="pr-${TIMESTAMP}"
local base_branch="development"
local current_branch=$(git rev-parse --abbrev-ref HEAD) local current_branch=$(git rev-parse --abbrev-ref HEAD)
local files=() local files=()
cleanup() {
git checkout "${current_branch}"
git checkout "${temp_branch}" -- "${all_files[@]}"
git restore --staged .
git branch -D "${temp_branch}"
git branch -D "${pr_branch}"
}
handle_error() {
local error_msg="$1"
echo "Error: ${error_msg}"
cleanup
return 1
}
# Parse arguments # Parse arguments
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
-b | --base) -b | --base)
origin_branch="$2" base_branch="$2"
shift 2 shift 2
;; ;;
*) *)
@ -22,54 +40,54 @@ create_pr_from_files() {
return 1 return 1
fi fi
# Checkout to the new branch and add the specified files # Backup all modified files
local commit_message="" local all_files=()
local new_branch="pr-$(date +%Y%m%d%H%M%S)" while IFS= read -r line; do
all_files+=("$line")
done < <(git status -s | cut -d " " -f 3)
git checkout -b "$new_branch" echo Our: "${files[@]}"
git add "${files[@]}" echo All: "${all_files[@]}"
# Generate commit message using aichat git checkout -b "$temp_branch" || handle_error "Failed to create temporary branch"
git commit -am "Backup changes" || handle_error "Failed to commit changes to temporary branch"
# Switch to base branch and create temporary branch
if [ "$current_branch" != "$base_branch" ]; then
git checkout "$base_branch" || handle_error "Failed to checkout base branch"
git pull || handle_error "Failed to sync base branch"
fi
git checkout -b "$pr_branch" || handle_error "Failed to create PR branch"
# Restore specified files from temporary branch
git checkout "$temp_branch" -- "${files[@]}" || handle_error "Failed to restore specified files"
git add "${files[@]}" || handle_error "Failed to stage specified files"
# # Generate commit message
echo "Generating commit message..." echo "Generating commit message..."
commit_message=$(git diff --staged | aichat -m ollama:pino-coder -r commitmessage) local commit_message=$(git diff --staged | aichat -m ollama:pino-coder -r commitmessage || handle_error "Failed to generate commit message.")
if [ -z "$commit_message" ]; then
echo "Failed to generate commit message. Cleaning up."
git checkout -
git branch -D "$new_branch"
if $has_changes; then
echo "Restoring stashed changes..."
git stash pop
fi
git checkout "${current_branch}"
return 1
fi
# Extract title and body from the generated commit message
local commit_subject=$(echo "$commit_message" | head -n 1) local commit_subject=$(echo "$commit_message" | head -n 1)
local commit_body=$(echo "$commit_message" | tail -n +2) local commit_body=$(echo "$commit_message" | tail -n +2)
if ! git commit -m "$commit_subject"$'\n\n'"$commit_body"; then # # # Commit the specified files
echo "Committing changes failed. Cleaning up." git commit --edit -m "$commit_subject"$'\n\n'"$commit_body" || handle_error "Committing files failed."
git checkout - if [ $? -ne 0 ]; then
git branch -D "$new_branch" handle_error "Committing files failed."
if $has_changes; then
echo "Restoring stashed changes..."
git stash pop
fi fi
git checkout "${current_branch}" # Push the PR branch to the remote repository
git push origin "$pr_branch" || handle_error "Failed to push PR branch"
return 1 # Create the pull request
fi gh pr create \
--base "$base_branch" \
git push origin "$new_branch" --head "$pr_branch" || handle_error "Failed to create pull request"
gh pr create --base "$origin_branch" --head "$new_branch" --title "$commit_subject" --body "$commit_body"
echo "Pull request created successfully." echo "Pull request created successfully."
git checkout "${current_branch}" # Cleanup
cleanup
} }
create_pr_from_commit() { create_pr_from_commit() {