Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions src/github-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@
import chalk = require('chalk');
import {checkpoint, CheckpointType} from './util/checkpoint';
import {ReleasePRFactory} from './release-pr-factory';
import {GitHub, OctokitAPIs, ReleaseCreateResponse} from './github';
import {GitHub, OctokitAPIs} from './github';
import {parse} from 'semver';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const parseGithubRepoUrl = require('parse-github-repo-url');
const GITHUB_RELEASE_LABEL = 'autorelease: tagged';

interface ReleaseResponse {
major: number;
minor: number;
patch: number;
version: string;
sha: string;
html_url: string;
tag_name: string;
pr: number;
}

export interface GitHubReleaseOptions {
label: string;
repoUrl: string;
Expand Down Expand Up @@ -64,7 +76,7 @@ export class GitHubRelease {
this.gh = this.gitHubInstance(options.octokitAPIs);
}

async createRelease(): Promise<ReleaseCreateResponse | undefined> {
async createRelease(): Promise<ReleaseResponse | undefined> {
// In most configurations, createRelease() should be called close to when
// a release PR is merged, e.g., a GitHub action that kicks off this
// workflow on merge. For tis reason, we can pull a fairly small number of PRs:
Expand Down Expand Up @@ -131,7 +143,23 @@ export class GitHubRelease {
// Remove 'autorelease: pending' which indicates a GitHub release
// has not yet been created.
await this.gh.removeLabels(this.labels, gitHubReleasePR.number);
return release;

const parsedVersion = parse(version, {loose: true});
if (parsedVersion) {
return {
major: parsedVersion.major,
minor: parsedVersion.minor,
patch: parsedVersion.patch,
sha: gitHubReleasePR.sha,
version,
pr: gitHubReleasePR.number,
html_url: release.html_url,
tag_name: release.tag_name,
};
} else {
console.warn(`failed to parse version informatino from ${version}`);
return undefined;
}
}

addPath(file: string) {
Expand Down
10 changes: 8 additions & 2 deletions test/github-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('GitHubRelease', () => {
return true;
}
)
.reply(200, {tag_name: 'v1.0.2'})
.reply(200, {tag_name: 'v1.0.3'})
.post(
'/repos/googleapis/foo/issues/1/labels',
(body: {[key: string]: string}) => {
Expand All @@ -82,7 +82,10 @@ describe('GitHubRelease', () => {
.reply(200);

const created = await release.createRelease();
strictEqual(created!.tag_name, 'v1.0.2');
strictEqual(created!.tag_name, 'v1.0.3');
strictEqual(created!.major, 1);
strictEqual(created!.minor, 0);
strictEqual(created!.patch, 3);
requests.done();
});

Expand Down Expand Up @@ -146,6 +149,9 @@ describe('GitHubRelease', () => {

const created = await release.createRelease();
strictEqual(created!.tag_name, 'bigquery/v1.0.3');
strictEqual(created!.major, 1);
strictEqual(created!.minor, 0);
strictEqual(created!.patch, 3);
requests.done();
});

Expand Down