diff --git a/.github/workflows/process-issue.yml b/.github/workflows/process-issue.yml index f660437..824047d 100644 --- a/.github/workflows/process-issue.yml +++ b/.github/workflows/process-issue.yml @@ -54,6 +54,7 @@ jobs: run: | echo "GITHUB_OUTPUT: ${{ env.GITHUB_OUTPUT }}" echo "hypernative_agent_ids: '${{ steps.process-issue.outputs.hypernative_agent_ids }}'" + echo "hypernative_agent_error: '${{ steps.process-issue.outputs.hypernative_agent_error }}'" - name: Create Pull Request uses: peter-evans/create-pull-request@v7.0.8 with: @@ -78,6 +79,7 @@ jobs: ### Hypernative agents - IDs: `${{ steps.process-issue.outputs.hypernative_agent_ids }}` - Names: `${{ steps.process-issue.outputs.hypernative_agent_names }}` + ${{ steps.process-issue.outputs.hypernative_agent_error != '' && format('- **Creation failed:** {0}', steps.process-issue.outputs.hypernative_agent_error) || '' }} Closes #${{ github.event.issue.number }} labels: | diff --git a/scripts/process-issue.ts b/scripts/process-issue.ts index b0b0833..664c5b4 100644 --- a/scripts/process-issue.ts +++ b/scripts/process-issue.ts @@ -111,31 +111,39 @@ async function processIssue(issueJson: string) { // this step requires the registry to be read thus having the registry updated already let createdAgents: HypernativeAgent[] = [] + let agentCreationError: string | undefined try { const isStablecoin = issueData.additional_contract_information.selected.includes( - 'Is the rate provider reporting for a stable coin - in USD terms?', + 'Is the rate provider reporting for a stable coin/FX/Yield tracking?', ) createdAgents = await createCustomAgents(issueData.rate_provider_contract_address, network, isStablecoin) console.log('createdAgents:', createdAgents) } catch (error) { - console.log(`Failed to create custom agents for chain ${network.name}`) + agentCreationError = error instanceof Error ? error.message : String(error) + console.log(`Failed to create custom agents for chain ${network.name}: ${agentCreationError}`) } - // If we successfully created any Hypernative agents, expose simple variables - // via the GitHub Actions step outputs (GITHUB_OUTPUT). The workflow can then - // use these in a markdown template in the PR body. - if (createdAgents.length > 0 && process.env.GITHUB_OUTPUT) { + // Expose Hypernative agent results (or failure reason) via GITHUB_OUTPUT for the PR body. + if (process.env.GITHUB_OUTPUT) { const outputPath = process.env.GITHUB_OUTPUT - const ids = createdAgents.map((agent) => agent.id).join(', ') - const names = createdAgents.map((agent) => agent.agentName).join(', ') - console.log('GITHUB_OUTPUT path:', outputPath) - console.log('hypernative_agent_ids value:', ids) - console.log('hypernative_agent_names value:', names) - - fs.appendFileSync(outputPath, `hypernative_agent_ids=${ids}\n`) - fs.appendFileSync(outputPath, `hypernative_agent_names=${names}\n`) + if (createdAgents.length > 0) { + const ids = createdAgents.map((agent) => agent.id).join(', ') + const names = createdAgents.map((agent) => agent.agentName).join(', ') + + console.log('GITHUB_OUTPUT path:', outputPath) + console.log('hypernative_agent_ids value:', ids) + console.log('hypernative_agent_names value:', names) + + fs.appendFileSync(outputPath, `hypernative_agent_ids=${ids}\n`) + fs.appendFileSync(outputPath, `hypernative_agent_names=${names}\n`) + } else { + const reason = (agentCreationError ?? 'No agents were created (unknown error)').replace(/\r?\n/g, ' ') + console.log('hypernative_agent_error value:', reason) + // Multiline delimiter keeps special characters (colons, quotes) safe in GITHUB_OUTPUT + fs.appendFileSync(outputPath, `hypernative_agent_error< { + const responseBody = await response.text() + console.error('Response Status:', response.status) + console.error('Response Body:', responseBody) + + let detail = `HTTP ${response.status}` + try { + const parsed = JSON.parse(responseBody) + if (parsed?.error) { + detail = `${detail}: ${parsed.error}` + } else if (responseBody) { + detail = `${detail}: ${responseBody}` + } + } catch { + if (responseBody) { + detail = `${detail}: ${responseBody}` + } + } + + throw new Error(detail) + } } export default HypernativeApi