Skip to content

Commit

Permalink
feat(github): ✅ support branch argument
Browse files Browse the repository at this point in the history
  • Loading branch information
edbzn committed Oct 6, 2021
1 parent 637758b commit d38b048
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
12 changes: 11 additions & 1 deletion packages/semver/src/executors/github/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@ describe('@jscutlery/semver:github', () => {
});
});

it('create release with given tag', async () => {
it('create release with specified tag', async () => {
const output = await executor(options);

expect(mockExec).toBeCalledWith('gh release create', ['v1.0.0']);
expect(output.success).toBe(true);
});

it('create release with specified branch', async () => {
const output = await executor({ ...options, branch: 'master' });

expect(mockExec).toBeCalledWith(
'gh release create',
expect.arrayContaining(['master'])
);
expect(output.success).toBe(true);
});
});
29 changes: 16 additions & 13 deletions packages/semver/src/executors/github/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import { execAsync } from '../common/exec-async';

import type { GithubExecutorSchema } from './schema';

export default async function runExecutor(
options: GithubExecutorSchema,
) {
return execAsync('gh release create', [options.tag])
.pipe(
mapTo({ success: true }),
catchError((error) => {
logger.error(error.stack ?? error.toString());
return of({ success: false });
})
)
.toPromise();
export default async function runExecutor({
tag,
branch,
}: GithubExecutorSchema) {
return execAsync('gh release create', [
tag,
...(branch ? [`--branch ${branch}`] : []),
])
.pipe(
mapTo({ success: true }),
catchError((error) => {
logger.error(error.stack ?? error.toString());
return of({ success: false });
})
)
.toPromise();
}

1 change: 1 addition & 0 deletions packages/semver/src/executors/github/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export interface GithubExecutorSchema {
tag: string;
branch?: string;
}
4 changes: 4 additions & 0 deletions packages/semver/src/executors/github/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"tag": {
"type": "string",
"description": "Create a new release from given tag."
},
"branch": {
"type": "string",
"description": "Target branch or full commit SHA (default: main branch)."
}
},
"required": ["tag"]
Expand Down

0 comments on commit d38b048

Please sign in to comment.