Skip to content

Commit

Permalink
ci: improved bot commit message, PR name and description
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Nov 3, 2023
1 parent 4980bce commit 1d4f243
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
30 changes: 18 additions & 12 deletions .github/workflows/bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ jobs:
# stage changes
git add -A
- name: Read and format log
run: |
# Assuming the log file is located at ~/.local/share/gptme/logs/<conversation name>/conversation.jsonl
while IFS= read -r line; do
echo $(echo "$line" | jq -r '"\(.role): \(.content)"')
done < ~/.local/share/gptme/logs/*/conversation.jsonl > log.txt
- name: Generate commit message
run: |
# generate commit message
Expand All @@ -164,23 +157,36 @@ jobs:
BRANCH_NAME: ${{ steps.checkout_branch.outputs.branch_name }}
BRANCH_BASE: "master"
run: |
# Read and format log
./scripts/format_log.sh ~/.local/share/gptme/logs/*/conversation.jsonl > log.txt
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
COMMENT_URL="https://github.com/${{ github.repository }}/issues/${{ github.event.issue.number }}#issuecomment-${{ github.event.comment.id }}"
COMMIT_MSG="\`gptme '$GPTME_COMMAND'\`
# commit message & description
COMMIT_MSG="$(cat message.txt || echo 'no commit message')"
COMMIT_DESC="\`gptme '$GPTME_COMMAND'\`
Triggered by: $COMMENT_URL
Run: $RUN_URL
Run: $RUN_URL"
# commit message with description
COMMIT_MSG_FULL="$COMMIT_MSG
$COMMIT_DESC"
# commit message with description and log
COMMIT_MSG_FULL_WITH_LOG="$COMMIT_MSG_FULL
<details>
<summary>Log</summary>
<pre>$(cat log.txt)</pre>
<pre>$(cat log.txt || echo 'could not get log')</pre>
</details>"
git config user.name "gptme-bot"
git config user.email "[email protected]"
git commit -m "$COMMIT_MSG"
git commit -m "$COMMIT_MSG_FULL"
# Push changes to the PR branch
git push -u origin $BRANCH_NAME
Expand All @@ -193,7 +199,7 @@ jobs:
sleep 1
# Create a PR
PR_URL=$(gh pr create --title "Changes for issue #$ISSUE_NUMBER" --body "$COMMIT_MSG" --repo $USER_NAME/$REPO_NAME | grep -o 'https://github.com[^ ]*')
PR_URL=$(gh pr create --title "$COMMIT_MSG" --body "$COMMIT_MSG_FULL_WITH_LOG" --repo $USER_NAME/$REPO_NAME | grep -o 'https://github.com[^ ]*')
# These are redundant/implied: --base $BRANCH_BASE --head $USER_NAME:$BRANCH_NAME
# Comment on the issue with the PR link
Expand Down
17 changes: 17 additions & 0 deletions scripts/format_log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Usage: ./format_log.sh <~/.local/share/gptme/logs/*/conversation.jsonl>
while IFS= read -r line; do
role="
$(echo "$line" | jq -r '.role'):"
# Pad the role to a length of 12 with spaces
role=$(printf "%-12s" "$role")
content=$(echo "$line" | jq -r '.content')
echo "$content" | while IFS= read -r line_content; do
if [[ -z "$line_content" ]]; then
echo " "
else
echo "$role $line_content"
role=" "
fi
done
done < $1

0 comments on commit 1d4f243

Please sign in to comment.