Skip to content

Commit

Permalink
feat: adding support for google-auth-library-java (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Jul 26, 2019
1 parent 200f710 commit f72c930
Show file tree
Hide file tree
Showing 19 changed files with 3,612 additions and 9 deletions.
507 changes: 507 additions & 0 deletions __snapshots__/graphql-to-commits.js

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions __snapshots__/java-auth-readme.js
@@ -0,0 +1,36 @@
exports['JavaAuthReadme updateContent updates version examples in README.md 1'] = `
## Quickstart
If you are using Maven, add this to your pom.xml file (notice that you can replace
\`google-auth-library-oauth2-http\` with any of \`google-auth-library-credentials\` and
\`google-auth-library-appengine\`, depending on your application needs):
[//]: # ({x-version-update-start:google-auth-library-oauth2-http:released})
\`\`\`xml
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>0.20.0</version>
</dependency>
\`\`\`
[//]: # ({x-version-update-end})
If you are using Gradle, add this to your dependencies
[//]: # ({x-version-update-start:google-auth-library-oauth2-http:released})
\`\`\`Groovy
compile 'com.google.auth:google-auth-library-oauth2-http:0.20.0'
\`\`\`
[//]: # ({x-version-update-end})
If you are using SBT, add this to your dependencies
[//]: # ({x-version-update-start:google-auth-library-oauth2-http:released})
\`\`\`Scala
libraryDependencies += "com.google.auth" % "google-auth-library-oauth2-http" % "0.20.0"
\`\`\`
[//]: # ({x-version-update-end})
`
25 changes: 25 additions & 0 deletions __snapshots__/java-auth-versions.js
@@ -0,0 +1,25 @@
exports['JavaAuthVersions updateContent updates versions.txt appropriately for non-SNAPSHOT release 1'] = `
# Format:
# module:released-version:current-version
google-auth-library:0.25.0:0.25.0
google-auth-library-bom:0.25.0:0.25.0
google-auth-library-parent:0.25.0:0.25.0
google-auth-library-appengine:0.25.0:0.25.0
google-auth-library-credentials:0.25.0:0.25.0
google-auth-library-oauth2-http:0.25.0:0.25.0
`

exports['JavaAuthVersions updateContent updates versions.txt appropriately for SNAPSHOT release 1'] = `
# Format:
# module:released-version:current-version
google-auth-library:0.16.2:0.16.2-SNAPSHOT
google-auth-library-bom:0.16.2:0.16.2-SNAPSHOT
google-auth-library-parent:0.16.2:0.16.2-SNAPSHOT
google-auth-library-appengine:0.16.2:0.16.2-SNAPSHOT
google-auth-library-credentials:0.16.2:0.16.2-SNAPSHOT
google-auth-library-oauth2-http:0.16.2:0.16.2-SNAPSHOT
`
87 changes: 87 additions & 0 deletions __snapshots__/pom-xml.js
@@ -0,0 +1,87 @@
exports['PomXML updateContent updates version in pom.xml 1'] = `
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<parent>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-parent</artifactId>
<version>0.19.0</version><!-- {x-version-update:google-auth-library-parent:current} -->
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>google-auth-library-appengine</artifactId>
<name>Google Auth Library for Java - Google App Engine</name>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<build>
<sourceDirectory>java</sourceDirectory>
<testSourceDirectory>javatests</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-credentials</artifactId>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>
`
10 changes: 8 additions & 2 deletions src/bin/release-please.ts
Expand Up @@ -34,7 +34,8 @@ interface ErrorObject {
interface YargsOptions {
describe: string;
demand?: boolean;
default?: string;
type?: string;
default?: string | boolean;
}

interface YargsOptionsBuilder {
Expand All @@ -58,6 +59,11 @@ const argv = yargs
.option('label', {
default: 'autorelease: pending,type: process',
describe: 'label(s) to add to generated PR',
})
.option('snapshot', {
describe: 'is it a snapshot (or pre-release) being generated?',
type: 'boolean',
default: false,
});
},
(argv: ReleasePROptions) => {
Expand Down Expand Up @@ -147,7 +153,7 @@ action "github-release" {
})
.option('release-type', {
describe: 'what type of repo is a release being created for?',
options: ['node', 'php-yoshi'],
choices: ['node', 'php-yoshi', 'java-auth-yoshi'],
default: 'node',
})
.option('bump-minor-pre-major', {
Expand Down
80 changes: 78 additions & 2 deletions src/github.ts
Expand Up @@ -106,13 +106,15 @@ export class GitHub {

async commitsSinceSha(
sha: string | undefined,
perPage = 100
perPage = 100,
labels = false
): Promise<Commit[]> {
const commits: Commit[] = [];
const method = labels ? 'commitsWithLabels' : 'commitsWithFiles';

let cursor;
while (true) {
const commitsResponse: CommitsResponse = await this.commitsWithFiles(
const commitsResponse: CommitsResponse = await this[method](
cursor,
perPage
);
Expand Down Expand Up @@ -219,6 +221,80 @@ export class GitHub {
}
}

private async commitsWithLabels(
cursor: string | undefined = undefined,
perPage = 32,
maxLabels = 16,
retries = 0
): Promise<CommitsResponse> {
try {
const response = await graphql({
query: `query commitsWithLabels($cursor: String, $owner: String!, $repo: String!, $perPage: Int, $maxLabels: Int) {
repository(owner: $owner, name: $repo) {
defaultBranchRef {
target {
... on Commit {
history(first: $perPage, after: $cursor) {
edges{
node {
... on Commit {
message
oid
associatedPullRequests(first: 1) {
edges {
node {
... on PullRequest {
number
labels(first: $maxLabels) {
edges {
node {
name
}
}
}
}
}
}
}
}
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
}
}`,
cursor,
maxLabels,
owner: this.owner,
perPage,
repo: this.repo,
url: `${this.apiUrl}/graphql${
this.proxyKey ? `?key=${this.proxyKey}` : ''
}`,
headers: {
authorization: `${this.proxyKey ? '' : 'token '}${this.token}`,
'content-type': 'application/vnd.github.v3+json',
},
});
return graphqlToCommits(this, response);
} catch (err) {
if (err.status === 502 && retries < 3) {
// GraphQL sometimes returns a 502 on the first request,
// this seems to relate to a cache being warmed and the
// second request generally works.
return this.commitsWithLabels(cursor, perPage, maxLabels, retries++);
} else {
throw err;
}
}
}

async pullRequestFiles(
num: number,
cursor: string,
Expand Down
46 changes: 44 additions & 2 deletions src/graphql-to-commits.ts
Expand Up @@ -16,6 +16,8 @@

import { GitHub } from './github';

const CONVENTIONAL_COMMIT_REGEX = /^[\w]+(\(\w+\))?!?: /;

// simplified model for working with commits (vs., GraphQL response):

export interface CommitsResponse {
Expand Down Expand Up @@ -50,13 +52,21 @@ interface CommitEdge {
}

export interface PREdge {
node: { number: number; files: { edges: FileEdge[]; pageInfo: PageInfo } };
node: {
number: number;
files: { edges: FileEdge[]; pageInfo: PageInfo };
labels: { edges: LabelEdge[] };
};
}

interface FileEdge {
node: { path: string };
}

interface LabelEdge {
node: { name: string };
}

interface PageInfo {
endCursor: string;
hasNextPage: boolean;
Expand Down Expand Up @@ -102,7 +112,7 @@ async function graphqlToCommit(

// if, on the off chance, there are more than 100 files attached to a
// PR, paginate in the additional files.
while (true) {
while (true && prEdge.node.files) {
for (let i = 0, fileEdge; i < prEdge.node.files.edges.length; i++) {
commit.files.push(prEdge.node.files.edges[i].node.path);
}
Expand All @@ -116,5 +126,37 @@ async function graphqlToCommit(
if (prEdge.node.files.pageInfo.hasNextPage === false) break;
}

// to help some language teams transition to conventional commits, we allow
// a label to be used as an alternative to a commit prefix.
if (
prEdge.node.labels &&
CONVENTIONAL_COMMIT_REGEX.test(commit.message) === false
) {
const prefix = prefixFromLabel(prEdge.node.labels.edges);
if (prefix) {
commit.message = `${prefix}${commit.message}`;
}
}
return commit;
}

function prefixFromLabel(labels: LabelEdge[]): string | undefined {
let prefix = undefined;
let breaking = false;
for (let i = 0, labelEdge; i < labels.length; i++) {
labelEdge = labels[i];
if (labelEdge.node.name === 'feature') {
prefix = 'feat';
} else if (labelEdge.node.name === 'fix') {
prefix = 'fix';
} else if (labelEdge.node.name === 'semver: major') {
breaking = true;
}
}

if (prefix) {
prefix = `${prefix}${breaking ? '!' : ''}: `;
}

return prefix;
}

0 comments on commit f72c930

Please sign in to comment.