diff --git a/.github/workflows/dogfood.yml b/.github/workflows/dogfood.yml new file mode 100644 index 0000000000..161f9e4c6d --- /dev/null +++ b/.github/workflows/dogfood.yml @@ -0,0 +1,116 @@ +name: Use OpenDevin to Resolve GitHub Issue + +on: + issues: + types: [labeled] + +permissions: + contents: write + pull-requests: write + issues: write + +jobs: + open-devin: + if: github.event.label.name == 'dogfood-this' + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Install poetry + run: pipx install poetry + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'poetry' + + - name: Install Dependencies + run: | + make build + + - name: Write Task File + env: + ISSUE_TITLE: ${{ github.event.issue.title }} + ISSUE_BODY: ${{ github.event.issue.body }} + run: | + echo "TITLE:" > task.txt + echo "${ISSUE_TITLE}" >> task.txt + echo "" >> task.txt + echo "BODY:" >> task.txt + echo "${ISSUE_BODY}" >> task.txt + + - name: Run OpenDevin + env: + ISSUE_TITLE: ${{ github.event.issue.title }} + ISSUE_BODY: ${{ github.event.issue.body }} + LLM_API_KEY: ${{ secrets.OPENAI_API_KEY }} + run: | + poetry run python ./opendevin/main.py -d "./" -i 50 -f task.txt + + - name: Setup Git, Create Branch, and Commit Changes + run: | + # Setup Git configuration + git config --global user.name 'OpenDevin' + git config --global user.email 'OpenDevin@users.noreply.github.com' + + # Create a unique branch name with a timestamp + BRANCH_NAME="fix/${{ github.event.issue.number }}-$(date +%Y%m%d%H%M%S)" + + # Checkout new branch + git checkout -b $BRANCH_NAME + + # Add all changes to staging, except task.txt + git add --all -- ':!task.txt' + + # Commit the changes, if any + git commit -m "OpenDevin: Resolve Issue #${{ github.event.issue.number }}" + if [ $? -ne 0 ]; then + echo "No changes to commit." + exit 0 + fi + + # Push changes + git push --set-upstream origin $BRANCH_NAME + + - name: Install GitHub CLI + run: | + sudo apt-get install gh + + - name: Fetch Default Branch + env: + GH_TOKEN: ${{ github.token }} + run: | + # Fetch the default branch using gh cli + DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name) + echo "Default branch is $DEFAULT_BRANCH" + echo "DEFAULT_BRANCH=$DEFAULT_BRANCH" >> $GITHUB_ENV + + - name: Generate PR + env: + GH_TOKEN: ${{ github.token }} + run: | + # Create PR and capture URL + PR_URL=$(gh pr create \ + --title "OpenDevin: Resolve Issue #2" \ + --body "This PR was generated by OpenDevin to resolve issue #2" \ + --repo "foragerr/OpenDevin" \ + --head "${{ github.head_ref }}" \ + --base "${{ env.DEFAULT_BRANCH }}" \ + | grep -o 'https://github.com/[^ ]*') + + # Extract PR number from URL + PR_NUMBER=$(echo "$PR_URL" | grep -o '[0-9]\+$') + + # Set environment vars + echo "PR_URL=$PR_URL" >> $GITHUB_ENV + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV + + - name: Post Comment + env: + GH_TOKEN: ${{ github.token }} + run: | + gh issue comment ${{ github.event.issue.number }} \ + -b "OpenDevin raised [PR #${{ env.PR_NUMBER }}](${{ env.PR_URL }}) to resolve this issue."