Skip to content

Commit

Permalink
feat: allow overriding release label (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 committed May 11, 2021
1 parent 37f4ec2 commit 1af2623
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/github-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ export class GitHubRelease {
releasePR: ReleasePR;
gh: GitHub;
draft: boolean;
releaseLabel: string;

constructor(options: GitHubReleaseConstructorOptions) {
this.draft = !!options.draft;
this.gh = options.github;
this.releasePR = options.releasePR;
this.releaseLabel = options.releaseLabel ?? GITHUB_RELEASE_LABEL;
}

async createRelease(): Promise<
Expand Down Expand Up @@ -107,7 +109,7 @@ export class GitHubRelease {

// Add a label indicating that a release has been created on GitHub,
// but a publication has not yet occurred.
await this.gh.addLabels([GITHUB_RELEASE_LABEL], candidate.pullNumber);
await this.gh.addLabels([this.releaseLabel], candidate.pullNumber);
// Remove 'autorelease: pending' which indicates a GitHub release
// has not yet been created.
await this.gh.removeLabels(this.releasePR.labels, candidate.pullNumber);
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface GitHubOptions {

// Used by GitHubRelease: Factory and Constructor
export interface GitHubReleaseOptions {
releaseLabel?: string;
draft?: boolean;
}

Expand Down
38 changes: 35 additions & 3 deletions test/github-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {describe, it, afterEach} from 'mocha';
import {expect} from 'chai';
import * as nock from 'nock';
import * as crypto from 'crypto';
import {strictEqual} from 'assert';
import {strictEqual, ok} from 'assert';
nock.disableNetConnect();

import {GitHubRelease} from '../src/github-release';
Expand Down Expand Up @@ -79,7 +79,8 @@ describe('GitHubRelease', () => {

function mockGithubLabelsAndComment(
mock: sinon.SinonMock,
mockLabelsAndComment: boolean
mockLabelsAndComment: boolean,
releaseLabel = 'autorelease: tagged'
) {
if (mockLabelsAndComment) {
mock
Expand All @@ -92,7 +93,7 @@ describe('GitHubRelease', () => {
.resolves();
mock
.expects('addLabels')
.withExactArgs(['autorelease: tagged'], 1)
.withExactArgs([releaseLabel], 1)
.once()
.resolves();
mock
Expand Down Expand Up @@ -593,6 +594,37 @@ describe('GitHubRelease', () => {
mock.verify();
expect(created).to.be.undefined;
});

it('supports overriding the release tag', async () => {
const github = new GitHub({owner: 'googleapis', repo: 'foo'});
const mock = mockGithubCommon({
github,
prHead: 'release-v1.0.3',
prTitle: 'Release v1.0.3',
});
mockGithubLabelsAndComment(mock, true, 'custom-label');
mock
.expects('createRelease')
.withExactArgs('foo', 'v1.0.3', 'abc123', '\n* entry', false)
.once()
.resolves({
name: 'foo v1.0.3',
tag_name: 'v1.0.3',
html_url: 'https://release.url',
upload_url: 'https://upload.url/',
body: '\n* entry',
});

const releasePR = new ReleasePR({github, packageName: 'foo'});
const releaser = new GitHubRelease({
github,
releasePR,
releaseLabel: 'custom-label',
});
const created = await releaser.run();

ok(created);
});
});
describe('createRelease', () => {
it('uses version for createRelease', async () => {
Expand Down

0 comments on commit 1af2623

Please sign in to comment.