From 2465324e371540ea4c8e8e3737a2829c7d086c91 Mon Sep 17 00:00:00 2001 From: Cody Oss Date: Tue, 15 Dec 2020 10:38:26 -0700 Subject: [PATCH] feat(go): support pseudo context aware commits 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 --- __snapshots__/yoshi-go.js | 5 +- src/releasers/go-yoshi.ts | 71 +++++++++++++------ .../fixtures/yoshi-go/cloud-go-commits.json | 4 +- 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/__snapshots__/yoshi-go.js b/__snapshots__/yoshi-go.js index 77d518417..e6c05d4a2 100644 --- a/__snapshots__/yoshi-go.js +++ b/__snapshots__/yoshi-go.js @@ -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)) ` diff --git a/src/releasers/go-yoshi.ts b/src/releasers/go-yoshi.ts index 19b242f38..e74c154cf 100644 --- a/src/releasers/go-yoshi.ts +++ b/src/releasers/go-yoshi.ts @@ -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, @@ -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 = /(?.*)\((?.*)\)(\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 = /(?.*)\((?.*)\)(\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, @@ -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 @@ -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, + }); + } + } } diff --git a/test/releasers/fixtures/yoshi-go/cloud-go-commits.json b/test/releasers/fixtures/yoshi-go/cloud-go-commits.json index d7755d2d1..7304929bf 100644 --- a/test/releasers/fixtures/yoshi-go/cloud-go-commits.json +++ b/test/releasers/fixtures/yoshi-go/cloud-go-commits.json @@ -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": [ @@ -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": [