Skip to content

Commit

Permalink
feat: detect default branch (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Jun 15, 2020
1 parent bec98a3 commit 301a08a
Show file tree
Hide file tree
Showing 17 changed files with 864 additions and 213 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -109,6 +109,7 @@ release-please release-pr --package-name=@google-cloud/firestore" \
| `--package-name` | is the name of the package to publish to publish to an upstream registry such as npm. |
| `--repo-url` | is the URL of the repository on GitHub. |
| `--token` | a token with write access to `--repo-url`. |
| `--default-branch`| branch to open pull release PR against (detected by default). |
### Creating a release on GitHub
Expand Down
61 changes: 18 additions & 43 deletions __snapshots__/java-bom.js
Expand Up @@ -819,21 +819,12 @@ exports['pom-bom'] = `
</project>
`

exports['PR body-bom'] = `
:robot: I have created a release \\*beep\\* \\*boop\\*
---
## [0.124.0](https://www.github.com/googleapis/java-cloud-bom/compare/0.123.4...v0.124.0)
### Dependencies
* update dependency com.google.cloud:google-cloud-spanner to v1.50.0 ([1f9663c](https://www.github.com/googleapis/java-cloud-bom/commit/1f9663cf08ab1cf3b68d95dee4dc99b7c4aac373))
* update dependency com.google.cloud:google-cloud-storage to v1.120.0 ([fcd1c89](https://www.github.com/googleapis/java-cloud-bom/commit/fcd1c890dc1526f4d62ceedad561f498195c8939))
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please).
`
exports['PR body-bom'] = {
'title': 'chore: release 0.124.0',
'body': ':robot: I have created a release \\*beep\\* \\*boop\\* \n---\n## [0.124.0](https://www.github.com/googleapis/java-cloud-bom/compare/0.123.4...v0.124.0) \n\n\n### Dependencies\n\n* update dependency com.google.cloud:google-cloud-spanner to v1.50.0 ([1f9663c](https://www.github.com/googleapis/java-cloud-bom/commit/1f9663cf08ab1cf3b68d95dee4dc99b7c4aac373))\n* update dependency com.google.cloud:google-cloud-storage to v1.120.0 ([fcd1c89](https://www.github.com/googleapis/java-cloud-bom/commit/fcd1c890dc1526f4d62ceedad561f498195c8939))\n---\n\n\nThis PR was generated with [Release Please](https://github.com/googleapis/release-please).',
'head': 'release-v0.124.0',
'base': 'main'
}

exports['labels-bom'] = {
'labels': [
Expand Down Expand Up @@ -1603,15 +1594,12 @@ exports['pom-bom-snapshot'] = `
</project>
`

exports['PR body-bom-snapshot'] = `
:robot: I have created a release \\*beep\\* \\*boop\\*
---
### Updating meta-information for bleeding-edge SNAPSHOT release.
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please).
`
exports['PR body-bom-snapshot'] = {
'title': 'chore: release 0.123.5-SNAPSHOT',
'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).',
'head': 'release-v0.123.5-SNAPSHOT',
'base': 'main'
}

exports['labels-bom-snapshot'] = {
'labels': [
Expand Down Expand Up @@ -2444,25 +2432,12 @@ exports['pom-bom-feature'] = `
</project>
`

exports['PR body-bom-feature'] = `
:robot: I have created a release \\*beep\\* \\*boop\\*
---
## [0.124.0](https://www.github.com/googleapis/java-cloud-bom/compare/0.123.4...v0.124.0)
### Features
* import google-cloud-game-servers ([1f9663c](https://www.github.com/googleapis/java-cloud-bom/commit/1f9663cf08ab1cf3b68d95dee4dc99b7c4aac373))
### Dependencies
* update dependency com.google.cloud:google-cloud-storage to v1.120.1 ([fcd1c89](https://www.github.com/googleapis/java-cloud-bom/commit/fcd1c890dc1526f4d62ceedad561f498195c8939))
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please).
`
exports['PR body-bom-feature'] = {
'title': 'chore: release 0.124.0',
'body': ':robot: I have created a release \\*beep\\* \\*boop\\* \n---\n## [0.124.0](https://www.github.com/googleapis/java-cloud-bom/compare/0.123.4...v0.124.0) \n\n\n### Features\n\n* import google-cloud-game-servers ([1f9663c](https://www.github.com/googleapis/java-cloud-bom/commit/1f9663cf08ab1cf3b68d95dee4dc99b7c4aac373))\n\n\n### Dependencies\n\n* update dependency com.google.cloud:google-cloud-storage to v1.120.1 ([fcd1c89](https://www.github.com/googleapis/java-cloud-bom/commit/fcd1c890dc1526f4d62ceedad561f498195c8939))\n---\n\n\nThis PR was generated with [Release Please](https://github.com/googleapis/release-please).',
'head': 'release-v0.124.0',
'base': 'master'
}

exports['labels-bom-feature'] = {
'labels': [
Expand Down
35 changes: 12 additions & 23 deletions __snapshots__/java-yoshi.js
Expand Up @@ -476,20 +476,12 @@ exports['pom'] = `
</project>
`

exports['PR body'] = `
:robot: I have created a release \\*beep\\* \\*boop\\*
---
### [0.20.4](https://www.github.com/googleapis/java-trace/compare/v0.20.3...v0.20.4)
### Bug Fixes
* Fix declared dependencies from merge issue ([#291](https://www.github.com/googleapis/java-trace/issues/291)) ([35abf13](https://www.github.com/googleapis/java-trace/commit/35abf13fa8acb3988aa086f3eb23f5ce1483cc5d))
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please).
`
exports['PR body'] = {
'title': 'chore: release 0.20.4',
'body': ':robot: I have created a release \\*beep\\* \\*boop\\* \n---\n### [0.20.4](https://www.github.com/googleapis/java-trace/compare/v0.20.3...v0.20.4) \n\n\n### Bug Fixes\n\n* Fix declared dependencies from merge issue ([#291](https://www.github.com/googleapis/java-trace/issues/291)) ([35abf13](https://www.github.com/googleapis/java-trace/commit/35abf13fa8acb3988aa086f3eb23f5ce1483cc5d))\n---\n\n\nThis PR was generated with [Release Please](https://github.com/googleapis/release-please).',
'head': 'release-v0.20.4',
'base': 'master'
}

exports['labels'] = {
'labels': [
Expand Down Expand Up @@ -860,15 +852,12 @@ exports['pom-snapshot'] = `
</project>
`

exports['PR body-snapshot'] = `
:robot: I have created a release \\*beep\\* \\*boop\\*
---
### Updating meta-information for bleeding-edge SNAPSHOT release.
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please).
`
exports['PR body-snapshot'] = {
'title': 'chore: release 0.20.4-SNAPSHOT',
'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).',
'head': 'release-v0.20.4-SNAPSHOT',
'base': 'main'
}

exports['labels-snapshot'] = {
'labels': [
Expand Down
42 changes: 12 additions & 30 deletions __snapshots__/release-pr-factory.js
Expand Up @@ -16,21 +16,12 @@ exports['ReleasePRFactory build returns instance of dynamically loaded releaser
`

exports['ReleasePRFactory build returns instance of dynamically loaded releaser 3'] = `
:robot: I have created a release \\*beep\\* \\*boop\\*
---
### [0.123.5](https://www.github.com/googleapis/simple-test-repo/compare/v0.123.4...v0.123.5)
### Bug Fixes
* **deps:** update dependency com.google.cloud:google-cloud-spanner to v1.50.0 ([1f9663c](https://www.github.com/googleapis/simple-test-repo/commit/1f9663cf08ab1cf3b68d95dee4dc99b7c4aac373))
* **deps:** update dependency com.google.cloud:google-cloud-storage to v1.120.0 ([fcd1c89](https://www.github.com/googleapis/simple-test-repo/commit/fcd1c890dc1526f4d62ceedad561f498195c8939))
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please).
`
exports['ReleasePRFactory build returns instance of dynamically loaded releaser 3'] = {
'title': 'chore: release 0.123.5',
'body': ':robot: I have created a release \\*beep\\* \\*boop\\* \n---\n### [0.123.5](https://www.github.com/googleapis/simple-test-repo/compare/v0.123.4...v0.123.5) \n\n\n### Bug Fixes\n\n* **deps:** update dependency com.google.cloud:google-cloud-spanner to v1.50.0 ([1f9663c](https://www.github.com/googleapis/simple-test-repo/commit/1f9663cf08ab1cf3b68d95dee4dc99b7c4aac373))\n* **deps:** update dependency com.google.cloud:google-cloud-storage to v1.120.0 ([fcd1c89](https://www.github.com/googleapis/simple-test-repo/commit/fcd1c890dc1526f4d62ceedad561f498195c8939))\n---\n\n\nThis PR was generated with [Release Please](https://github.com/googleapis/release-please).',
'head': 'release-v0.123.5',
'base': 'main'
}

exports['ReleasePRFactory build returns instance of dynamically loaded releaser 4'] = {
'labels': [
Expand All @@ -56,21 +47,12 @@ exports['ReleasePRFactory buildStatic returns an instance of a statically loaded
`

exports['ReleasePRFactory buildStatic returns an instance of a statically loaded releaser 3'] = `
:robot: I have created a release \\*beep\\* \\*boop\\*
---
### [0.123.5](https://www.github.com/googleapis/simple-test-repo/compare/v0.123.4...v0.123.5)
### Bug Fixes
* **deps:** update dependency com.google.cloud:google-cloud-spanner to v1.50.0 ([1f9663c](https://www.github.com/googleapis/simple-test-repo/commit/1f9663cf08ab1cf3b68d95dee4dc99b7c4aac373))
* **deps:** update dependency com.google.cloud:google-cloud-storage to v1.120.0 ([fcd1c89](https://www.github.com/googleapis/simple-test-repo/commit/fcd1c890dc1526f4d62ceedad561f498195c8939))
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please).
`
exports['ReleasePRFactory buildStatic returns an instance of a statically loaded releaser 3'] = {
'title': 'chore: release 0.123.5',
'body': ':robot: I have created a release \\*beep\\* \\*boop\\* \n---\n### [0.123.5](https://www.github.com/googleapis/simple-test-repo/compare/v0.123.4...v0.123.5) \n\n\n### Bug Fixes\n\n* **deps:** update dependency com.google.cloud:google-cloud-spanner to v1.50.0 ([1f9663c](https://www.github.com/googleapis/simple-test-repo/commit/1f9663cf08ab1cf3b68d95dee4dc99b7c4aac373))\n* **deps:** update dependency com.google.cloud:google-cloud-storage to v1.120.0 ([fcd1c89](https://www.github.com/googleapis/simple-test-repo/commit/fcd1c890dc1526f4d62ceedad561f498195c8939))\n---\n\n\nThis PR was generated with [Release Please](https://github.com/googleapis/release-please).',
'head': 'release-v0.123.5',
'base': 'main'
}

exports['ReleasePRFactory buildStatic returns an instance of a statically loaded releaser 4'] = {
'labels': [
Expand Down
63 changes: 6 additions & 57 deletions __snapshots__/release-pr.js
Expand Up @@ -18,60 +18,9 @@ exports['GitHub Yoshi PHP Mono-Repo generates CHANGELOG and aborts if duplicate
`

exports['GitHub Yoshi PHP Mono-Repo generates CHANGELOG and aborts if duplicate 2'] = `
:robot: I have created a release \\*beep\\* \\*boop\\*
---
## 0.21.0
<details><summary>automl 1.8.4</summary>
### Bug Fixes
* correctly label as beta ([#1963](https://www.github.com/googleapis/release-please/issues/1963)) ([52f4fbf](https://www.github.com/googleapis/release-please/commit/52f4fbfa1fc3fde585c84e64ef40571d2b85d72e))
</details>
<details><summary>datastore 2.0.1</summary>
### Bug Fixes
* Assorted minor fixes for Cloud Datastore client ([#1964](https://www.github.com/googleapis/release-please/issues/1964)) ([269cf92](https://www.github.com/googleapis/release-please/commit/269cf923ea6fd0375abaf0bb19790475693c6f90))
</details>
<details><summary>pubsub 1.0.2</summary>
### Bug Fixes
* Update PubSub timeouts. ([#1967](https://www.github.com/googleapis/release-please/issues/1967)) ([0a84771](https://www.github.com/googleapis/release-please/commit/0a8477108a26aeb21d7af06e62be4ae5cb00ad42))
</details>
<details><summary>speech 1.1.0</summary>
### Features
* move speech from alpha -> beta ([#1962](https://www.github.com/googleapis/release-please/issues/1962)) ([8db7f3b](https://www.github.com/googleapis/release-please/commit/8db7f3b19c46c873897d79c89ce35b8492e5fe60))
</details>
<details><summary>websecurityscanner 0.9.0</summary>
### Features
* Add Web Security Center Client ([#1961](https://www.github.com/googleapis/release-please/issues/1961)) ([fa5761e](https://www.github.com/googleapis/release-please/commit/fa5761e9e52f36506a72a9292843259d198468b0))
</details>
This PR was generated with [Release Please](https://github.com/googleapis/release-please).
`
exports['GitHub Yoshi PHP Mono-Repo generates CHANGELOG and aborts if duplicate 2'] = {
'title': 'chore: release 0.21.0',
'body': ':robot: I have created a release \\*beep\\* \\*boop\\* \n---\n## 0.21.0\n\n<details><summary>automl 1.8.4</summary>\n\n\n\n### Bug Fixes\n\n* correctly label as beta ([#1963](https://www.github.com/googleapis/release-please/issues/1963)) ([52f4fbf](https://www.github.com/googleapis/release-please/commit/52f4fbfa1fc3fde585c84e64ef40571d2b85d72e))\n\n</details>\n\n<details><summary>datastore 2.0.1</summary>\n\n\n\n### Bug Fixes\n\n* Assorted minor fixes for Cloud Datastore client ([#1964](https://www.github.com/googleapis/release-please/issues/1964)) ([269cf92](https://www.github.com/googleapis/release-please/commit/269cf923ea6fd0375abaf0bb19790475693c6f90))\n\n</details>\n\n<details><summary>pubsub 1.0.2</summary>\n\n\n\n### Bug Fixes\n\n* Update PubSub timeouts. ([#1967](https://www.github.com/googleapis/release-please/issues/1967)) ([0a84771](https://www.github.com/googleapis/release-please/commit/0a8477108a26aeb21d7af06e62be4ae5cb00ad42))\n\n</details>\n\n<details><summary>speech 1.1.0</summary>\n\n\n\n### Features\n\n* move speech from alpha -> beta ([#1962](https://www.github.com/googleapis/release-please/issues/1962)) ([8db7f3b](https://www.github.com/googleapis/release-please/commit/8db7f3b19c46c873897d79c89ce35b8492e5fe60))\n\n</details>\n\n<details><summary>websecurityscanner 0.9.0</summary>\n\n\n\n### Features\n\n* Add Web Security Center Client ([#1961](https://www.github.com/googleapis/release-please/issues/1961)) ([fa5761e](https://www.github.com/googleapis/release-please/commit/fa5761e9e52f36506a72a9292843259d198468b0))\n\n</details>\n\nThis PR was generated with [Release Please](https://github.com/googleapis/release-please).',
'head': 'release-v0.21.0',
'base': 'master'
}
21 changes: 6 additions & 15 deletions __snapshots__/simple.js
Expand Up @@ -16,21 +16,12 @@ exports['version-txt-simple'] = `
`

exports['PR body-simple'] = `
:robot: I have created a release \\*beep\\* \\*boop\\*
---
### [0.123.5](https://www.github.com/googleapis/simple-test-repo/compare/v0.123.4...v0.123.5)
### Bug Fixes
* **deps:** update dependency com.google.cloud:google-cloud-spanner to v1.50.0 ([1f9663c](https://www.github.com/googleapis/simple-test-repo/commit/1f9663cf08ab1cf3b68d95dee4dc99b7c4aac373))
* **deps:** update dependency com.google.cloud:google-cloud-storage to v1.120.0 ([fcd1c89](https://www.github.com/googleapis/simple-test-repo/commit/fcd1c890dc1526f4d62ceedad561f498195c8939))
---
This PR was generated with [Release Please](https://github.com/googleapis/release-please).
`
exports['PR body-simple'] = {
'title': 'chore: release 0.123.5',
'body': ':robot: I have created a release \\*beep\\* \\*boop\\* \n---\n### [0.123.5](https://www.github.com/googleapis/simple-test-repo/compare/v0.123.4...v0.123.5) \n\n\n### Bug Fixes\n\n* **deps:** update dependency com.google.cloud:google-cloud-spanner to v1.50.0 ([1f9663c](https://www.github.com/googleapis/simple-test-repo/commit/1f9663cf08ab1cf3b68d95dee4dc99b7c4aac373))\n* **deps:** update dependency com.google.cloud:google-cloud-storage to v1.120.0 ([fcd1c89](https://www.github.com/googleapis/simple-test-repo/commit/fcd1c890dc1526f4d62ceedad561f498195c8939))\n---\n\n\nThis PR was generated with [Release Please](https://github.com/googleapis/release-please).',
'head': 'release-v0.123.5',
'base': 'master'
}

exports['labels-simple'] = {
'labels': [
Expand Down
8 changes: 8 additions & 0 deletions src/bin/release-please.ts
Expand Up @@ -68,6 +68,10 @@ const argv = yargs
describe: 'is it a snapshot (or pre-release) being generated?',
type: 'boolean',
default: false,
})
.option('default-branch', {
describe: 'default branch to open release PR against',
type: 'string',
});
},
(argv: ReleasePROptions) => {
Expand Down Expand Up @@ -140,6 +144,10 @@ const argv = yargs
default: false,
type: 'boolean',
})
.option('default-branch', {
describe: '',
type: 'string',
})
.demandCommand(1)
.strict(true)
.parse();
Expand Down
21 changes: 18 additions & 3 deletions src/github.ts
Expand Up @@ -65,6 +65,7 @@ export interface OctokitAPIs {
}

interface GitHubOptions {
defaultBranch?: string;
token?: string;
owner: string;
repo: string;
Expand Down Expand Up @@ -108,6 +109,7 @@ interface FileSearchResponseFile {
let probotMode = false;

export class GitHub {
defaultBranch?: string;
octokit: OctokitType;
request: Function;
graphql: Function;
Expand All @@ -118,6 +120,7 @@ export class GitHub {
proxyKey?: string;

constructor(options: GitHubOptions) {
this.defaultBranch = options.defaultBranch;
this.token = options.token;
this.owner = options.owner;
this.repo = options.repo;
Expand Down Expand Up @@ -674,7 +677,7 @@ export class GitHub {
}

await this.updateFiles(options.updates, options.branch, refName);

const base = await this.getDefaultBranch(this.owner, this.repo);
if (openReleasePR) {
// TODO: dig into why `updateRef` closes an issue attached
// to the branch being updated:
Expand All @@ -696,7 +699,7 @@ export class GitHub {
title: options.title,
body: options.body,
state: 'open',
base: 'master',
base,
}
);
return openReleasePR.number;
Expand All @@ -715,13 +718,25 @@ export class GitHub {
title: options.title,
body: options.body,
head: options.branch,
base: 'master',
base,
}
);
return resp.data.number;
}
}

private async getDefaultBranch(owner: string, repo: string): Promise<string> {
if (this.defaultBranch) {
return this.defaultBranch;
}
const {data} = await this.octokit.repos.get({
repo,
owner,
});
this.defaultBranch = data.default_branch;
return this.defaultBranch;
}

async updateFiles(updates: Update[], branch: string, refName: string) {
// does the user care about skipping CI at all?
const skipCiEverSet = updates.some(
Expand Down
4 changes: 1 addition & 3 deletions src/graphql-to-commits.ts
Expand Up @@ -94,8 +94,6 @@ export async function graphqlToCommits(
commitEdge,
observedSHAs
);
// if the commit and its associated PR do not share a sha, we assume
// that the commit was a push to master and disregard it.
if (commit) {
commits.commits.push(commit);
}
Expand Down Expand Up @@ -124,7 +122,7 @@ async function graphqlToCommit(
let prEdge: PREdge = commitEdge.node.associatedPullRequests.edges[0];

// if the commit.sha and mergeCommit.oid do not match, assume that this
// was a push to master and drop the commit.
// was a push directly to the default branch.
//
// TODO: investigate our motivations for skipping commits when
// commitEdge.node.oid and prEdge.node.mergeCommit.oid do not match (this
Expand Down

0 comments on commit 301a08a

Please sign in to comment.