diff --git a/src/github.ts b/src/github.ts index 5fe550ef0..82a57379b 100644 --- a/src/github.ts +++ b/src/github.ts @@ -471,31 +471,6 @@ export class GitHub { return refResponse.data.object.sha; } - // This looks for the most recent matching release tag on - // the branch we're configured for. - async latestTag( - prefix?: string, - preRelease = false - ): Promise { - // only look at the last 250 or so commits to find the latest tag - we - // don't want to scan the entire repository history if this repo has never - // been released - const pull = await this.findMergedReleasePR([], prefix, preRelease, 250); - if (!pull) return await this.latestTagFallback(prefix, preRelease); - - // FIXME: this assumes that the version is in the branch name - const branchName = BranchName.parse(pull.headRefName)!; - const version = branchName.getVersion()!; - const normalizedVersion = semver.valid(version)!; - - const tag = { - name: `v${normalizedVersion}`, - sha: pull.sha, - version: normalizedVersion, - } as GitHubTag; - return tag; - } - // If we can't find a release branch (a common cause of this, as an example // is that we might be dealing with the first relese), use the last semver // tag that's available on the repository: diff --git a/src/release-pr.ts b/src/release-pr.ts index 426b5a208..5a83d0c9e 100644 --- a/src/release-pr.ts +++ b/src/release-pr.ts @@ -491,4 +491,118 @@ export class ReleasePR { return this.defaultBranch; } + + /** + * Find the most recent matching release tag on the branch we're + * configured for. + * + * @param {string} prefix - Limit the release to a specific component. + * @param {boolean} preRelease - Whether or not to return pre-release + * versions. Defaults to false. + */ + async latestTag( + prefix?: string, + preRelease = false + ): Promise { + // only look at the last 250 or so commits to find the latest tag - we + // don't want to scan the entire repository history if this repo has never + // been released + const pull = await this.findMergedReleasePR([], prefix, preRelease, 250); + if (!pull) return await this.gh.latestTagFallback(prefix, preRelease); + + // TODO: shouldn't need to do this twice + const branchName = BranchName.parse(pull.headRefName)!; + const version = await this.detectReleaseVersion(pull, branchName); + const normalizedVersion = semver.valid(version)!; + + return { + name: `v${normalizedVersion}`, + sha: pull.sha, + version: normalizedVersion, + }; + } + + // The default matcher will rule out pre-releases. + /** + * Find the last merged pull request that targeted the default + * branch and looks like a release PR. + * + * @param {string[]} labels - If provided, ensure that the pull + * request has all of the specified labels + * @param {string|undefined} branchPrefix - If provided, limit + * release pull requests that contain the specified component + * @param {boolean} preRelease - Whether to include pre-release + * versions in the response. Defaults to true. + * @param {number} maxResults - Limit the number of results searched. + * Defaults to unlimited. + * @returns {MergedGitHubPR|undefined} + */ + protected async findMergedReleasePR( + labels: string[], + branchPrefix: string | undefined = undefined, + preRelease = true, + maxResults: number = Number.MAX_SAFE_INTEGER + ): Promise { + branchPrefix = branchPrefix?.endsWith('-') + ? branchPrefix.replace(/-$/, '') + : branchPrefix; + + const generator = this.gh.mergeCommitIterator(maxResults); + for await (const commitWithPullRequest of generator) { + const mergedPullRequest = commitWithPullRequest.pullRequest; + if (!mergedPullRequest) { + continue; + } + + // If labels specified, ensure the pull request has all the specified labels + if ( + labels.length > 0 && + !this.hasAllLabels(labels, mergedPullRequest.labels) + ) { + continue; + } + + const branchName = BranchName.parse(mergedPullRequest.headRefName); + if (!branchName) { + continue; + } + + // If branchPrefix is specified, ensure it is found in the branch name. + // If branchPrefix is not specified, component should also be undefined. + if (branchName.getComponent() !== branchPrefix) { + continue; + } + + const version = await this.detectReleaseVersion( + mergedPullRequest, + branchName + ); + if (!version) { + continue; + } + + // What's left by now should just be the version string. + // Check for pre-releases if needed. + if (!preRelease && version.indexOf('-') >= 0) { + continue; + } + + // Make sure we did get a valid semver. + const normalizedVersion = semver.valid(version); + if (!normalizedVersion) { + continue; + } + return mergedPullRequest; + } + + return undefined; + } + + private hasAllLabels(labelsA: string[], labelsB: string[]) { + let hasAll = true; + labelsA.forEach(label => { + if (labelsB.indexOf(label) === -1) hasAll = false; + }); + return hasAll; + } } diff --git a/src/releasers/go-yoshi.ts b/src/releasers/go-yoshi.ts index 14ec208d9..eb86ebca2 100644 --- a/src/releasers/go-yoshi.ts +++ b/src/releasers/go-yoshi.ts @@ -48,7 +48,7 @@ const REGEN_PR_REGEX = /.*auto-regenerate.*/; export class GoYoshi extends ReleasePR { protected async _run(): Promise { - const latestTag = await this.gh.latestTag( + const latestTag = await this.latestTag( this.monorepoTags ? `${this.packageName}-` : undefined, false ); diff --git a/src/releasers/java-bom.ts b/src/releasers/java-bom.ts index a83ec3f66..29b4b4040 100644 --- a/src/releasers/java-bom.ts +++ b/src/releasers/java-bom.ts @@ -74,7 +74,7 @@ export class JavaBom extends ReleasePR { this.labels = ['type: process']; } - const latestTag: GitHubTag | undefined = await this.gh.latestTag(); + const latestTag: GitHubTag | undefined = await this.latestTag(); const commits = await this.commits({ sha: latestTag ? latestTag.sha : undefined, diff --git a/src/releasers/java-yoshi.ts b/src/releasers/java-yoshi.ts index 508e3afb5..752ee6b7a 100644 --- a/src/releasers/java-yoshi.ts +++ b/src/releasers/java-yoshi.ts @@ -76,7 +76,7 @@ export class JavaYoshi extends ReleasePR { this.labels = ['type: process']; } - const latestTag: GitHubTag | undefined = await this.gh.latestTag(); + const latestTag: GitHubTag | undefined = await this.latestTag(); const commits: Commit[] = this.snapshot ? [ { @@ -321,7 +321,7 @@ export class JavaYoshi extends ReleasePR { // Override this method to detect the release version from code (if it cannot be // inferred from the release PR head branch) protected detectReleaseVersionFromTitle(title: string): string | undefined { - const pattern = /^chore\((?[^(]+)\): release ?(?.*) (?\d+\.\d+\.\d+)$/; + const pattern = /^chore\((?[^(]+)\): release ?(?.*) (?\d+\.\d+\.\d+(-\w+)?)$/; const match = title.match(pattern); if (match?.groups) { return match.groups['version']; diff --git a/src/releasers/node.ts b/src/releasers/node.ts index 085f5978d..a1e9d833b 100644 --- a/src/releasers/node.ts +++ b/src/releasers/node.ts @@ -120,7 +120,7 @@ export class Node extends ReleasePR { } protected async _run(): Promise { - const latestTag: GitHubTag | undefined = await this.gh.latestTag( + const latestTag: GitHubTag | undefined = await this.latestTag( this.monorepoTags ? `${this.packagePrefix}-` : undefined ); const commits: Commit[] = await this.commits({ diff --git a/src/releasers/ocaml.ts b/src/releasers/ocaml.ts index 2176bbcab..f45340e3e 100644 --- a/src/releasers/ocaml.ts +++ b/src/releasers/ocaml.ts @@ -43,7 +43,7 @@ const CHANGELOG_SECTIONS = [ export class OCaml extends ReleasePR { protected async _run(): Promise { - const latestTag: GitHubTag | undefined = await this.gh.latestTag( + const latestTag: GitHubTag | undefined = await this.latestTag( this.monorepoTags ? `${this.packageName}-` : undefined ); const commits: Commit[] = await this.commits({ diff --git a/src/releasers/php-yoshi.ts b/src/releasers/php-yoshi.ts index b823c6c3f..99f74d7ab 100644 --- a/src/releasers/php-yoshi.ts +++ b/src/releasers/php-yoshi.ts @@ -51,7 +51,7 @@ interface PHPYoshiBulkUpdate { export class PHPYoshi extends ReleasePR { protected async _run(): Promise { - const latestTag: GitHubTag | undefined = await this.gh.latestTag(); + const latestTag: GitHubTag | undefined = await this.latestTag(); const commits: Commit[] = await this.commits({ sha: latestTag ? latestTag.sha : undefined, }); diff --git a/src/releasers/python.ts b/src/releasers/python.ts index be530ba40..9ece665b4 100644 --- a/src/releasers/python.ts +++ b/src/releasers/python.ts @@ -131,7 +131,7 @@ export class Python extends ReleasePR { } protected async _run(): Promise { - const latestTag: GitHubTag | undefined = await this.gh.latestTag( + const latestTag: GitHubTag | undefined = await this.latestTag( this.monorepoTags ? `${this.packageName}-` : undefined ); const commits: Commit[] = await this.commits({ diff --git a/src/releasers/ruby.ts b/src/releasers/ruby.ts index 75a5b8c08..9be5861d7 100644 --- a/src/releasers/ruby.ts +++ b/src/releasers/ruby.ts @@ -39,7 +39,7 @@ export class Ruby extends ReleasePR { this.versionFile = options.versionFile; } protected async _run(): Promise { - const latestTag: GitHubTag | undefined = await this.gh.latestTag( + const latestTag: GitHubTag | undefined = await this.latestTag( this.monorepoTags ? `${this.packageName}-` : undefined, false ); diff --git a/src/releasers/rust.ts b/src/releasers/rust.ts index cee8ba2ec..984ba6335 100644 --- a/src/releasers/rust.ts +++ b/src/releasers/rust.ts @@ -37,7 +37,7 @@ export class Rust extends ReleasePR { return tagOrBranch; }; - const latestTag: GitHubTag | undefined = await this.gh.latestTag(prefix); + const latestTag: GitHubTag | undefined = await this.latestTag(prefix); const commits: Commit[] = await this.commits({ sha: latestTag ? latestTag.sha : undefined, path: this.path, diff --git a/src/releasers/simple.ts b/src/releasers/simple.ts index 83f121de1..4b4388031 100644 --- a/src/releasers/simple.ts +++ b/src/releasers/simple.ts @@ -27,7 +27,7 @@ import {VersionTxt} from '../updaters/version-txt'; export class Simple extends ReleasePR { protected async _run(): Promise { - const latestTag: GitHubTag | undefined = await this.gh.latestTag( + const latestTag: GitHubTag | undefined = await this.latestTag( this.monorepoTags ? `${this.packageName}-` : undefined ); const commits: Commit[] = await this.commits({ diff --git a/src/releasers/terraform-module.ts b/src/releasers/terraform-module.ts index 7ba5df176..efd1b9872 100644 --- a/src/releasers/terraform-module.ts +++ b/src/releasers/terraform-module.ts @@ -28,7 +28,7 @@ import {ModuleVersion} from '../updaters/terraform/module-version'; export class TerraformModule extends ReleasePR { protected async _run(): Promise { - const latestTag: GitHubTag | undefined = await this.gh.latestTag( + const latestTag: GitHubTag | undefined = await this.latestTag( this.monorepoTags ? `${this.packageName}-` : undefined ); const commits: Commit[] = await this.commits({ diff --git a/test/fixtures/latest-tag-stable-branch.json b/test/fixtures/latest-tag-stable-branch.json new file mode 100644 index 000000000..57ca01acb --- /dev/null +++ b/test/fixtures/latest-tag-stable-branch.json @@ -0,0 +1,275 @@ +{ + "repository": { + "ref": { + "target": { + "history": { + "nodes": [ + { + "associatedPullRequests": { + "nodes": [ + { + "number": 1098, + "title": "chore(master): release 1.127.1-SNAPSHOT", + "baseRefName": "master", + "headRefName": "release-please/branches/master", + "labels": { + "nodes": [ + { + "name": "api: bigquery" + }, + { + "name": "cla: yes" + }, + { + "name": "type: process" + } + ] + }, + "body": ":robot: I have created a release \\*beep\\* \\*boop\\* \n---\n### Updating meta-information for bleeding-edge SNAPSHOT release.\n---\n\n\nThis PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please)." + } + ] + }, + "sha": "7b3dd6bd71b13b2b56de9ec3d11cc07677719823", + "message": "chore(master): release 1.127.1-SNAPSHOT (#1098)\n\n:robot: I have created a release \\*beep\\* \\*boop\\* \n---\n### Updating meta-information for bleeding-edge SNAPSHOT release.\n---\n\n\nThis PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please)." + }, + { + "associatedPullRequests": { + "nodes": [ + { + "number": 1100, + "title": "chore: regenerate README", + "baseRefName": "master", + "headRefName": "autosynth-readme", + "labels": { + "nodes": [ + { + "name": "api: bigquery" + }, + { + "name": "cla: yes" + } + ] + }, + "body": "This PR was generated using Autosynth. :rainbow:\n\n\n
Log from Synthtool\n\n```\n2021-02-09 23:43:01,019 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-bigquery/.github/readme/synth.py.\nOn branch autosynth-readme\nnothing to commit, working tree clean\n2021-02-09 23:43:02,240 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata.\n\n```\n
\n\nFull log will be available here:\nhttps://source.cloud.google.com/results/invocations/018ca47c-890f-44fa-be83-c39023919e5d/targets\n\n- [ ] To automatically regenerate this PR, check this box." + } + ] + }, + "sha": "5573e5a01443af412224e1baf0dc281d4e4242d9", + "message": "chore: regenerate README (#1100)\n\nThis PR was generated using Autosynth. :rainbow:\n\n\n
Log from Synthtool\n\n```\n2021-02-09 23:43:01,019 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-bigquery/.github/readme/synth.py.\nOn branch autosynth-readme\nnothing to commit, working tree clean\n2021-02-09 23:43:02,240 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata.\n\n```\n
\n\nFull log will be available here:\nhttps://source.cloud.google.com/results/invocations/018ca47c-890f-44fa-be83-c39023919e5d/targets\n\n- [ ] To automatically regenerate this PR, check this box." + }, + { + "associatedPullRequests": { + "nodes": [ + { + "number": 1095, + "title": "deps: update dependency com.google.cloud:google-cloud-bigtable to v1.20.0", + "baseRefName": "master", + "headRefName": "renovate/com.google.cloud-google-cloud-bigtable-1.x", + "labels": { + "nodes": [ + { + "name": "api: bigquery" + }, + { + "name": "cla: yes" + } + ] + }, + "body": "[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)\n\nThis PR contains the following updates:\n\n| Package | Change | Age | Adoption | Passing | Confidence |\n|---|---|---|---|---|---|\n| [com.google.cloud:google-cloud-bigtable](https://togithub.com/googleapis/java-bigtable) | `1.19.2` -> `1.20.0` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-bigtable/1.20.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-bigtable/1.20.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-bigtable/1.20.0/compatibility-slim/1.19.2)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-bigtable/1.20.0/confidence-slim/1.19.2)](https://docs.renovatebot.com/merge-confidence/) |\n\n---\n\n### Release Notes\n\n
\ngoogleapis/java-bigtable\n\n### [`v1.20.0`](https://togithub.com/googleapis/java-bigtable/blob/master/CHANGELOG.md#​1200-httpswwwgithubcomgoogleapisjava-bigtablecomparev1192v1200-2021-02-05)\n\n[Compare Source](https://togithub.com/googleapis/java-bigtable/compare/v1.19.2...v1.20.0)\n\n##### Features\n\n- Surface the server-timing metric ([#​535](https://www.github.com/googleapis/java-bigtable/issues/535)) ([8240779](https://www.github.com/googleapis/java-bigtable/commit/8240779434a602dc8b2bf90dbe539c5d7470d850))\n\n##### Bug Fixes\n\n- fix MetricTracerTest to rebase on head ([#​581](https://www.github.com/googleapis/java-bigtable/issues/581)) ([23e97cb](https://www.github.com/googleapis/java-bigtable/commit/23e97cb308403b35fbe972b08048d0e59423e694))\n- fix MutateRowsAttemptCallable to avoid NPE in MetricTracer ([#​557](https://www.github.com/googleapis/java-bigtable/issues/557)) ([8d71020](https://www.github.com/googleapis/java-bigtable/commit/8d7102003b54757b64fd598290301d3b24fd9c29))\n- Retry \"received rst stream\" ([#​586](https://www.github.com/googleapis/java-bigtable/issues/586)) ([b09a21c](https://www.github.com/googleapis/java-bigtable/commit/b09a21c1dd1a05b68bfd3a0134089ba32dca1774))\n- update repo name ([#​615](https://www.github.com/googleapis/java-bigtable/issues/615)) ([bb3ed6d](https://www.github.com/googleapis/java-bigtable/commit/bb3ed6dcbadbd70dbd9c68152c8d93c4cefd4dcb))\n\n##### Dependencies\n\n- update dependency com.google.cloud:google-cloud-shared-dependencies to v0.17.1 ([#​590](https://www.github.com/googleapis/java-bigtable/issues/590)) ([5035ad0](https://www.github.com/googleapis/java-bigtable/commit/5035ad0db01a9247634137050698c30da29722a6))\n- update dependency com.google.cloud:google-cloud-shared-dependencies to v0.18.0 ([#​592](https://www.github.com/googleapis/java-bigtable/issues/592)) ([c58b73a](https://www.github.com/googleapis/java-bigtable/commit/c58b73a7d70c8da1581ac06d77b5e362648a0868))\n- update dependency com.google.errorprone:error_prone_annotations to v2.5.0 ([#​591](https://www.github.com/googleapis/java-bigtable/issues/591)) ([dfa4da7](https://www.github.com/googleapis/java-bigtable/commit/dfa4da75e5ac81cc941177462326f7c38f18bacd))\n- update dependency com.google.errorprone:error_prone_annotations to v2.5.1 ([#​594](https://www.github.com/googleapis/java-bigtable/issues/594)) ([ea599a1](https://www.github.com/googleapis/java-bigtable/commit/ea599a10e2e4fdbaf56c45b74fbb1ea5a708a7f2))\n\n##### Documentation\n\n- Expand hello world snippet to show how to access specific cells ([#​516](https://www.github.com/googleapis/java-bigtable/issues/516)) ([a9001a8](https://www.github.com/googleapis/java-bigtable/commit/a9001a88f338fc2acf6bc48927765f29819124ee))\n- Update stackdriver examples for tracing and stats ([#​613](https://www.github.com/googleapis/java-bigtable/issues/613)) ([3e8af74](https://www.github.com/googleapis/java-bigtable/commit/3e8af747b329f6656a410160e8da14fd8227c8fc))\n- use autogenerated readme functionality and regenerate ([#​568](https://www.github.com/googleapis/java-bigtable/issues/568)) ([844e5be](https://www.github.com/googleapis/java-bigtable/commit/844e5beb6230df6ca220935056aae7f6e73d2bc0))\n\n##### [1.19.2](https://www.github.com/googleapis/java-bigtable/compare/v1.19.1...v1.19.2) (2020-12-15)\n\n##### Dependencies\n\n- update dependency com.google.cloud:google-cloud-shared-dependencies to v0.17.0 ([#​566](https://www.github.com/googleapis/java-bigtable/issues/566)) ([7c8e32b](https://www.github.com/googleapis/java-bigtable/commit/7c8e32b33c701cdf701384ad60986bc96ec4684a))\n\n##### [1.19.1](https://www.github.com/googleapis/java-bigtable/compare/v1.19.0...v1.19.1) (2020-12-14)\n\n##### Dependencies\n\n- update dependency com.google.cloud:google-cloud-shared-dependencies to v0.16.1 ([1c4ceda](https://www.github.com/googleapis/java-bigtable/commit/1c4ceda740157569fb95f7eeb9ddc0cf780cd038))\n\n
\n\n---\n\n### Renovate configuration\n\n:date: **Schedule**: At any time (no schedule defined).\n\n:vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied.\n\n:recycle: **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.\n\n:no_bell: **Ignore**: Close this PR and you won't be reminded about this update again.\n\n---\n\n - [ ] If you want to rebase/retry this PR, check this box\n\n---\n\nThis PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-bigquery)." + } + ] + }, + "sha": "82ff3695c8f5811e3b1f52dd52ab6d743475e40c", + "message": "deps: update dependency com.google.cloud:google-cloud-bigtable to v1.20.0 (#1095)" + }, + { + "associatedPullRequests": { + "nodes": [ + { + "number": 1099, + "title": "chore(deps): update dependency com.google.cloud:google-cloud-bigquery to v1.127.0", + "baseRefName": "master", + "headRefName": "renovate/com.google.cloud-google-cloud-bigquery-1.x", + "labels": { + "nodes": [ + { + "name": "api: bigquery" + }, + { + "name": "cla: yes" + } + ] + }, + "body": "[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)\n\nThis PR contains the following updates:\n\n| Package | Change | Age | Adoption | Passing | Confidence |\n|---|---|---|---|---|---|\n| [com.google.cloud:google-cloud-bigquery](https://togithub.com/googleapis/java-bigquery) | `1.126.6` -> `1.127.0` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-bigquery/1.127.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-bigquery/1.127.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-bigquery/1.127.0/compatibility-slim/1.126.6)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-bigquery/1.127.0/confidence-slim/1.126.6)](https://docs.renovatebot.com/merge-confidence/) |\n\n---\n\n### Release Notes\n\n
\ngoogleapis/java-bigquery\n\n### [`v1.127.0`](https://togithub.com/googleapis/java-bigquery/blob/master/CHANGELOG.md#​11270-httpswwwgithubcomgoogleapisjava-bigquerycomparev11266v11270-2021-02-09)\n\n[Compare Source](https://togithub.com/googleapis/java-bigquery/compare/v1.126.6...v1.127.0)\n\n##### Features\n\n- add reservation usage in job statistics ([#​1018](https://www.github.com/googleapis/java-bigquery/issues/1018)) ([49cbb0f](https://www.github.com/googleapis/java-bigquery/commit/49cbb0f16ac3236e2f87b44570994d7235485902))\n- add support for javascript UDFs determinism level ([#​1094](https://www.github.com/googleapis/java-bigquery/issues/1094)) ([cf68d8d](https://www.github.com/googleapis/java-bigquery/commit/cf68d8dc6bf421ea9c82c27760af03dd64b24a29)), closes [#​1083](https://www.github.com/googleapis/java-bigquery/issues/1083)\n\n##### Documentation\n\n- **samples:** fix sample issue ([#​1086](https://www.github.com/googleapis/java-bigquery/issues/1086)) ([ef669df](https://www.github.com/googleapis/java-bigquery/commit/ef669df3c97981664615f0d752f8d988d08c00c9))\n- **samples:** Update region tag for create table external hive partitioning ([#​1079](https://www.github.com/googleapis/java-bigquery/issues/1079)) ([50bf783](https://www.github.com/googleapis/java-bigquery/commit/50bf7831d9a7fe40ae08894d50fd2c8ae974f05a))\n\n##### [1.126.6](https://www.github.com/googleapis/java-bigquery/compare/v1.126.5...v1.126.6) (2021-01-13)\n\n##### Dependencies\n\n- update dependency com.google.cloud:google-cloud-shared-dependencies to v0.18.0 ([#​1064](https://www.github.com/googleapis/java-bigquery/issues/1064)) ([0b7925e](https://www.github.com/googleapis/java-bigquery/commit/0b7925ef311808293f2ed9969a71414520fdd8d3))\n\n##### [1.126.5](https://www.github.com/googleapis/java-bigquery/compare/v1.126.4...v1.126.5) (2021-01-13)\n\n##### Dependencies\n\n- update dependency com.google.cloud:google-cloud-storage to v1.113.9 ([#​1061](https://www.github.com/googleapis/java-bigquery/issues/1061)) ([0644f40](https://www.github.com/googleapis/java-bigquery/commit/0644f408d4d0a80c54e78aeef8169b0e18aa8256))\n\n##### [1.126.4](https://www.github.com/googleapis/java-bigquery/compare/v1.126.3...v1.126.4) (2021-01-12)\n\n##### Dependencies\n\n- update dependency com.google.cloud:google-cloud-bigtable to v1.19.2 ([#​1035](https://www.github.com/googleapis/java-bigquery/issues/1035)) ([239975b](https://www.github.com/googleapis/java-bigquery/commit/239975b318e513c93fdf42a2699bb019089459ed))\n- update dependency com.google.cloud:google-cloud-shared-dependencies to v0.17.1 ([#​1056](https://www.github.com/googleapis/java-bigquery/issues/1056)) ([be89a1b](https://www.github.com/googleapis/java-bigquery/commit/be89a1bffcd59d0b171dde86f118714a4ba31d08))\n- update dependency com.google.cloud:google-cloud-storage to v1.113.8 ([#​1046](https://www.github.com/googleapis/java-bigquery/issues/1046)) ([c3e9348](https://www.github.com/googleapis/java-bigquery/commit/c3e934809eddfdf6e191f50acf97e8670a80865b))\n- update dependency com.google.oauth-client:google-oauth-client-jetty to v1.31.4 ([#​1055](https://www.github.com/googleapis/java-bigquery/issues/1055)) ([8dd66e6](https://www.github.com/googleapis/java-bigquery/commit/8dd66e69c78febb00aa2f8f9028817f6d4735e79))\n\n##### [1.126.3](https://www.github.com/googleapis/java-bigquery/compare/v1.126.2...v1.126.3) (2020-12-15)\n\n##### Dependencies\n\n- update dependency com.google.cloud:google-cloud-bigtable to v1.19.1 ([#​1025](https://www.github.com/googleapis/java-bigquery/issues/1025)) ([1c6e90d](https://www.github.com/googleapis/java-bigquery/commit/1c6e90d9e2fe13d99ab7fe1c9999c6050371a5d9))\n- update dependency com.google.cloud:google-cloud-shared-dependencies to v0.17.0 ([#​1026](https://www.github.com/googleapis/java-bigquery/issues/1026)) ([12e2c38](https://www.github.com/googleapis/java-bigquery/commit/12e2c382f6749c3baa54119e404725eea58da907))\n\n##### [1.126.2](https://www.github.com/googleapis/java-bigquery/compare/v1.126.1...v1.126.2) (2020-12-14)\n\n##### Documentation\n\n- **samples:** add missing region tag ([#​1014](https://www.github.com/googleapis/java-bigquery/issues/1014)) ([1999950](https://www.github.com/googleapis/java-bigquery/commit/1999950da0e784b72c4dbe749ceb56d750cea1b3))\n\n##### Dependencies\n\n- update dependency com.google.cloud:google-cloud-shared-dependencies to v0.16.1 ([#​1020](https://www.github.com/googleapis/java-bigquery/issues/1020)) ([aa52928](https://www.github.com/googleapis/java-bigquery/commit/aa5292844fc64642b32a4a823338acf8e61549b0))\n- update dependency com.google.cloud:google-cloud-storage to v1.113.6 ([#​1017](https://www.github.com/googleapis/java-bigquery/issues/1017)) ([b62e8f2](https://www.github.com/googleapis/java-bigquery/commit/b62e8f208ae4741e7ba6df41c6c90a8192f84aee))\n\n##### [1.126.1](https://www.github.com/googleapis/java-bigquery/compare/v1.126.0...v1.126.1) (2020-12-09)\n\n##### Dependencies\n\n- update dependency com.google.cloud:google-cloud-storage to v1.113.5 ([#​1007](https://www.github.com/googleapis/java-bigquery/issues/1007)) ([479ae98](https://www.github.com/googleapis/java-bigquery/commit/479ae98a22df32d257d13ef7d9aad4888ddacfdf))\n\n
\n\n---\n\n### Renovate configuration\n\n:date: **Schedule**: At any time (no schedule defined).\n\n:vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied.\n\n:recycle: **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.\n\n:no_bell: **Ignore**: Close this PR and you won't be reminded about this update again.\n\n---\n\n - [ ] If you want to rebase/retry this PR, check this box\n\n---\n\nThis PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-bigquery)." + } + ] + }, + "sha": "b98c978c0f8a484f9c4cff823dc8361b2678dc0d", + "message": "chore(deps): update dependency com.google.cloud:google-cloud-bigquery to v1.127.0 (#1099)" + }, + { + "associatedPullRequests": { + "nodes": [ + { + "number": 1090, + "title": "chore(master): release 1.127.0", + "baseRefName": "master", + "headRefName": "release-please/branches/master", + "labels": { + "nodes": [ + { + "name": "api: bigquery" + }, + { + "name": "autorelease: published" + }, + { + "name": "cla: yes" + } + ] + }, + "body": ":robot: I have created a release \\*beep\\* \\*boop\\* \n---\n## [1.127.0](https://www.github.com/googleapis/java-bigquery/compare/v1.126.6...v1.127.0) (2021-02-09)\n\n\n### Features\n\n* add reservation usage in job statistics ([#1018](https://www.github.com/googleapis/java-bigquery/issues/1018)) ([49cbb0f](https://www.github.com/googleapis/java-bigquery/commit/49cbb0f16ac3236e2f87b44570994d7235485902))\n* add support for javascript UDFs determinism level ([#1094](https://www.github.com/googleapis/java-bigquery/issues/1094)) ([cf68d8d](https://www.github.com/googleapis/java-bigquery/commit/cf68d8dc6bf421ea9c82c27760af03dd64b24a29)), closes [#1083](https://www.github.com/googleapis/java-bigquery/issues/1083)\n\n\n### Documentation\n\n* **samples:** fix sample issue ([#1086](https://www.github.com/googleapis/java-bigquery/issues/1086)) ([ef669df](https://www.github.com/googleapis/java-bigquery/commit/ef669df3c97981664615f0d752f8d988d08c00c9))\n* **samples:** Update region tag for create table external hive partitioning ([#1079](https://www.github.com/googleapis/java-bigquery/issues/1079)) ([50bf783](https://www.github.com/googleapis/java-bigquery/commit/50bf7831d9a7fe40ae08894d50fd2c8ae974f05a))\n---\n\n\nThis PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please)." + } + ] + }, + "sha": "9d8f923eedb2c02456d3f73fccca6d2e87137979", + "message": "chore(master): release 1.127.0 (#1090)\n\nCo-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>" + }, + { + "associatedPullRequests": { + "nodes": [ + { + "number": 1094, + "title": "feat: add support for javascript UDFs determinism level", + "baseRefName": "master", + "headRefName": "determinism", + "labels": { + "nodes": [ + { + "name": "api: bigquery" + }, + { + "name": "cla: yes" + } + ] + }, + "body": "Fixes #1083" + } + ] + }, + "sha": "cf68d8dc6bf421ea9c82c27760af03dd64b24a29", + "message": "feat: add support for javascript UDFs determinism level (#1094)\n\nFixes #1083" + }, + { + "associatedPullRequests": { + "nodes": [ + { + "number": 1097, + "title": "chore: regenerate README", + "baseRefName": "master", + "headRefName": "autosynth-readme", + "labels": { + "nodes": [ + { + "name": "api: bigquery" + }, + { + "name": "cla: yes" + } + ] + }, + "body": "This PR was generated using Autosynth. :rainbow:\n\n\n
Log from Synthtool\n\n```\n2021-02-09 20:18:35,801 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-bigquery/.github/readme/synth.py.\nOn branch autosynth-readme\nnothing to commit, working tree clean\n2021-02-09 20:18:36,888 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata.\n\n```\n
\n\nFull log will be available here:\nhttps://source.cloud.google.com/results/invocations/0a897e4a-b595-47b0-bd09-7deeaf714ce7/targets\n\n- [ ] To automatically regenerate this PR, check this box." + } + ] + }, + "sha": "86cba8b3252cc9f2bb470bd73bb83245cff733fb", + "message": "chore: regenerate README (#1097)\n\nThis PR was generated using Autosynth. :rainbow:\n\n\n
Log from Synthtool\n\n```\n2021-02-09 20:18:35,801 synthtool [DEBUG] > Executing /root/.cache/synthtool/java-bigquery/.github/readme/synth.py.\nOn branch autosynth-readme\nnothing to commit, working tree clean\n2021-02-09 20:18:36,888 synthtool [DEBUG] > Wrote metadata to .github/readme/synth.metadata/synth.metadata.\n\n```\n
\n\nFull log will be available here:\nhttps://source.cloud.google.com/results/invocations/0a897e4a-b595-47b0-bd09-7deeaf714ce7/targets\n\n- [ ] To automatically regenerate this PR, check this box." + }, + { + "associatedPullRequests": { + "nodes": [ + { + "number": 1096, + "title": "chore(deps): update dependency com.google.cloud:libraries-bom to v16.4.0", + "baseRefName": "master", + "headRefName": "renovate/com.google.cloud-libraries-bom-16.x", + "labels": { + "nodes": [ + { + "name": "api: bigquery" + }, + { + "name": "cla: yes" + } + ] + }, + "body": "[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)\n\nThis PR contains the following updates:\n\n| Package | Change | Age | Adoption | Passing | Confidence |\n|---|---|---|---|---|---|\n| [com.google.cloud:libraries-bom](https://togithub.com/GoogleCloudPlatform/cloud-opensource-java) | `16.3.0` -> `16.4.0` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:libraries-bom/16.4.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:libraries-bom/16.4.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:libraries-bom/16.4.0/compatibility-slim/16.3.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:libraries-bom/16.4.0/confidence-slim/16.3.0)](https://docs.renovatebot.com/merge-confidence/) |\n\n---\n\n### Renovate configuration\n\n:date: **Schedule**: At any time (no schedule defined).\n\n:vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied.\n\n:recycle: **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.\n\n:no_bell: **Ignore**: Close this PR and you won't be reminded about this update again.\n\n---\n\n - [ ] If you want to rebase/retry this PR, check this box\n\n---\n\nThis PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-bigquery)." + } + ] + }, + "sha": "2e7bd9df075bc850d818dafd4439245f11eb34ee", + "message": "chore(deps): update dependency com.google.cloud:libraries-bom to v16.4.0 (#1096)" + }, + { + "associatedPullRequests": { + "nodes": [ + { + "number": 1018, + "title": "feat: add reservation usage in job statistics", + "baseRefName": "master", + "headRefName": "reservationusage", + "labels": { + "nodes": [ + { + "name": "api: bigquery" + }, + { + "name": "cla: yes" + } + ] + }, + "body": "Fixes #1087" + } + ] + }, + "sha": "49cbb0f16ac3236e2f87b44570994d7235485902", + "message": "feat: add reservation usage in job statistics (#1018)" + }, + { + "associatedPullRequests": { + "nodes": [ + { + "number": 1092, + "title": "chore: Re-generated to pick up changes from synthtool.", + "baseRefName": "master", + "headRefName": "autosynth-synthtool", + "labels": { + "nodes": [ + { + "name": "api: bigquery" + }, + { + "name": "cla: yes" + }, + { + "name": "context: full" + } + ] + }, + "body": "This PR was generated using Autosynth. :rainbow:\n\nSynth log will be available here:\nhttps://source.cloud.google.com/results/invocations/fb5ed929-07a6-4b9c-9c01-20c1d4125a75/targets\n\n- [ ] To automatically regenerate this PR, check this box.\n\nSource-Link: https://github.com/googleapis/synthtool/commit/692715c0f23a7bb3bfbbaa300f7620ddfa8c47e5\nSource-Link: https://github.com/googleapis/synthtool/commit/27b2d4f4674840628d0b75c5941e89c12af4764f" + } + ] + }, + "sha": "24a6a3bf46fa528ca233413e47a858bb14d38f8d", + "message": "chore: Re-generated to pick up changes from synthtool. (#1092)\n\nThis PR was generated using Autosynth. :rainbow:\n\nSynth log will be available here:\nhttps://source.cloud.google.com/results/invocations/fb5ed929-07a6-4b9c-9c01-20c1d4125a75/targets\n\n- [ ] To automatically regenerate this PR, check this box.\n\nSource-Link: https://github.com/googleapis/synthtool/commit/692715c0f23a7bb3bfbbaa300f7620ddfa8c47e5\nSource-Link: https://github.com/googleapis/synthtool/commit/27b2d4f4674840628d0b75c5941e89c12af4764f" + } + ], + "pageInfo": { + "hasNextPage": false, + "endCursor": "7b3dd6bd71b13b2b56de9ec3d11cc07677719823 19" + } + } + } + } + } +} \ No newline at end of file diff --git a/test/github.ts b/test/github.ts index 9fca76e65..de791f641 100644 --- a/test/github.ts +++ b/test/github.ts @@ -274,255 +274,6 @@ describe('GitHub', () => { // Todo - not finding things from other branches }); - describe('latestTag', () => { - it('handles monorepo composite branch names properly', async () => { - const graphql = JSON.parse( - readFileSync(resolve(fixturesPath, 'latest-tag-monorepo.json'), 'utf8') - ); - req.post('/graphql').reply(200, { - data: graphql, - }); - const latestTag = await github.latestTag('complex-package_name-v1-'); - expect(latestTag!.version).to.equal('1.1.0'); - req.done(); - }); - - it('does not return monorepo composite tag, if no prefix provided', async () => { - const graphql = JSON.parse( - readFileSync(resolve(fixturesPath, 'latest-tag-monorepo.json'), 'utf8') - ); - req.post('/graphql').reply(200, { - data: graphql, - }); - const latestTag = await github.latestTag(); - expect(latestTag!.version).to.equal('1.3.0'); - req.done(); - }); - - it('returns the latest tag on the main branch, based on PR date', async () => { - const graphql = JSON.parse( - readFileSync(resolve(fixturesPath, 'latest-tag.json'), 'utf8') - ); - req.post('/graphql').reply(200, { - data: graphql, - }); - const latestTag = await github.latestTag(); - expect(latestTag!.version).to.equal('1.3.0'); - req.done(); - }); - - it('returns the latest tag on a sub branch, based on PR date', async () => { - const graphql = JSON.parse( - readFileSync( - resolve(fixturesPath, 'latest-tag-alternate-branch.json'), - 'utf8' - ) - ); - req.post('/graphql').reply(200, { - data: graphql, - }); - - // We need a special one here to set an alternate branch. - github = new GitHub({ - owner: 'fake', - repo: 'fake', - defaultBranch: 'legacy-8', - }); - - const latestTag = await github.latestTag(); - expect(latestTag!.version).to.equal('1.3.0'); - req.done(); - }); - - it('does not return pre-releases as latest tag', async () => { - const graphql = JSON.parse( - readFileSync(resolve(fixturesPath, 'latest-tag.json'), 'utf8') - ); - req.post('/graphql').reply(200, { - data: graphql, - }); - - const latestTag = await github.latestTag(); - expect(latestTag!.version).to.equal('1.3.0'); - req.done(); - }); - - it('returns pre-releases on the main branch as latest, when preRelease is true', async () => { - const graphql = JSON.parse( - readFileSync(resolve(fixturesPath, 'latest-tag.json'), 'utf8') - ); - req.post('/graphql').reply(200, { - data: graphql, - }); - const latestTag = await github.latestTag(undefined, true); - expect(latestTag!.version).to.equal('2.0.0-rc1'); - req.done(); - }); - - it('returns pre-releases on a sub branch as latest, when preRelease is true', async () => { - const graphql = JSON.parse( - readFileSync( - resolve(fixturesPath, 'latest-tag-alternate-branch.json'), - 'utf8' - ) - ); - req.post('/graphql').reply(200, { - data: graphql, - }); - - // We need a special one here to set an alternate branch. - github = new GitHub({ - owner: 'fake', - repo: 'fake', - defaultBranch: 'prerelease', - }); - const latestTag = await github.latestTag(undefined, true); - expect(latestTag!.version).to.equal('2.0.0-rc1'); - req.done(); - }); - - it('falls back to using tags, for simple case', async () => { - const graphql = JSON.parse( - readFileSync( - resolve(fixturesPath, 'latest-tag-no-commits.json'), - 'utf8' - ) - ); - req - .post('/graphql') - .reply(200, { - data: graphql, - }) - .get('/repos/fake/fake/tags?per_page=100') - .reply(200, [ - { - name: 'v1.0.0', - commit: {sha: 'abc123'}, - }, - { - name: 'v1.1.0', - commit: {sha: 'deadbeef'}, - }, - ]); - const latestTag = await github.latestTag(); - expect(latestTag!.version).to.equal('1.1.0'); - req.done(); - }); - it('falls back to using tags, when prefix is provided', async () => { - const graphql = JSON.parse( - readFileSync( - resolve(fixturesPath, 'latest-tag-no-commits.json'), - 'utf8' - ) - ); - req - .post('/graphql') - .reply(200, { - data: graphql, - }) - .get('/repos/fake/fake/tags?per_page=100') - .reply(200, [ - { - name: 'v1.0.0', - commit: {sha: 'abc123'}, - }, - { - name: 'v1.1.0', - commit: {sha: 'deadbeef'}, - }, - { - name: 'foo-v1.9.0', - commit: {sha: 'deadbeef'}, - }, - { - name: 'v1.2.0', - commit: {sha: 'deadbeef'}, - }, - ]); - const latestTag = await github.latestTag('foo-'); - expect(latestTag!.version).to.equal('1.9.0'); - req.done(); - }); - it('allows for "@" rather than "-" when fallback used', async () => { - const graphql = JSON.parse( - readFileSync( - resolve(fixturesPath, 'latest-tag-no-commits.json'), - 'utf8' - ) - ); - req - .post('/graphql') - .reply(200, { - data: graphql, - }) - .get('/repos/fake/fake/tags?per_page=100') - .reply(200, [ - { - name: 'v1.0.0', - commit: {sha: 'abc123'}, - }, - { - name: 'v1.1.0', - commit: {sha: 'deadbeef'}, - }, - { - name: 'foo@v1.9.0', - commit: {sha: 'dead'}, - }, - { - name: 'v1.2.0', - commit: {sha: 'beef'}, - }, - { - name: 'foo@v2.1.0', - commit: {sha: '123abc'}, - }, - ]); - const latestTag = await github.latestTag('foo-'); - expect(latestTag!.version).to.equal('2.1.0'); - req.done(); - }); - it('allows for "/" rather than "-" when fallback used', async () => { - const graphql = JSON.parse( - readFileSync( - resolve(fixturesPath, 'latest-tag-no-commits.json'), - 'utf8' - ) - ); - req - .post('/graphql') - .reply(200, { - data: graphql, - }) - .get('/repos/fake/fake/tags?per_page=100') - .reply(200, [ - { - name: 'v1.0.0', - commit: {sha: 'abc123'}, - }, - { - name: 'v1.1.0', - commit: {sha: 'deadbeef'}, - }, - { - name: 'foo/v2.3.0', - commit: {sha: 'dead'}, - }, - { - name: 'v1.2.0', - commit: {sha: 'beef'}, - }, - { - name: 'foo/v2.1.0', - commit: {sha: '123abc'}, - }, - ]); - const latestTag = await github.latestTag('foo-'); - expect(latestTag!.version).to.equal('2.3.0'); - req.done(); - }); - }); - describe('getFileContents', () => { it('should support Github Data API in case of a big file', async () => { const simpleAPIResponse = JSON.parse( @@ -578,6 +329,7 @@ describe('GitHub', () => { req.done(); }); }); + describe('getFileContentsWithSimpleAPI', () => { const setupReq = (ref: string) => { req @@ -928,4 +680,102 @@ describe('GitHub', () => { expect(thrown).to.be.true; }); }); + + describe('latestTagFallback', () => { + it('falls back to using tags, for simple case', async () => { + req.get('/repos/fake/fake/tags?per_page=100').reply(200, [ + { + name: 'v1.0.0', + commit: {sha: 'abc123'}, + }, + { + name: 'v1.1.0', + commit: {sha: 'deadbeef'}, + }, + ]); + const latestTag = await github.latestTagFallback(); + expect(latestTag!.version).to.equal('1.1.0'); + req.done(); + }); + + it('falls back to using tags, when prefix is provided', async () => { + req.get('/repos/fake/fake/tags?per_page=100').reply(200, [ + { + name: 'v1.0.0', + commit: {sha: 'abc123'}, + }, + { + name: 'v1.1.0', + commit: {sha: 'deadbeef'}, + }, + { + name: 'foo-v1.9.0', + commit: {sha: 'deadbeef'}, + }, + { + name: 'v1.2.0', + commit: {sha: 'deadbeef'}, + }, + ]); + const latestTag = await github.latestTagFallback('foo-'); + expect(latestTag!.version).to.equal('1.9.0'); + req.done(); + }); + + it('allows for "@" rather than "-" when fallback used', async () => { + req.get('/repos/fake/fake/tags?per_page=100').reply(200, [ + { + name: 'v1.0.0', + commit: {sha: 'abc123'}, + }, + { + name: 'v1.1.0', + commit: {sha: 'deadbeef'}, + }, + { + name: 'foo@v1.9.0', + commit: {sha: 'dead'}, + }, + { + name: 'v1.2.0', + commit: {sha: 'beef'}, + }, + { + name: 'foo@v2.1.0', + commit: {sha: '123abc'}, + }, + ]); + const latestTag = await github.latestTagFallback('foo-'); + expect(latestTag!.version).to.equal('2.1.0'); + req.done(); + }); + + it('allows for "/" rather than "-" when fallback used', async () => { + req.get('/repos/fake/fake/tags?per_page=100').reply(200, [ + { + name: 'v1.0.0', + commit: {sha: 'abc123'}, + }, + { + name: 'v1.1.0', + commit: {sha: 'deadbeef'}, + }, + { + name: 'foo/v2.3.0', + commit: {sha: 'dead'}, + }, + { + name: 'v1.2.0', + commit: {sha: 'beef'}, + }, + { + name: 'foo/v2.1.0', + commit: {sha: '123abc'}, + }, + ]); + const latestTag = await github.latestTagFallback('foo-'); + expect(latestTag!.version).to.equal('2.3.0'); + req.done(); + }); + }); }); diff --git a/test/release-pr.ts b/test/release-pr.ts index 5d8abeb67..f28fb204c 100644 --- a/test/release-pr.ts +++ b/test/release-pr.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import {describe, it, afterEach} from 'mocha'; +import {describe, it, afterEach, beforeEach} from 'mocha'; import {expect} from 'chai'; import * as nock from 'nock'; nock.disableNetConnect(); @@ -22,8 +22,11 @@ import {GitHub, GitHubTag, GitHubPR} from '../src/github'; import {ReleaseCandidate, ReleasePR, OpenPROptions} from '../src/release-pr'; import * as sinon from 'sinon'; import {Node} from '../src/releasers/node'; +import {readFileSync} from 'fs'; +import {resolve} from 'path'; const sandbox = sinon.createSandbox(); +const fixturesPath = './test/fixtures'; class TestableReleasePR extends Node { openPROpts?: GitHubPR; @@ -239,4 +242,129 @@ describe('Release-PR', () => { }); }); }); + + describe('latestTag', () => { + let req: nock.Scope; + let releasePR: ReleasePR; + + beforeEach(() => { + req = nock('https://api.github.com/'); + releasePR = new ReleasePR({ + repoUrl: 'fake/fake', + apiUrl: 'https://api.github.com', + releaseType: 'base', + }); + + sandbox.stub(releasePR.gh, 'getDefaultBranch').resolves('main'); + }); + + it('handles monorepo composite branch names properly', async () => { + const graphql = JSON.parse( + readFileSync(resolve(fixturesPath, 'latest-tag-monorepo.json'), 'utf8') + ); + req.post('/graphql').reply(200, { + data: graphql, + }); + const latestTag = await releasePR.latestTag('complex-package_name-v1-'); + expect(latestTag!.version).to.equal('1.1.0'); + req.done(); + }); + + it('does not return monorepo composite tag, if no prefix provided', async () => { + const graphql = JSON.parse( + readFileSync(resolve(fixturesPath, 'latest-tag-monorepo.json'), 'utf8') + ); + req.post('/graphql').reply(200, { + data: graphql, + }); + const latestTag = await releasePR.latestTag(); + expect(latestTag!.version).to.equal('1.3.0'); + req.done(); + }); + + it('returns the latest tag on the main branch, based on PR date', async () => { + const graphql = JSON.parse( + readFileSync(resolve(fixturesPath, 'latest-tag.json'), 'utf8') + ); + req.post('/graphql').reply(200, { + data: graphql, + }); + const latestTag = await releasePR.latestTag(); + expect(latestTag!.version).to.equal('1.3.0'); + req.done(); + }); + + it('returns the latest tag on a sub branch, based on PR date', async () => { + const graphql = JSON.parse( + readFileSync( + resolve(fixturesPath, 'latest-tag-alternate-branch.json'), + 'utf8' + ) + ); + req.post('/graphql').reply(200, { + data: graphql, + }); + + // We need a special one here to set an alternate branch. + releasePR = new ReleasePR({ + repoUrl: 'fake/fake', + apiUrl: 'https://api.github.com', + releaseType: 'base', + defaultBranch: 'legacy-8', + }); + + const latestTag = await releasePR.latestTag(); + expect(latestTag!.version).to.equal('1.3.0'); + req.done(); + }); + + it('does not return pre-releases as latest tag', async () => { + const graphql = JSON.parse( + readFileSync(resolve(fixturesPath, 'latest-tag.json'), 'utf8') + ); + req.post('/graphql').reply(200, { + data: graphql, + }); + + const latestTag = await releasePR.latestTag(); + expect(latestTag!.version).to.equal('1.3.0'); + req.done(); + }); + + it('returns pre-releases on the main branch as latest, when preRelease is true', async () => { + const graphql = JSON.parse( + readFileSync(resolve(fixturesPath, 'latest-tag.json'), 'utf8') + ); + req.post('/graphql').reply(200, { + data: graphql, + }); + const latestTag = await releasePR.latestTag(undefined, true); + expect(latestTag!.version).to.equal('2.0.0-rc1'); + req.done(); + }); + + it('returns pre-releases on a sub branch as latest, when preRelease is true', async () => { + const graphql = JSON.parse( + readFileSync( + resolve(fixturesPath, 'latest-tag-alternate-branch.json'), + 'utf8' + ) + ); + req.post('/graphql').reply(200, { + data: graphql, + }); + + // We need a special one here to set an alternate branch. + releasePR = new ReleasePR({ + repoUrl: 'fake/fake', + apiUrl: 'https://api.github.com', + releaseType: 'base', + defaultBranch: 'prerelease', + }); + + const latestTag = await releasePR.latestTag(undefined, true); + expect(latestTag!.version).to.equal('2.0.0-rc1'); + req.done(); + }); + }); }); diff --git a/test/releasers/java-bom.ts b/test/releasers/java-bom.ts index d84c9e4fa..066e796a9 100644 --- a/test/releasers/java-bom.ts +++ b/test/releasers/java-bom.ts @@ -57,7 +57,7 @@ describe('JavaBom', () => { .returns(Promise.resolve(undefined)); // Indicates that there are no PRs currently waiting to be released: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ name: 'v0.123.4', sha: 'abc123', @@ -153,7 +153,7 @@ describe('JavaBom', () => { .returns(Promise.resolve(undefined)); // Indicates that there are no PRs currently waiting to be released: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ name: 'v0.123.4', sha: 'abc123', @@ -285,7 +285,7 @@ describe('JavaBom', () => { .returns(Promise.resolve(undefined)); // Indicates that there are no PRs currently waiting to be released: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ name: 'v0.123.4', sha: 'abc123', @@ -380,7 +380,7 @@ describe('JavaBom', () => { .returns(Promise.resolve(undefined)); // Indicates that there are no PRs currently waiting to be released: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ name: 'v0.123.4', sha: 'abc123', diff --git a/test/releasers/java-yoshi.ts b/test/releasers/java-yoshi.ts index 02627f030..55fe0ef67 100644 --- a/test/releasers/java-yoshi.ts +++ b/test/releasers/java-yoshi.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import {describe, it, afterEach} from 'mocha'; +import {describe, it, afterEach, beforeEach} from 'mocha'; import * as nock from 'nock'; nock.disableNetConnect(); @@ -24,6 +24,9 @@ import {GitHubFileContents} from '../../src/github'; import {expect} from 'chai'; import {buildGitHubFileContent} from './utils'; import {buildMockCommit} from '../helpers'; +import {readFileSync} from 'fs'; +import {resolve} from 'path'; +import {ReleasePR} from '../../src/release-pr'; const sandbox = sinon.createSandbox(); @@ -61,7 +64,7 @@ describe('JavaYoshi', () => { .stub(releasePR.gh, 'findMergedReleasePR') .returns(Promise.resolve(undefined)); - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ name: 'v0.20.3', sha: 'abc123', @@ -163,7 +166,7 @@ describe('JavaYoshi', () => { .returns(Promise.resolve(undefined)); // Indicates that there are no PRs currently waiting to be released: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ name: 'v0.20.3', sha: 'abc123', @@ -261,7 +264,7 @@ describe('JavaYoshi', () => { .returns(Promise.resolve(undefined)); // Indicates that there are no PRs currently waiting to be released: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ name: 'v0.20.3', sha: 'abc123', @@ -390,7 +393,7 @@ describe('JavaYoshi', () => { .returns(Promise.resolve(undefined)); // Indicates that there are no PRs currently waiting to be released: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ name: 'v0.20.3', sha: 'abc123', @@ -487,7 +490,7 @@ describe('JavaYoshi', () => { .returns(Promise.resolve(undefined)); // Indicates that there are no PRs currently waiting to be released: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ name: 'v0.20.3', sha: 'abc123', @@ -579,7 +582,7 @@ describe('JavaYoshi', () => { .returns(Promise.resolve(undefined)); // Indicates that there are no PRs currently waiting to be released: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ name: 'v0.20.3', sha: 'abc123', @@ -658,4 +661,51 @@ describe('JavaYoshi', () => { ) ); }); + + describe('latestTag', () => { + let req: nock.Scope; + let releasePR: ReleasePR; + + beforeEach(() => { + req = nock('https://api.github.com/'); + releasePR = new JavaYoshi({ + repoUrl: 'googleapis/java-trace', + releaseType: 'java-yoshi', + // not actually used by this type of repo. + packageName: 'java-trace', + apiUrl: 'https://api.github.com', + }); + + sandbox.stub(releasePR.gh, 'getDefaultBranch').resolves('main'); + }); + it('returns a stable branch pull request', async () => { + const graphql = JSON.parse( + readFileSync( + resolve('./test/fixtures', 'latest-tag-stable-branch.json'), + 'utf8' + ) + ); + req.post('/graphql').reply(200, { + data: graphql, + }); + const latestTag = await releasePR.latestTag(); + expect(latestTag!.version).to.equal('1.127.0'); + req.done(); + }); + + it('returns a prerelease tag stable branch', async () => { + const graphql = JSON.parse( + readFileSync( + resolve('./test/fixtures', 'latest-tag-stable-branch.json'), + 'utf8' + ) + ); + req.post('/graphql').reply(200, { + data: graphql, + }); + const latestTag = await releasePR.latestTag(undefined, true); + expect(latestTag!.version).to.equal('1.127.1-SNAPSHOT'); + req.done(); + }); + }); }); diff --git a/test/releasers/node.ts b/test/releasers/node.ts index 10507c487..caa8ba1d0 100644 --- a/test/releasers/node.ts +++ b/test/releasers/node.ts @@ -58,7 +58,7 @@ function mockRequest(releasePR: Node) { .stub(releasePR.gh, 'findMergedReleasePR') .returns(Promise.resolve(undefined)); - sandbox.stub(releasePR.gh, 'latestTag').resolves(LATEST_TAG); + sandbox.stub(releasePR, 'latestTag').resolves(LATEST_TAG); sandbox.stub(releasePR.gh, 'commitsSinceSha').resolves(COMMITS); diff --git a/test/releasers/ocaml.ts b/test/releasers/ocaml.ts index fed67c2ee..3b22750d2 100644 --- a/test/releasers/ocaml.ts +++ b/test/releasers/ocaml.ts @@ -60,7 +60,7 @@ describe('OCaml', () => { .returns(Promise.resolve(undefined)); // Return latest tag used to determine next version #: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ sha: 'da6e52d956c1e35d19e75e0f2fdba439739ba364', name: 'v0.5.0', @@ -170,7 +170,7 @@ describe('OCaml', () => { .returns(Promise.resolve(undefined)); // Return latest tag used to determine next version #: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ sha: 'da6e52d956c1e35d19e75e0f2fdba439739ba364', name: 'v0.5.0', diff --git a/test/releasers/php-yoshi.ts b/test/releasers/php-yoshi.ts index 7d592a74e..6455f457e 100644 --- a/test/releasers/php-yoshi.ts +++ b/test/releasers/php-yoshi.ts @@ -58,7 +58,7 @@ describe('PHPYoshi', () => { .stub(releasePR.gh, 'findMergedReleasePR') .returns(Promise.resolve(undefined)); - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ name: 'v0.20.3', sha: 'bf69d0f204474b88b3f8b5a72a392129d16a3929', diff --git a/test/releasers/python.ts b/test/releasers/python.ts index 64c59c37a..506a981af 100644 --- a/test/releasers/python.ts +++ b/test/releasers/python.ts @@ -56,7 +56,7 @@ function stubGithub(releasePR: Python, versionFiles: string[] = []) { sandbox .stub(releasePR.gh, 'findMergedReleasePR') .returns(Promise.resolve(undefined)); - sandbox.stub(releasePR.gh, 'latestTag').resolves(LATEST_TAG); + sandbox.stub(releasePR, 'latestTag').resolves(LATEST_TAG); sandbox.stub(releasePR.gh, 'commitsSinceSha').resolves(COMMITS); sandbox.stub(releasePR.gh, 'addLabels'); sandbox.stub(releasePR.gh, 'findFilesByFilename').resolves(versionFiles); diff --git a/test/releasers/rust.ts b/test/releasers/rust.ts index 4361cb199..32248064e 100644 --- a/test/releasers/rust.ts +++ b/test/releasers/rust.ts @@ -49,7 +49,7 @@ describe('Rust', () => { .returns(Promise.resolve(undefined)); // Return latest tag used to determine next version #: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ sha: 'da6e52d956c1e35d19e75e0f2fdba439739ba364', name: 'v0.123.4', @@ -150,7 +150,7 @@ describe('Rust', () => { .returns(Promise.resolve(undefined)); // Return latest tag used to determine next version #: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ sha: 'da6e52d956c1e35d19e75e0f2fdba439739ba364', name: 'v0.123.4', diff --git a/test/releasers/simple.ts b/test/releasers/simple.ts index 4a5fbbc9c..f77d32896 100644 --- a/test/releasers/simple.ts +++ b/test/releasers/simple.ts @@ -46,7 +46,7 @@ describe('Simple', () => { .returns(Promise.resolve(undefined)); // Return latest tag used to determine next version #: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ sha: 'da6e52d956c1e35d19e75e0f2fdba439739ba364', name: 'v0.123.4', diff --git a/test/releasers/terraform-module.ts b/test/releasers/terraform-module.ts index 5badc3a5c..88ab2c08d 100644 --- a/test/releasers/terraform-module.ts +++ b/test/releasers/terraform-module.ts @@ -106,7 +106,7 @@ describe('terraform-module', () => { .returns(Promise.resolve(test.findVersionFiles)); // Return latest tag used to determine next version #: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ sha: 'da6e52d956c1e35d19e75e0f2fdba439739ba364', name: 'v2.1.0', diff --git a/test/releasers/yoshi-go.ts b/test/releasers/yoshi-go.ts index abebd7810..4982049f3 100644 --- a/test/releasers/yoshi-go.ts +++ b/test/releasers/yoshi-go.ts @@ -66,7 +66,7 @@ describe('YoshiGo', () => { .stub(releasePR.gh, 'findMergedReleasePR') .returns(Promise.resolve(undefined)); - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ name: 'v0.123.4', sha: 'da6e52d956c1e35d19e75e0f2fdba439739ba364', @@ -137,7 +137,7 @@ describe('YoshiGo', () => { .returns(Promise.resolve(undefined)); // Return latest tag used to determine next version #: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ sha: 'da6e52d956c1e35d19e75e0f2fdba439739ba364', name: 'v0.123.4', @@ -224,7 +224,7 @@ describe('YoshiGo', () => { .returns(Promise.resolve(undefined)); // Return latest tag used to determine next version #: - sandbox.stub(releasePR.gh, 'latestTag').returns( + sandbox.stub(releasePR, 'latestTag').returns( Promise.resolve({ sha: 'da6e52d956c1e35d19e75e0f2fdba439739ba364', name: 'v0.123.4',