review-pr.yml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Workflow that uses OpenHands to review a pull request. PR must be labeled 'review-this'
  2. name: Use OpenHands to Review Pull Request
  3. on:
  4. pull_request:
  5. types: [synchronize, labeled]
  6. permissions:
  7. contents: write
  8. pull-requests: write
  9. jobs:
  10. dogfood:
  11. if: contains(github.event.pull_request.labels.*.name, 'review-this')
  12. runs-on: ubuntu-latest
  13. steps:
  14. - uses: actions/checkout@v4
  15. - name: Set up Docker Buildx
  16. id: buildx
  17. uses: docker/setup-buildx-action@v3
  18. - name: Set up Python
  19. uses: actions/setup-python@v5
  20. with:
  21. python-version: '3.12'
  22. - name: install git, github cli
  23. run: |
  24. sudo apt-get install -y git gh
  25. git config --global --add safe.directory $PWD
  26. - name: Checkout Repository
  27. uses: actions/checkout@v4
  28. with:
  29. ref: ${{ github.event.pull_request.base.ref }} # check out the target branch
  30. - name: Download Diff
  31. run: |
  32. curl -O "${{ github.event.pull_request.diff_url }}" -L
  33. - name: Write Task File
  34. run: |
  35. echo "Your coworker wants to apply a pull request to this project." > task.txt
  36. echo "Read and review ${{ github.event.pull_request.number }}.diff file. Create a review-${{ github.event.pull_request.number }}.txt and write your concise comments and suggestions there." >> task.txt
  37. echo "Do not ask me for confirmation at any point." >> task.txt
  38. echo "" >> task.txt
  39. echo "Title" >> task.txt
  40. echo "${{ github.event.pull_request.title }}" >> task.txt
  41. echo "" >> task.txt
  42. echo "Description" >> task.txt
  43. echo "${{ github.event.pull_request.body }}" >> task.txt
  44. echo "" >> task.txt
  45. echo "Diff file is: ${{ github.event.pull_request.number }}.diff" >> task.txt
  46. - name: Set up environment
  47. run: |
  48. curl -sSL https://install.python-poetry.org | python3 -
  49. export PATH="/github/home/.local/bin:$PATH"
  50. poetry install --without evaluation,llama-index
  51. poetry run playwright install --with-deps chromium
  52. - name: Run OpenHands
  53. env:
  54. LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
  55. LLM_MODEL: ${{ vars.LLM_MODEL }}
  56. run: |
  57. # Append path to launch poetry
  58. export PATH="/github/home/.local/bin:$PATH"
  59. # Append path to correctly import package, note: must set pwd at first
  60. export PYTHONPATH=$(pwd):$PYTHONPATH
  61. export WORKSPACE_MOUNT_PATH=$GITHUB_WORKSPACE
  62. export WORKSPACE_BASE=$GITHUB_WORKSPACE
  63. echo -e "/exit\n" | poetry run python openhands/core/main.py -i 50 -f task.txt
  64. rm task.txt
  65. - name: Check if review file is non-empty
  66. id: check_file
  67. run: |
  68. ls -la
  69. if [[ -s review-${{ github.event.pull_request.number }}.txt ]]; then
  70. echo "non_empty=true" >> $GITHUB_OUTPUT
  71. fi
  72. shell: bash
  73. - name: Create PR review if file is non-empty
  74. env:
  75. GH_TOKEN: ${{ github.token }}
  76. if: steps.check_file.outputs.non_empty == 'true'
  77. run: |
  78. gh pr review ${{ github.event.pull_request.number }} --comment --body-file "review-${{ github.event.pull_request.number }}.txt"