Skip to content

Commit

Permalink
feat: add branch (#48)
Browse files Browse the repository at this point in the history
* feat: add branch

* oop
  • Loading branch information
cjquines authored Sep 4, 2024
1 parent 78c4ec4 commit ab21d44
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
8 changes: 6 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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}`;
Expand All @@ -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);
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -43,6 +44,7 @@ export async function main() {
projectName,
commitMessage,
guessConfig,
branch,
);
if (!response.ok) {
const text = await response.text();
Expand All @@ -66,6 +68,7 @@ async function uploadSpecAndConfig(
projectName: string,
commitMessage: string,
guessConfig: boolean,
branch: string,
): Promise<Response> {
const formData = new FormData();

Expand All @@ -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,
Expand Down

0 comments on commit ab21d44

Please sign in to comment.