|
| 1 | +name: Devin on "devin" label |
| 2 | +on: |
| 3 | + issues: |
| 4 | + types: [labeled] |
| 5 | + |
| 6 | +# allow commenting on the issue |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + issues: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + create-devin-session: |
| 13 | + if: ${{ github.event.label.name == 'devin' }} |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Ensure jq is available |
| 17 | + run: | |
| 18 | + if ! command -v jq >/dev/null; then |
| 19 | + sudo apt-get update && sudo apt-get install -y jq |
| 20 | + fi |
| 21 | +
|
| 22 | + - name: Build prompt file |
| 23 | + run: | |
| 24 | + cat > prompt.txt <<'EOF' |
| 25 | + Triage this issue: |
| 26 | + ${{ github.event.issue.html_url }} |
| 27 | +
|
| 28 | + Title: ${{ github.event.issue.title }} |
| 29 | +
|
| 30 | + Body: |
| 31 | + ${{ github.event.issue.body }} |
| 32 | + EOF |
| 33 | +
|
| 34 | + - name: Create Devin session |
| 35 | + id: devin |
| 36 | + env: |
| 37 | + DEVIN_API_KEY: ${{ secrets.DEVIN_API_KEY }} |
| 38 | + run: | |
| 39 | + set -eo pipefail |
| 40 | +
|
| 41 | + resp=$(curl -fSs https://api.devin.ai/v1/sessions \ |
| 42 | + -H "Authorization: Bearer $DEVIN_API_KEY" \ |
| 43 | + -H "Content-Type: application/json" \ |
| 44 | + -d "$(jq -n --rawfile prompt prompt.txt \ |
| 45 | + --arg title "Issue #${{ github.event.issue.number }}: ${{ github.event.issue.title }}" \ |
| 46 | + --arg repo "${{ github.repository }}" \ |
| 47 | + --arg issue "${{ github.event.issue.number }}" \ |
| 48 | + '{prompt:$prompt, title:$title, idempotent:true, |
| 49 | + tags:["src:github","label:devin","repo:"+$repo,"issue:"+$issue]}')" ) |
| 50 | + |
| 51 | + echo "$resp" > resp.json |
| 52 | +
|
| 53 | + # required outputs (fail if url missing) |
| 54 | + url=$(jq -er '.url' resp.json) |
| 55 | + echo "url=$url" >> "$GITHUB_OUTPUT" |
| 56 | +
|
| 57 | + session_id=$(jq -r '.session_id' resp.json) |
| 58 | + echo "session_id=$session_id" >> "$GITHUB_OUTPUT" |
| 59 | +
|
| 60 | + is_new=$(jq -r '.is_new_session // true' resp.json) |
| 61 | + echo "is_new_session=$is_new" >> "$GITHUB_OUTPUT" |
| 62 | +
|
| 63 | + - name: Comment on the issue with session link (newline-safe) |
| 64 | + if: ${{ steps.devin.outputs.url != '' && steps.devin.outputs.is_new_session == 'true' }} |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + run: | |
| 68 | + jq -n \ |
| 69 | + --arg url "${{ steps.devin.outputs.url }}" \ |
| 70 | + '{body: "🤖 Devin is on it.\n\n**Session:** \($url)"}' > body.json |
| 71 | +
|
| 72 | + curl -sS -X POST \ |
| 73 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 74 | + -H "Accept: application/vnd.github+json" \ |
| 75 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 76 | + --data @body.json \ |
| 77 | + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" |
0 commit comments