Skip to content

Commit

Permalink
fix(yoshi-go): store the sha of the first commit (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Aug 18, 2020
1 parent f645e87 commit 6c313c1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
14 changes: 7 additions & 7 deletions __snapshots__/yoshi-go.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports['CHANGES-go-yoshi'] = `
### Features
* **all:** auto-regenerate gapics ([#1000](https://github.com/googleapis/yoshi-go-test-repo/issues/1000)) ([#1001](https://github.com/googleapis/yoshi-go-test-repo/issues/1001))
* **all:** auto-regenerate gapics , refs [#1000](https://github.com/googleapis/yoshi-go-test-repo/issues/1000) [#1001](https://github.com/googleapis/yoshi-go-test-repo/issues/1001)
* **asset:** added a really cool feature ([d7d1c89](https://github.com/googleapis/yoshi-go-test-repo/commit/d7d1c890dc1526f4d62ceedad581f498195c8939))
* **pubsublite:** start generating v1 ([1d9662c](https://github.com/googleapis/yoshi-go-test-repo/commit/1d9662cf08ab1cf3b68d95dee4dc99b7c4aac371))
Expand All @@ -22,14 +22,14 @@ exports['CHANGES-go-yoshi'] = `
`

exports['PR body-go-yoshi'] = {
"title": "chore: release 0.124.0",
"body": ":robot: I have created a release \\*beep\\* \\*boop\\* \n---\n## [0.124.0](https://github.com/googleapis/yoshi-go-test-repo/compare/v0.123.4...v0.124.0) \n\n\n### Features\n\n* **all:** auto-regenerate gapics ([#1000](https://github.com/googleapis/yoshi-go-test-repo/issues/1000)) ([#1001](https://github.com/googleapis/yoshi-go-test-repo/issues/1001))\n* **asset:** added a really cool feature ([d7d1c89](https://github.com/googleapis/yoshi-go-test-repo/commit/d7d1c890dc1526f4d62ceedad581f498195c8939))\n* **pubsublite:** start generating v1 ([1d9662c](https://github.com/googleapis/yoshi-go-test-repo/commit/1d9662cf08ab1cf3b68d95dee4dc99b7c4aac371))\n\n\n### Bug Fixes\n\n* **automl:** fixed a really bad bug ([d7d1c89](https://github.com/googleapis/yoshi-go-test-repo/commit/d7d1c890dc1526f4d62ceedad581f498195c8939))\n---\n\n\nThis PR was generated with [Release Please](https://github.com/googleapis/release-please).",
"head": "release-v0.124.0",
"base": "master"
'title': 'chore: release 0.124.0',
'body': ':robot: I have created a release \\*beep\\* \\*boop\\* \n---\n## [0.124.0](https://github.com/googleapis/yoshi-go-test-repo/compare/v0.123.4...v0.124.0) \n\n\n### Features\n\n* **all:** auto-regenerate gapics , refs [#1000](https://github.com/googleapis/yoshi-go-test-repo/issues/1000) [#1001](https://github.com/googleapis/yoshi-go-test-repo/issues/1001)\n* **asset:** added a really cool feature ([d7d1c89](https://github.com/googleapis/yoshi-go-test-repo/commit/d7d1c890dc1526f4d62ceedad581f498195c8939))\n* **pubsublite:** start generating v1 ([1d9662c](https://github.com/googleapis/yoshi-go-test-repo/commit/1d9662cf08ab1cf3b68d95dee4dc99b7c4aac371))\n\n\n### Bug Fixes\n\n* **automl:** fixed a really bad bug ([d7d1c89](https://github.com/googleapis/yoshi-go-test-repo/commit/d7d1c890dc1526f4d62ceedad581f498195c8939))\n\nThis PR was generated with [Release Please](https://github.com/googleapis/release-please).',
'head': 'release-v0.124.0',
'base': 'master'
}

exports['labels-go-yoshi'] = {
"labels": [
"autorelease: pending"
'labels': [
'autorelease: pending'
]
}
36 changes: 26 additions & 10 deletions src/releasers/go-yoshi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class GoYoshi extends ReleasePR {
this.monorepoTags ? `${this.packageName}-` : undefined
);
let gapicPR: Commit | undefined;
let sha: null | string = null;
const commits = (
await this.commits({
sha: latestTag?.sha,
Expand All @@ -69,20 +70,29 @@ export class GoYoshi extends ReleasePR {
return false;
}
}
// Store the very first SHA returned, this represents the HEAD of the
// release being created:
if (!sha) {
sha = commit.sha;
}
// Only have a single entry of the nightly regen listed in the changelog.
// If there are more than one of these commits, append associated PR.
if (GAPIC_PR_REGEX.test(commit.message)) {
const issueRe = /(?<prefix>.*)\((?<pr>.*)\)(\n|$)/;
if (gapicPR) {
const issueRe = /.*(?<pr>\(.*\))/;
const match = commit.message.match(issueRe);
if (match?.groups?.pr) {
gapicPR.message = `${gapicPR.message} ${match.groups.pr}`;
gapicPR.message += `\nRefs ${match.groups.pr}`;
}
return false;
} else {
// Throw away the sha for nightly regens, will just append PR numbers.
commit.sha = null;
gapicPR = commit;
const match = commit.message.match(issueRe);
if (match?.groups?.pr) {
gapicPR.message = `${match.groups.prefix}\n\nRefs ${match.groups.pr}`;
}
}
}
return true;
Expand All @@ -98,11 +108,15 @@ export class GoYoshi extends ReleasePR {
latestTag
);

const changelogEntry: string = await cc.generateChangelogEntry({
version: candidate.version,
currentTag: `v${candidate.version}`,
previousTag: candidate.previousTag,
});
// "closes" is a little presumptuous, let's just indicate that the
// PR references these other commits:
const changelogEntry: string = (
await cc.generateChangelogEntry({
version: candidate.version,
currentTag: `v${candidate.version}`,
previousTag: candidate.previousTag,
})
).replace(/, closes /g, ', refs ');

// don't create a release candidate until user facing changes
// (fix, feat, BREAKING CHANGE) have been made; a CHANGELOG that's
Expand All @@ -127,10 +141,12 @@ export class GoYoshi extends ReleasePR {
packageName: this.packageName,
})
);

if (!sha) {
throw Error('no sha found for pull request');
}
await this.openPR({
sha: commits[0].sha!,
changelogEntry: `${changelogEntry}\n---\n`,
sha: sha!,
changelogEntry,
updates,
version: candidate.version,
includePackageName: this.monorepoTags,
Expand Down

0 comments on commit 6c313c1

Please sign in to comment.