solve-issue.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. name: Use OpenDevin to Resolve GitHub Issue
  2. on:
  3. issues:
  4. types: [labeled]
  5. permissions:
  6. contents: write
  7. pull-requests: write
  8. issues: write
  9. jobs:
  10. dogfood:
  11. if: github.event.label.name == 'solve-this'
  12. runs-on: ubuntu-latest
  13. container:
  14. image: ghcr.io/opendevin/opendevin
  15. volumes:
  16. - /var/run/docker.sock:/var/run/docker.sock
  17. steps:
  18. - name: install git, github cli
  19. run: apt-get install -y git gh
  20. - name: Checkout Repository
  21. uses: actions/checkout@v4
  22. - name: Write Task File
  23. env:
  24. ISSUE_TITLE: ${{ github.event.issue.title }}
  25. ISSUE_BODY: ${{ github.event.issue.body }}
  26. run: |
  27. echo "TITLE:" > task.txt
  28. echo "${ISSUE_TITLE}" >> task.txt
  29. echo "" >> task.txt
  30. echo "BODY:" >> task.txt
  31. echo "${ISSUE_BODY}" >> task.txt
  32. - name: Run OpenDevin
  33. env:
  34. ISSUE_TITLE: ${{ github.event.issue.title }}
  35. ISSUE_BODY: ${{ github.event.issue.body }}
  36. LLM_API_KEY: ${{ secrets.OPENAI_API_KEY }}
  37. SANDBOX_TYPE: exec
  38. run: |
  39. WORKSPACE_MOUNT_PATH=$GITHUB_WORKSPACE python ./opendevin/main.py -i 50 -f task.txt -d $GITHUB_WORKSPACE
  40. rm task.txt
  41. - name: Setup Git, Create Branch, and Commit Changes
  42. run: |
  43. # Setup Git configuration
  44. git config --global --add safe.directory $PWD
  45. git config --global user.name 'OpenDevin'
  46. git config --global user.email 'OpenDevin@users.noreply.github.com'
  47. # Create a unique branch name with a timestamp
  48. BRANCH_NAME="fix/${{ github.event.issue.number }}-$(date +%Y%m%d%H%M%S)"
  49. # Checkout new branch
  50. git checkout -b $BRANCH_NAME
  51. # Add all changes to staging, except task.txt
  52. git add --all -- ':!task.txt'
  53. # Commit the changes, if any
  54. git commit -m "OpenDevin: Resolve Issue #${{ github.event.issue.number }}"
  55. if [ $? -ne 0 ]; then
  56. echo "No changes to commit."
  57. exit 0
  58. fi
  59. # Push changes
  60. git push --set-upstream origin $BRANCH_NAME
  61. - name: Fetch Default Branch
  62. env:
  63. GH_TOKEN: ${{ github.token }}
  64. run: |
  65. # Fetch the default branch using gh cli
  66. DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name)
  67. echo "Default branch is $DEFAULT_BRANCH"
  68. echo "DEFAULT_BRANCH=$DEFAULT_BRANCH" >> $GITHUB_ENV
  69. - name: Generate PR
  70. env:
  71. GH_TOKEN: ${{ github.token }}
  72. run: |
  73. # Create PR and capture URL
  74. PR_URL=$(gh pr create \
  75. --title "OpenDevin: Resolve Issue #2" \
  76. --body "This PR was generated by OpenDevin to resolve issue #2" \
  77. --repo "foragerr/OpenDevin" \
  78. --head "${{ github.head_ref }}" \
  79. --base "${{ env.DEFAULT_BRANCH }}" \
  80. | grep -o 'https://github.com/[^ ]*')
  81. # Extract PR number from URL
  82. PR_NUMBER=$(echo "$PR_URL" | grep -o '[0-9]\+$')
  83. # Set environment vars
  84. echo "PR_URL=$PR_URL" >> $GITHUB_ENV
  85. echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
  86. - name: Post Comment
  87. env:
  88. GH_TOKEN: ${{ github.token }}
  89. run: |
  90. gh issue comment ${{ github.event.issue.number }} \
  91. -b "OpenDevin raised [PR #${{ env.PR_NUMBER }}](${{ env.PR_URL }}) to resolve this issue."