Skip to content

Commit

Permalink
Merge pull request #6 from hey-api/chore/github-refs
Browse files Browse the repository at this point in the history
chore: pass github refs to api
  • Loading branch information
mrlubos authored Apr 17, 2024
2 parents c8af9ee + cf1f212 commit 781bc0f
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/upload.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as core from '@actions/core'
import { readFileSync } from 'node:fs'

/**
Expand All @@ -23,18 +24,25 @@ export async function upload(
throw new Error('invalid OpenAPI path')
}

let formData = [
[encodeURIComponent('openapi'), encodeURIComponent(data.toString())]
]
const formData: Record<string, string | number | boolean> = {
github_repo: process.env.GITHUB_REPOSITORY!,
github_repo_id: process.env.GITHUB_REPOSITORY_ID!,
openapi: data.toString()
}

if (dryRun) {
formData = [
...formData,
[encodeURIComponent('dry-run'), encodeURIComponent(dryRun)]
]
formData['dry-run'] = dryRun
}

const body = formData.flatMap(arr => arr.join('=')).join('&')
core.debug(`GitHub repo: ${process.env.GITHUB_REPOSITORY}`)
core.debug(`GitHub repo ID: ${process.env.GITHUB_REPOSITORY_ID}`)

const body = Object.entries(formData)
.flatMap(
([key, value]) =>
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`
)
.join('&')

const response = await fetch(
'https://platform-production-25fb.up.railway.app/api/openapi',
Expand Down

0 comments on commit 781bc0f

Please sign in to comment.