|
| 1 | +name: Stale Community PR Devin Completion |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [labeled] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + complete-stale-pr: |
| 13 | + name: Trigger Devin to Complete Stale Community PR |
| 14 | + # Only run if the 'stale' label was added and PR has 'community' label |
| 15 | + if: github.event.label.name == 'stale' && contains(github.event.pull_request.labels.*.name, 'community') |
| 16 | + runs-on: blacksmith-2vcpu-ubuntu-2404 |
| 17 | + steps: |
| 18 | + - name: Create Devin session |
| 19 | + env: |
| 20 | + DEVIN_API_KEY: ${{ secrets.DEVIN_API_KEY }} |
| 21 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 22 | + PR_TITLE: ${{ github.event.pull_request.title }} |
| 23 | + PR_AUTHOR: ${{ github.event.pull_request.user.login }} |
| 24 | + PR_BRANCH: ${{ github.event.pull_request.head.ref }} |
| 25 | + REPO_NAME: ${{ github.repository }} |
| 26 | + run: | |
| 27 | + FULL_PROMPT="You are completing a stale community PR #${PR_NUMBER} in repository ${REPO_NAME}. |
| 28 | +
|
| 29 | + This PR was started by @${PR_AUTHOR} but has become stale. Your job is to complete it. |
| 30 | +
|
| 31 | + PR Title: ${PR_TITLE} |
| 32 | + PR Branch: ${PR_BRANCH} |
| 33 | +
|
| 34 | + Your tasks: |
| 35 | + 1. Clone the repository ${REPO_NAME} locally. |
| 36 | + 2. Check out the PR branch: ${PR_BRANCH} |
| 37 | + 3. Review the current state of the PR and understand what it's trying to accomplish. |
| 38 | + 4. Read the PR description and any comments/review feedback on the PR. |
| 39 | + 5. Complete any unfinished work on the PR: |
| 40 | + - Fix any issues mentioned in review comments |
| 41 | + - Ensure the code follows the repository's coding standards |
| 42 | + - Add any missing tests if applicable |
| 43 | + - Fix any linting or type errors |
| 44 | + 6. Run the appropriate checks (lint, type-check, tests) to ensure the PR is ready for review. |
| 45 | + 7. Commit your changes with clear commit messages. |
| 46 | + 8. Push your changes to the PR branch. |
| 47 | + 9. Post a summary comment on the PR explaining what you completed. |
| 48 | +
|
| 49 | + Rules and Guidelines: |
| 50 | + 1. Respect the original author's intent and approach - don't rewrite the PR from scratch. |
| 51 | + 2. Make minimal, focused changes that complete the PR's original goal. |
| 52 | + 3. Follow the existing code style and conventions in the repository. |
| 53 | + 4. If the PR's original approach seems fundamentally flawed, explain why in a comment instead of making major changes. |
| 54 | + 5. Never ask for user confirmation. Never wait for user messages. |
| 55 | + 6. Credit the original author in your commit messages where appropriate." |
| 56 | +
|
| 57 | + RESPONSE=$(curl -s -X POST "https://api.devin.ai/v1/sessions" \ |
| 58 | + -H "Authorization: Bearer ${DEVIN_API_KEY}" \ |
| 59 | + -H "Content-Type: application/json" \ |
| 60 | + -d "$(jq -n \ |
| 61 | + --arg prompt "$FULL_PROMPT" \ |
| 62 | + --arg title "Complete Stale PR #${PR_NUMBER}: ${PR_TITLE}" \ |
| 63 | + '{ |
| 64 | + prompt: $prompt, |
| 65 | + title: $title, |
| 66 | + tags: ["stale-pr-completion", "pr-'${PR_NUMBER}'"] |
| 67 | + }')") |
| 68 | + |
| 69 | + SESSION_URL=$(echo "$RESPONSE" | jq -r '.url // .session_url // empty') |
| 70 | + if [ -n "$SESSION_URL" ]; then |
| 71 | + echo "Devin session created: $SESSION_URL" |
| 72 | + echo "SESSION_URL=$SESSION_URL" >> $GITHUB_ENV |
| 73 | + else |
| 74 | + echo "Failed to create Devin session" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | +
|
| 78 | + - name: Post comment with Devin session link |
| 79 | + if: env.SESSION_URL != '' |
| 80 | + uses: actions/github-script@v7 |
| 81 | + env: |
| 82 | + PR_AUTHOR: ${{ github.event.pull_request.user.login }} |
| 83 | + with: |
| 84 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + script: | |
| 86 | + const sessionUrl = process.env.SESSION_URL; |
| 87 | + const prAuthor = process.env.PR_AUTHOR; |
| 88 | + await github.rest.issues.createComment({ |
| 89 | + owner: context.repo.owner, |
| 90 | + repo: context.repo.repo, |
| 91 | + issue_number: context.payload.pull_request.number, |
| 92 | + body: `### Devin AI is completing this stale PR\n\nThis PR by @${prAuthor} has been marked as stale. A Devin session has been created to complete the remaining work.\n\n[View Devin Session](${sessionUrl})\n\n---\n*Devin will review the PR, address any feedback, and push updates to complete this PR.*` |
| 93 | + }); |
0 commit comments