Merge branch 'master' of ssh://git.giugl.io/peperunas/nixos
This commit is contained in:
commit
586529e23d
@ -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.)
|
||||||
|
@ -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"
|
||||||
echo "Generating commit message..."
|
git commit -am "Backup changes" || handle_error "Failed to commit changes to temporary branch"
|
||||||
commit_message=$(git diff --staged | aichat -m ollama:pino-coder -r commitmessage)
|
|
||||||
|
|
||||||
if [ -z "$commit_message" ]; then
|
# Switch to base branch and create temporary branch
|
||||||
echo "Failed to generate commit message. Cleaning up."
|
if [ "$current_branch" != "$base_branch" ]; then
|
||||||
git checkout -
|
git checkout "$base_branch" || handle_error "Failed to checkout base branch"
|
||||||
git branch -D "$new_branch"
|
git pull || handle_error "Failed to sync base branch"
|
||||||
if $has_changes; then
|
|
||||||
echo "Restoring stashed changes..."
|
|
||||||
git stash pop
|
|
||||||
fi
|
|
||||||
git checkout "${current_branch}"
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Extract title and body from the generated commit message
|
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..."
|
||||||
|
local commit_message=$(git diff --staged | aichat -m ollama:pino-coder -r commitmessage || handle_error "Failed to generate 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
|
|
||||||
|
|
||||||
git checkout "${current_branch}"
|
|
||||||
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git push origin "$new_branch"
|
# Push the PR branch to the remote repository
|
||||||
|
git push origin "$pr_branch" || handle_error "Failed to push PR branch"
|
||||||
|
|
||||||
gh pr create --base "$origin_branch" --head "$new_branch" --title "$commit_subject" --body "$commit_body"
|
# Create the pull request
|
||||||
|
gh pr create \
|
||||||
|
--base "$base_branch" \
|
||||||
|
--head "$pr_branch" || handle_error "Failed to create pull request"
|
||||||
|
|
||||||
echo "Pull request created successfully."
|
echo "Pull request created successfully."
|
||||||
|
|
||||||
git checkout "${current_branch}"
|
# Cleanup
|
||||||
|
cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
create_pr_from_commit() {
|
create_pr_from_commit() {
|
||||||
|
Loading…
Reference in New Issue
Block a user