Skip to content

Commit

Permalink
Merge branch 'master' into issue_381_branch_url_escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Sep 10, 2019
2 parents 87d7314 + 32804b8 commit 3aa8c40
Show file tree
Hide file tree
Showing 397 changed files with 43,932 additions and 87 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Java CI Build and Test

on: [push, pull_request]


jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Maven Download all dependencies
run: mvn -B org.apache.maven.plugins:maven-dependency-plugin:3.1.1:go-offline
- name: Maven Build
run: mvn -B package --file pom.xml -Dtest=CommitTest,GistTest,PullRequestTest,UserTest,WireMockStatusReporterTest
62 changes: 62 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Contributing

## Using WireMock and Snapshots

This project has started converting to using WireMock to stub out http responses instead of use live data.
This change will allow tests to run in a CI environment without needing to touch github.com.
The tests will instead serve previously recorded responses from local data files.

### Running WireMock tests

Example:

`mvn install -Dtest=WireMockStatusReporterTest`

This the default behavior.


### Setting up credential

1. Create an OAuth token on github.com
2. Set the GITHUB_OAUTH environment variable to the value of that token
3. Set the system property `test.github.useProxy` (usually like "-Dtest.github.useProxy" as a Java VM option)

`mvn install -Dtest.github.useProxy -Dtest=WireMockStatusReporterTest`

4. The above should report no test failures and include the following console output:

`WireMockStatusReporterTest: GitHub proxying and user auth correctly configured for user login: <your login>`

Whenever you run tests with `-Dtest.github.useProxy`, they will try to get data from local files but will fallback to proxying to github if not found.


### Writing a new test

Once you have credentials setup, you add new test classes and test methods as you would normally.
Keep `useProxy` enabled and iterate on your tests as needed. Remember, while proxying your tests are interacting with GitHub - you will need to clean up your state between runs.

When you are ready to create a snapshot of your test data,
run your test with `test.github.takeSnapshot` ("-Dtest.github.takeSnapshot" as a Java VM option). For example:

`mvn install -Dtest.github.takeSnapshot -Dtest=YourTestClassName`

The above command would create snapshot WireMock data files under the path `src/test/resources/org/kohsuhke/github/YourTestClassName/wiremock`.
Each method would get a separate director that would hold the data files for that test method.

Add all files including the generated data to your commit and submit a PR.

### Modifying existing tests

When modifying existing tests, you can change the stubbed WireMock data files by hand or you can try generating a new snapshot.

#### Manual editing of data (minor changes only)

If you know what data will change, it is sometimes simplest to make any required changes to the data files manually.
This can be easier if the changes are minor or when you development environment is not setup to to take updated snapshots.

#### Generating a new snapshot

For more most changes, it is recommended to take a new snapshot when updating tests.
Delete the wiremock data files for the test method you will be modifying.
For more significant changes, you can even delete the WireMock files for an entire test class.
Then follow the same as when writing a new test: run with proxy enabled to debug, take a new snapshot when done, commit everything, and submit the PR.
3 changes: 0 additions & 3 deletions README

This file was deleted.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Java API for GitHub

See https://github-api.kohsuke.org/ for more details
98 changes: 74 additions & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
<parent>
<groupId>org.kohsuke</groupId>
<artifactId>pom</artifactId>
<version>20</version>
<version>21</version>
<relativePath />
</parent>

<artifactId>github-api</artifactId>
<version>1.96-SNAPSHOT</version>
<name>GitHub API for Java</name>
<url>http://github-api.kohsuke.org/</url>
<url>https://github-api.kohsuke.org/</url>
<description>GitHub API for Java</description>

<scm>
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
<url>http://${project.artifactId}.kohsuke.org/</url>
<url>https://${project.artifactId}.kohsuke.org/</url>
<tag>HEAD</tag>
</scm>

