|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euxo pipefail |
| 4 | + |
| 5 | +# This script updates the PR description with commands to run the PR locally |
| 6 | +# It adds both Docker and uvx commands |
| 7 | + |
| 8 | +# Get the branch name for the PR |
| 9 | +BRANCH_NAME=$(gh pr view "$PR_NUMBER" --json headRefName --jq .headRefName) |
| 10 | + |
| 11 | +# Define the Docker command |
| 12 | +DOCKER_RUN_COMMAND="docker run -it --rm \ |
| 13 | + -p 3000:3000 \ |
| 14 | + -v /var/run/docker.sock:/var/run/docker.sock \ |
| 15 | + --add-host host.docker.internal:host-gateway \ |
| 16 | + -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:${SHORT_SHA}-nikolaik \ |
| 17 | + --name openhands-app-${SHORT_SHA} \ |
| 18 | + docker.all-hands.dev/all-hands-ai/openhands:${SHORT_SHA}" |
| 19 | + |
| 20 | +# Define the uvx command |
| 21 | +UVX_RUN_COMMAND="uvx --python 3.12 --from git+https://github.com/All-Hands-AI/OpenHands@${BRANCH_NAME} openhands" |
| 22 | + |
| 23 | +# Get the current PR body |
| 24 | +PR_BODY=$(gh pr view "$PR_NUMBER" --json body --jq .body) |
| 25 | + |
| 26 | +# Prepare the new PR body with both commands |
| 27 | +if echo "$PR_BODY" | grep -q "To run this PR locally, use the following command:"; then |
| 28 | + # For existing PR descriptions, use a more robust approach |
| 29 | + # Split the PR body at the "To run this PR locally" section and replace everything after it |
| 30 | + BEFORE_SECTION=$(echo "$PR_BODY" | sed '/To run this PR locally, use the following command:/,$d') |
| 31 | + NEW_PR_BODY=$(cat <<EOF |
| 32 | +${BEFORE_SECTION} |
| 33 | +
|
| 34 | +To run this PR locally, use the following command: |
| 35 | +
|
| 36 | +GUI with Docker: |
| 37 | +\`\`\` |
| 38 | +${DOCKER_RUN_COMMAND} |
| 39 | +\`\`\` |
| 40 | +
|
| 41 | +CLI with uvx: |
| 42 | +\`\`\` |
| 43 | +${UVX_RUN_COMMAND} |
| 44 | +\`\`\` |
| 45 | +EOF |
| 46 | +) |
| 47 | +else |
| 48 | + # For new PR descriptions: use heredoc safely without indentation |
| 49 | + NEW_PR_BODY=$(cat <<EOF |
| 50 | +$PR_BODY |
| 51 | +
|
| 52 | +--- |
| 53 | +
|
| 54 | +To run this PR locally, use the following command: |
| 55 | +
|
| 56 | +GUI with Docker: |
| 57 | +\`\`\` |
| 58 | +${DOCKER_RUN_COMMAND} |
| 59 | +\`\`\` |
| 60 | +
|
| 61 | +CLI with uvx: |
| 62 | +\`\`\` |
| 63 | +${UVX_RUN_COMMAND} |
| 64 | +\`\`\` |
| 65 | +EOF |
| 66 | +) |
| 67 | +fi |
| 68 | + |
| 69 | +# Update the PR description |
| 70 | +echo "Updating PR description with Docker and uvx commands" |
| 71 | +gh pr edit "$PR_NUMBER" --body "$NEW_PR_BODY" |
0 commit comments