Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/process-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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: |
Expand Down
36 changes: 22 additions & 14 deletions scripts/process-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<<EOF\n${reason}\nEOF\n`)
}
}

// Only continue with erc4626 review if
Expand Down
32 changes: 24 additions & 8 deletions src/services/hypernativeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ class HypernativeApi {
})

if (!response.ok) {
const responseBody = await response.text()
console.error('Response Status:', response.status)
console.error('Response Body:', responseBody)
throw new Error(`HTTP error! status: ${response.status}`)
await this.throwHttpError(response)
}

const data: any = await response.json()
Expand Down Expand Up @@ -140,10 +137,7 @@ class HypernativeApi {
})

if (!response.ok) {
const responseBody = await response.text()
console.error('Response Status:', response.status)
console.error('Response Body:', responseBody)
throw new Error(`HTTP error! status: ${response.status}`)
await this.throwHttpError(response)
}

const data: any = await response.json()
Expand Down Expand Up @@ -314,6 +308,28 @@ class HypernativeApi {
}
return validChainName
}

private async throwHttpError(response: Response): Promise<never> {
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
Loading