From 1d4f243a629b9f37a5010c8da6ccfac99534ca3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bj=C3=A4reholt?= Date: Fri, 3 Nov 2023 01:31:21 +0100 Subject: [PATCH] ci: improved bot commit message, PR name and description --- .github/workflows/bot.yml | 30 ++++++++++++++++++------------ scripts/format_log.sh | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 12 deletions(-) create mode 100755 scripts/format_log.sh diff --git a/.github/workflows/bot.yml b/.github/workflows/bot.yml index cb90f89b..0a26507f 100644 --- a/.github/workflows/bot.yml +++ b/.github/workflows/bot.yml @@ -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.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 @@ -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
Log -
$(cat log.txt)
+
$(cat log.txt || echo 'could not get log')
" git config user.name "gptme-bot" git config user.email "gptme-bot@superuserlabs.org" - git commit -m "$COMMIT_MSG" + git commit -m "$COMMIT_MSG_FULL" # Push changes to the PR branch git push -u origin $BRANCH_NAME @@ -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 diff --git a/scripts/format_log.sh b/scripts/format_log.sh new file mode 100755 index 00000000..f03e34f4 --- /dev/null +++ b/scripts/format_log.sh @@ -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