diff --git a/src/upload.ts b/src/upload.ts index 00ed41d..585411e 100644 --- a/src/upload.ts +++ b/src/upload.ts @@ -1,3 +1,4 @@ +import * as core from '@actions/core' import { readFileSync } from 'node:fs' /** @@ -23,18 +24,25 @@ export async function upload( throw new Error('invalid OpenAPI path') } - let formData = [ - [encodeURIComponent('openapi'), encodeURIComponent(data.toString())] - ] + const formData: Record = { + 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',