Skip to content

Commit 8aa7aa5

Browse files
Merge pull request #45 from intuit/bug
Fix Single new project
2 parents a7fb0ac + b9e474a commit 8aa7aa5

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/__tests__/github-release.test.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,18 @@ describe('GithubRelease', () => {
218218
describe('addToChangelog', async () => {
219219
test("creates new changelog if one didn't exist", async () => {
220220
const gh = new GithubRelease();
221-
await gh.addToChangelog('# My new Notes', 'v0.0.0');
221+
await gh.addToChangelog(
222+
'# My new Notes',
223+
'klajsdlfk4lj51l43k5hj234l',
224+
'v0.0.0'
225+
);
222226

223227
expect(writeSpy.mock.calls[0][1].includes(`# My new Notes`)).toBe(true);
224228
});
225229

226230
test("creates new changelog if one didn't exist", async () => {
227231
const gh = new GithubRelease();
228-
await gh.addToChangelog('# My new Notes', 'v1.0.0', false);
232+
await gh.addToChangelog('# My new Notes', 'v1.0.0', 'v1.0.0', false);
229233

230234
expect(writeSpy.mock.calls[0][1].includes(`v1.0.1`)).toBe(true);
231235
});
@@ -236,7 +240,11 @@ describe('GithubRelease', () => {
236240
existsSync.mockReturnValueOnce(true);
237241
readResult = '# My old Notes';
238242

239-
await gh.addToChangelog('# My new Notes', 'v0.0.0');
243+
await gh.addToChangelog(
244+
'# My new Notes',
245+
'asdfasdlkfjlkj435l2j',
246+
'v0.0.0'
247+
);
240248
expect(writeSpy.mock.calls[0][1].includes(readResult)).toBe(true);
241249
});
242250

@@ -247,7 +255,13 @@ describe('GithubRelease', () => {
247255
existsSync.mockReturnValueOnce(true);
248256
readResult = '# My old Notes';
249257

250-
await gh.addToChangelog('# My new Notes', 'v0.0.0', false, message);
258+
await gh.addToChangelog(
259+
'# My new Notes',
260+
'asdklfhlkh24387513',
261+
'v0.0.0',
262+
false,
263+
message
264+
);
251265
expect(execSpy.mock.calls[1][0].includes(message)).toBe(true);
252266
});
253267
});

src/github-release.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,28 @@ export default class GithubRelease {
159159
public async addToChangelog(
160160
releaseNotes: string,
161161
lastRelease: string,
162+
currentVersion: string,
162163
noVersionPrefix = true,
163164
message = 'Update CHANGELOG.md [skip ci]'
164165
) {
165166
this.logger.verbose.info('Adding new changes to changelog.');
166167

167-
const version = await this.calcNextVersion(lastRelease);
168+
let version;
169+
170+
if (lastRelease.match(/\d+\.\d+\.\d+/)) {
171+
version = await this.calcNextVersion(lastRelease);
172+
} else {
173+
const bump = await this.getSemverBump(lastRelease);
174+
version = inc(currentVersion, bump as ReleaseType);
175+
}
168176

169177
this.logger.verbose.info('Calculated next version to be:', version);
170178

171179
const date = new Date().toDateString();
172-
const prefixed = noVersionPrefix ? version : `v${version}`;
180+
const prefixed =
181+
noVersionPrefix || (version && version.startsWith('v'))
182+
? version
183+
: `v${version}`;
173184

174185
let newChangelog = `# ${prefixed} (${date})\n\n${releaseNotes}`;
175186

src/main.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ async function makeChangelog(
134134

135135
await githubRelease.addToChangelog(
136136
releaseNotes,
137+
lastRelease,
137138
currentVersion,
138139
args.no_version_prefix,
139140
args.message || undefined
@@ -201,7 +202,7 @@ export async function run(args: ArgsType) {
201202
let rawConfig = {};
202203

203204
const prefixRelease = (release: string) =>
204-
args.no_version_prefix || release.includes('v') ? release : `v${release}`;
205+
args.no_version_prefix || release.startsWith('v') ? release : `v${release}`;
205206

206207
if (result && result.config) {
207208
rawConfig = result.config;

0 commit comments

Comments
 (0)