Expand All @@ -28,12 +29,23 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<findbugs-maven-plugin.version>3.0.2</findbugs-maven-plugin.version>
<findbugs-maven-plugin.failOnError>true</findbugs-maven-plugin.failOnError>
<spotbugs-maven-plugin.version>3.1.11</spotbugs-maven-plugin.version>
<spotbugs.version>3.1.12</spotbugs.version>
<spotbugs-maven-plugin.failOnError>true</spotbugs-maven-plugin.failOnError>
<hamcrest.version>2.1</hamcrest.version>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
Expand Down Expand Up @@ -75,22 +87,41 @@
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${findbugs-maven-plugin.version}</version>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<xmlOutput>true</xmlOutput>
<failOnError>${findbugs-maven-plugin.failOnError}</failOnError>
<failOnError>${spotbugs-maven-plugin.failOnError}</failOnError>
</configuration>
<executions>
<execution>
<id>run-findbugs</id>
<id>run-spotbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>${spotbugs.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- Do not use gmaven plugin -->
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<goals>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand All @@ -106,22 +137,35 @@
<artifactId>commons-codec</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<!-- This is needed in order to force junit4 and JTH tests to use newer hamcrest version -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.2</version>
<version>2.9.9.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down Expand Up @@ -171,22 +215,28 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<version>${spotbugs.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8-standalone</artifactId>
<version>2.24.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

Expand All @@ -202,7 +252,7 @@
<licenses>
<license>
<name>The MIT license</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<url>https://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHDeployKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ public class GHDeployKey {

protected String url, key, title;
protected boolean verified;
protected int id;
protected long id;
private GHRepository owner;

public int getId() {
public long getId() {
return id;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHEventInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class GHEventInfo {
"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR" }, justification = "JSON API")
public static class GHEventRepository {
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
private int id;
private long id;
@SuppressFBWarnings(value = "UUF_UNUSED_FIELD", justification = "We don't provide it in API now")
private String url; // repository API URL
private String name; // owner/repo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public GHPullRequestQueryBuilder state(GHIssueState state) {
}

public GHPullRequestQueryBuilder head(String head) {
if (head != null && !head.contains(":")) {
head = repo.getOwnerName() + ":" + head;
}
req.with("head",head);
return this;
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/kohsuke/github/GHPullRequestReview.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.util.Date;
import javax.annotation.CheckForNull;
import java.io.IOException;
import java.net.URL;
Expand All @@ -43,6 +44,7 @@ public class GHPullRequestReview extends GHObject {
private GHUser user;
private String commit_id;
private GHPullRequestReviewState state;
private String submitted_at;

/*package*/ GHPullRequestReview wrapUp(GHPullRequest owner) {
this.owner = owner;
Expand Down Expand Up @@ -88,6 +90,21 @@ protected String getApiRoute() {
return owner.getApiRoute()+"/reviews/"+id;
}

/**
* When was this resource created?
*/
public Date getSubmittedAt() throws IOException {
return GitHub.parseDate(submitted_at);
}

/**
* Since this method does not exist, we forward this value.
*/
@Override
public Date getCreatedAt() throws IOException {
return getSubmittedAt();
}

/**
* @deprecated
* Former preview method that changed when it got public. Left here for backward compatibility.
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,36 @@ public GHPullRequestQueryBuilder queryPullRequests() {
* of a pull request.
*/
public GHPullRequest createPullRequest(String title, String head, String base, String body) throws IOException {
return createPullRequest(title, head, base, body, true);
}

/**
* Creates a new pull request. Maintainer's permissions aware.
*
* @param title
* Required. The title of the pull request.
* @param head
* Required. The name of the branch where your changes are implemented.
* For cross-repository pull requests in the same network,
* namespace head with a user like this: username:branch.
* @param base
* Required. The name of the branch you want your changes pulled into.
* This should be an existing branch on the current repository.
* @param body
* The contents of the pull request. This is the markdown description
* of a pull request.
* @param maintainerCanModify
* Indicates whether maintainers can modify the pull request.
*/
public GHPullRequest createPullRequest(String title, String head, String base, String body,
boolean maintainerCanModify) throws IOException {
return new Requester(root).with("title",title)
.with("head",head)
.with("base",base)
.with("body",body).to(getApiTailUrl("pulls"),GHPullRequest.class).wrapUp(this);
.with("body",body)
.with("maintainer_can_modify", maintainerCanModify)
.to(getApiTailUrl("pulls"),GHPullRequest.class)
.wrapUp(this);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void add(GHUser u) throws IOException {
*/
public void add(GHUser user, Role role) throws IOException {
org.root.retrieve().method("PUT")
.with("role", role.name())
.with("role", role)
.to(api("/memberships/" + user.getLogin()), null);
}

Expand Down

0 comments on commit 3aa8c40

Please sign in to comment.