From ab21d447fdb7cf4db5ff0afe8aeabb4fb6172627 Mon Sep 17 00:00:00 2001 From: CJ Quines Date: Wed, 4 Sep 2024 16:55:40 -0400 Subject: [PATCH] feat: add branch (#48) * feat: add branch * oop --- README.md | 17 ++++++++++++----- action.yml | 6 +++++- dist/index.js | 8 ++++++-- index.ts | 7 +++++++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index aa88fee..f9f76ba 100644 --- a/README.md +++ b/README.md @@ -52,12 +52,19 @@ You can optionally add `config_path: 'path/to/my-company.stainless.yaml'` to the You can identify your Stainless project name on the [Stainless dashboard](https://app.stainlessapi.com/). -`commit_message` is an optional parameter that allows you to specify the commit message that we will use for the commits -generated for your SDKs as a result of your API change (and which will subsequently appear in the Changelog). If you -provide it, it MUST follow the [Conventional Commits format](https://www.conventionalcommits.org/en/v1.0.0/). If you do -not provide it, we will use a default message. +### Optional parameters -`guess_config` is an optional parameter that, when `true`, will update your Stainless config file based on the change you've made to your spec. By default, it is `false`. You should not set this to `true` if you are passing a `config_path`. +- `branch`: Specifies the branch to push files to. If you provide it, the project MUST have the [branches +feature](https://app.stainlessapi.com/docs/guides/branches) enabled. By default, it is `main`. + +- `commit_message`: Specifies the commit message that we will use for the commits generated for your SDKs as a result +of the API change (and which will subsequently appear in the Changelog). If you provide it, it MUST follow the +[Conventional Commits format](https://www.conventionalcommits.org/en/v1.0.0/). If you do not provide it, we will use a +default message. + +- `guess_config`: When `true`, will update your Stainless config file based on the change you've made to your spec. This +does the same thing as selecting the "Generate missing endpoints" button in the Studio. By default, it is `false`. You +should not set this to `true` if you are passing a `config_path`. ## Usage with ReadMe for docs with example snippets diff --git a/action.yml b/action.yml index 2536e6d..7952278 100644 --- a/action.yml +++ b/action.yml @@ -27,4 +27,8 @@ inputs: guess_config: description: 'If true, renegerate the endpoints in the Stainless config file.' required: false - default: false + default: 'false' + branch: + description: 'If true, renegerate the endpoints in the Stainless config file.' + required: false + default: 'main' diff --git a/dist/index.js b/dist/index.js index 552af7c..5d28c26 100644 --- a/dist/index.js +++ b/dist/index.js @@ -31725,6 +31725,7 @@ function main() { const projectName = (0, core_1.getInput)('project_name', { required: false }); const commitMessage = (0, core_1.getInput)('commit_message', { required: false }); const guessConfig = (0, core_1.getBooleanInput)('guess_config', { required: false }); + const branch = (0, core_1.getInput)('branch', { required: false }); const outputPath = (0, core_1.getInput)('output_path'); if (configPath && guessConfig) { const errorMsg = "Can't set both configPath and guessConfig"; @@ -31737,7 +31738,7 @@ function main() { throw Error(errorMsg); } (0, console_1.info)(configPath ? 'Uploading spec and config files...' : 'Uploading spec file...'); - const response = yield uploadSpecAndConfig(inputPath, configPath, stainless_api_key, projectName, commitMessage, guessConfig); + const response = yield uploadSpecAndConfig(inputPath, configPath, stainless_api_key, projectName, commitMessage, guessConfig, branch); if (!response.ok) { const text = yield response.text(); const errorMsg = `Failed to upload files: ${response.statusText} ${text}`; @@ -31753,7 +31754,7 @@ function main() { }); } exports.main = main; -function uploadSpecAndConfig(specPath, configPath, token, projectName, commitMessage, guessConfig) { +function uploadSpecAndConfig(specPath, configPath, token, projectName, commitMessage, guessConfig, branch) { return __awaiter(this, void 0, void 0, function* () { const formData = new node_fetch_1.FormData(); formData.set('projectName', projectName); @@ -31769,6 +31770,9 @@ function uploadSpecAndConfig(specPath, configPath, token, projectName, commitMes if (guessConfig) { formData.set('guessConfig', 'true'); } + if (branch) { + formData.set('branch', branch); + } const response = yield (0, node_fetch_1.default)('https://api.stainlessapi.com/api/spec', { method: 'POST', body: formData, diff --git a/index.ts b/index.ts index bf5d411..cc34f0a 100644 --- a/index.ts +++ b/index.ts @@ -20,6 +20,7 @@ export async function main() { const projectName = getInput('project_name', { required: false }); const commitMessage = getInput('commit_message', { required: false }); const guessConfig = getBooleanInput('guess_config', { required: false }); + const branch = getInput('branch', { required: false }); const outputPath = getInput('output_path'); if (configPath && guessConfig) { @@ -43,6 +44,7 @@ export async function main() { projectName, commitMessage, guessConfig, + branch, ); if (!response.ok) { const text = await response.text(); @@ -66,6 +68,7 @@ async function uploadSpecAndConfig( projectName: string, commitMessage: string, guessConfig: boolean, + branch: string, ): Promise { const formData = new FormData(); @@ -87,6 +90,10 @@ async function uploadSpecAndConfig( formData.set('guessConfig', 'true'); } + if (branch) { + formData.set('branch', branch); + } + const response = await fetch('https://api.stainlessapi.com/api/spec', { method: 'POST', body: formData,