|
| 1 | +name: Issue Responder |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + id-token: write |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + respond-to-issue: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Configure AWS credentials |
| 17 | + uses: aws-actions/configure-aws-credentials@v4 |
| 18 | + with: |
| 19 | + role-to-assume: ${{ secrets.STRANDS_AGENTCORE_ACTIONS_ROLE }} |
| 20 | + aws-region: us-west-2 |
| 21 | + - name: Invoke AgentCore with issue details |
| 22 | + env: |
| 23 | + GH_ISSUE_AGENTCORE_RUNTIME_ARN: ${{ secrets.GH_ISSUE_AGENTCORE_RUNTIME_ARN }} |
| 24 | + ISSUE_NUMBER: ${{ github.event.issue.number }} |
| 25 | + ISSUE_TITLE: ${{ github.event.issue.title }} |
| 26 | + ISSUE_BODY: ${{ github.event.issue.body }} |
| 27 | + ISSUE_URL: ${{ github.event.issue.html_url }} |
| 28 | + ISSUE_AUTHOR: ${{ github.event.issue.user.login }} |
| 29 | + REPO: ${{ github.repository }} |
| 30 | + run: | |
| 31 | + npm install @aws-sdk/client-bedrock-agentcore |
| 32 | + node - <<'JSEOF' |
| 33 | + const { BedrockAgentCoreClient, InvokeAgentRuntimeCommand } = require("@aws-sdk/client-bedrock-agentcore"); |
| 34 | +
|
| 35 | + const payload = JSON.stringify({ |
| 36 | + source: "github", |
| 37 | + action: "issue_opened", |
| 38 | + issue: { |
| 39 | + number: parseInt(process.env.ISSUE_NUMBER), |
| 40 | + title: process.env.ISSUE_TITLE, |
| 41 | + body: process.env.ISSUE_BODY, |
| 42 | + url: process.env.ISSUE_URL, |
| 43 | + author: process.env.ISSUE_AUTHOR, |
| 44 | + repo: process.env.REPO |
| 45 | + } |
| 46 | + }); |
| 47 | +
|
| 48 | + console.log("Invoking AgentCore with payload:"); |
| 49 | + console.log(JSON.stringify(JSON.parse(payload), null, 2)); |
| 50 | +
|
| 51 | + const client = new BedrockAgentCoreClient({ region: "us-west-2" }); |
| 52 | + |
| 53 | + const sessionId = `github-issue-${process.env.ISSUE_NUMBER}-${Date.now()}-${Math.random().toString(36).slice(2)}`; |
| 54 | + |
| 55 | + const command = new InvokeAgentRuntimeCommand({ |
| 56 | + agentRuntimeArn: process.env.GH_ISSUE_AGENTCORE_RUNTIME_ARN, |
| 57 | + runtimeSessionId: sessionId, |
| 58 | + payload: Buffer.from(payload) |
| 59 | + }); |
| 60 | +
|
| 61 | + (async () => { |
| 62 | + const response = await client.send(command); |
| 63 | + const textResponse = await response.response.transformToString(); |
| 64 | + console.log("Response:", textResponse); |
| 65 | + })(); |
| 66 | + JSEOF |
0 commit comments