Skip to content

Commit 1d4f243

Browse files
committed
ci: improved bot commit message, PR name and description
1 parent 4980bce commit 1d4f243

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

.github/workflows/bot.yml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,6 @@ jobs:
141141
# stage changes
142142
git add -A
143143
144-
- name: Read and format log
145-
run: |
146-
# Assuming the log file is located at ~/.local/share/gptme/logs/<conversation name>/conversation.jsonl
147-
while IFS= read -r line; do
148-
echo $(echo "$line" | jq -r '"\(.role): \(.content)"')
149-
done < ~/.local/share/gptme/logs/*/conversation.jsonl > log.txt
150-
151144
- name: Generate commit message
152145
run: |
153146
# generate commit message
@@ -164,23 +157,36 @@ jobs:
164157
BRANCH_NAME: ${{ steps.checkout_branch.outputs.branch_name }}
165158
BRANCH_BASE: "master"
166159
run: |
160+
# Read and format log
161+
./scripts/format_log.sh ~/.local/share/gptme/logs/*/conversation.jsonl > log.txt
162+
167163
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
168164
COMMENT_URL="https://github.com/${{ github.repository }}/issues/${{ github.event.issue.number }}#issuecomment-${{ github.event.comment.id }}"
169165
170-
COMMIT_MSG="\`gptme '$GPTME_COMMAND'\`
166+
# commit message & description
167+
COMMIT_MSG="$(cat message.txt || echo 'no commit message')"
168+
COMMIT_DESC="\`gptme '$GPTME_COMMAND'\`
171169
172170
Triggered by: $COMMENT_URL
173-
Run: $RUN_URL
171+
Run: $RUN_URL"
172+
173+
# commit message with description
174+
COMMIT_MSG_FULL="$COMMIT_MSG
175+
176+
$COMMIT_DESC"
177+
178+
# commit message with description and log
179+
COMMIT_MSG_FULL_WITH_LOG="$COMMIT_MSG_FULL
174180
175181
<details>
176182
<summary>Log</summary>
177-
<pre>$(cat log.txt)</pre>
183+
<pre>$(cat log.txt || echo 'could not get log')</pre>
178184
</details>"
179185
180186
git config user.name "gptme-bot"
181187
git config user.email "[email protected]"
182188
183-
git commit -m "$COMMIT_MSG"
189+
git commit -m "$COMMIT_MSG_FULL"
184190
185191
# Push changes to the PR branch
186192
git push -u origin $BRANCH_NAME
@@ -193,7 +199,7 @@ jobs:
193199
sleep 1
194200
195201
# Create a PR
196-
PR_URL=$(gh pr create --title "Changes for issue #$ISSUE_NUMBER" --body "$COMMIT_MSG" --repo $USER_NAME/$REPO_NAME | grep -o 'https://github.com[^ ]*')
202+
PR_URL=$(gh pr create --title "$COMMIT_MSG" --body "$COMMIT_MSG_FULL_WITH_LOG" --repo $USER_NAME/$REPO_NAME | grep -o 'https://github.com[^ ]*')
197203
# These are redundant/implied: --base $BRANCH_BASE --head $USER_NAME:$BRANCH_NAME
198204
199205
# Comment on the issue with the PR link

scripts/format_log.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
# Usage: ./format_log.sh <~/.local/share/gptme/logs/*/conversation.jsonl>
3+
while IFS= read -r line; do
4+
role="
5+
$(echo "$line" | jq -r '.role'):"
6+
# Pad the role to a length of 12 with spaces
7+
role=$(printf "%-12s" "$role")
8+
content=$(echo "$line" | jq -r '.content')
9+
echo "$content" | while IFS= read -r line_content; do
10+
if [[ -z "$line_content" ]]; then
11+
echo " "
12+
else
13+
echo "$role $line_content"
14+
role=" "
15+
fi
16+
done
17+
done < $1

0 commit comments

Comments
 (0)