File size: 3,376 Bytes
9004c96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Use OpenDevin to Resolve GitHub Issue

on:
  issues:
    types: [labeled]

permissions:
  contents: write
  pull-requests: write
  issues: write

jobs:
  dogfood:
    if: github.event.label.name == 'solve-this'
    runs-on: ubuntu-latest
    container:
      image: ghcr.io/opendevin/opendevin
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock

    steps:
    - name: install git, github cli
      run: apt-get install -y git gh

    - name: Checkout Repository
      uses: actions/checkout@v4

    - 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 }}
        SANDBOX_TYPE: exec
      run: |
        WORKSPACE_MOUNT_PATH=$GITHUB_WORKSPACE python ./opendevin/core/main.py -i 50 -f task.txt -d $GITHUB_WORKSPACE
        rm task.txt

    - name: Setup Git, Create Branch, and Commit Changes
      run: |
        # Setup Git configuration
        git config --global --add safe.directory $PWD
        git config --global user.name 'OpenDevin'
        git config --global user.email '[email protected]'

        # 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: 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."