Skip to content

Commit

Permalink
feat(go): support pseudo context aware commits
Browse files Browse the repository at this point in the history
Go regen PRs now enumerate all of the changes they contain. This
adds logic to parse those changes so individual entries appear in
the changelog. Example PR: googleapis/google-cloud-go#3391
  • Loading branch information
codyoss committed Dec 15, 2020
1 parent 9ba60ee commit 2465324
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
5 changes: 4 additions & 1 deletion __snapshots__/yoshi-go.js
Expand Up @@ -14,13 +14,16 @@ filename: CHANGES.md
### Features
* **all:** auto-regenerate gapics , refs [#1000](https://www.github.com/googleapis/google-cloud-go/issues/1000) [#1001](https://www.github.com/googleapis/google-cloud-go/issues/1001)
* **asset:** added a really cool feature ([d7d1c89](https://www.github.com/googleapis/google-cloud-go/commit/d7d1c890dc1526f4d62ceedad581f498195c8939))
* **container:** contained it ([1f9663c](https://www.github.com/googleapis/google-cloud-go/commit/1f9663cf08ab1cf3b68d95dee4dc99b7c4aac371))
* **oslogin:** a critical feature ([2f9663c](https://www.github.com/googleapis/google-cloud-go/commit/2f9663cf08ab1cf3b68d95dee4dc99b7c4aac372))
### Bug Fixes
* **automl:** fixed a really bad bug ([d7d1c89](https://www.github.com/googleapis/google-cloud-go/commit/d7d1c890dc1526f4d62ceedad581f498195c8939))
* **dialogflow:** fixed the cadence ([1f9663c](https://www.github.com/googleapis/google-cloud-go/commit/1f9663cf08ab1cf3b68d95dee4dc99b7c4aac371))
* **securitycenter:** security things ([2f9663c](https://www.github.com/googleapis/google-cloud-go/commit/2f9663cf08ab1cf3b68d95dee4dc99b7c4aac372))
`

Expand Down
71 changes: 50 additions & 21 deletions src/releasers/go-yoshi.ts
Expand Up @@ -62,6 +62,7 @@ export class GoYoshi extends ReleasePR {
const [_owner, repo] = parseGithubRepoUrl(this.repoUrl);
let regenPR: Commit | undefined;
let sha: null | string = null;
const parsedCommits: Commit[] = [];
const commits = (
await this.commits({
sha: latestTag?.sha,
Expand Down Expand Up @@ -101,29 +102,36 @@ export class GoYoshi extends ReleasePR {
sha = commit.sha;
}

if (this.isMultiClientRepo(repo) && REGEN_PR_REGEX.test(commit.message)) {
// 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.
const issueRe = /(?<prefix>.*)\((?<pr>.*)\)(\n|$)/;
if (regenPR) {
const match = commit.message.match(issueRe);
if (match?.groups?.pr) {
regenPR.message += `\nRefs ${match.groups.pr}`;
}
if (REGEN_PR_REGEX.test(commit.message)) {
if (this.isGapicRepo(repo)) {
this.parseCommits(parsedCommits, commit);
// Throw away the regen PR itself as individual updates will be listed.
return false;
} else {
// Throw away the sha for nightly regens, will just append PR numbers.
commit.sha = null;
regenPR = commit;

const match = commit.message.match(issueRe);
if (match?.groups?.pr) {
regenPR.message = `${match.groups.prefix}\n\nRefs ${match.groups.pr}`;
} else if (repo === 'google-api-go-client') {
// 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.
const issueRe = /(?<prefix>.*)\((?<pr>.*)\)(\n|$)/;
if (regenPR) {
const match = commit.message.match(issueRe);
if (match?.groups?.pr) {
regenPR.message += `\nRefs ${match.groups.pr}`;
}
return false;
} else {
// Throw away the sha for nightly regens, will just append PR numbers.
commit.sha = null;
regenPR = commit;

const match = commit.message.match(issueRe);
if (match?.groups?.pr) {
regenPR.message = `${match.groups.prefix}\n\nRefs ${match.groups.pr}`;
}
}
}
}
return true;
});
commits.push(...parsedCommits);
const cc = new ConventionalCommits({
commits: commits,
githubRepoUrl: this.repoUrl,
Expand Down Expand Up @@ -183,10 +191,6 @@ export class GoYoshi extends ReleasePR {
return repo === 'google-cloud-go';
}

private isMultiClientRepo(repo: string): boolean {
return repo === 'google-cloud-go' || repo === 'google-api-go-client';
}

protected async coerceReleaseCandidate(
cc: ConventionalCommits,
latestTag: GitHubTag | undefined
Expand All @@ -207,4 +211,29 @@ export class GoYoshi extends ReleasePR {
static tagSeparator(): string {
return '/';
}

// parseCommits breaks down the nightly regen PR to look like individual
// commits for the release notes.
private parseCommits(commits: Commit[], commit: Commit) {
const msg = commit.message;
const splitMsg = msg.split('\n\nChanges:');
if (splitMsg.length !== 2) {
return;
}
const changes = splitMsg[1].split('\n-');
for (const change of changes) {
if (change === '') {
continue;
}
const commitMsgParts = change.split('\n\n');
if (commitMsgParts.length < 2) {
continue;
}
commits.push({
message: commitMsgParts[0],
sha: commit.sha,
files: commit.files,
});
}
}
}
4 changes: 2 additions & 2 deletions test/releasers/fixtures/yoshi-go/cloud-go-commits.json
Expand Up @@ -141,7 +141,7 @@
},
{
"node": {
"message": "feat(all): auto-regenerate gapics (#1000)",
"message": "feat(all): auto-regenerate gapics (#1000)\n\nCommit Body\n\nChanges:\n-feat(oslogin): a critical feature\n\nPiperOrigin-RevId: 9999999\nSource-Link: somewhere\n\n-chore(oslogin): a random chore\n\nPiperOrigin-RevId: 9999999\nSource-Link: somewhere\n\n-fix(securitycenter): security things\n\nPiperOrigin-RevId: 9999999\nSource-Link: somewhere\n\n",
"oid": "2f9663cf08ab1cf3b68d95dee4dc99b7c4aac372",
"associatedPullRequests": {
"edges": [
Expand All @@ -168,7 +168,7 @@
},
{
"node": {
"message": "feat(all): auto-regenerate gapics (#1001)\n\nCommit Body",
"message": "feat(all): auto-regenerate gapics (#1001)\n\nCommit Body\n\nChanges:\n-chore(trace): traced lines\n\nPiperOrigin-RevId: 9999999\nSource-Link: somewhere\n\n-feat(container): contained it\n\nPiperOrigin-RevId: 9999999\nSource-Link: somewhere\n\n-fix(dialogflow): fixed the cadence\n\nPiperOrigin-RevId: 9999999\nSource-Link: somewhere\n\n",
"oid": "1f9663cf08ab1cf3b68d95dee4dc99b7c4aac371",
"associatedPullRequests": {
"edges": [
Expand Down

0 comments on commit 2465324

Please sign in to comment.