Skip to content

Commit

Permalink
Merge branch 'master' into add-preview-arch-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoferrer authored Dec 15, 2020
2 parents d82bc80 + 9151102 commit 5504d1f
Show file tree
Hide file tree
Showing 24 changed files with 1,560 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Example:

This the default behavior.

Example for a single test case:

`mvn install -Dtest=WireMockStatusReporterTest#user_whenProxying_AuthCorrectlyConfigured`


### Setting up credential

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spotbugs-maven-plugin.version>4.0.4</spotbugs-maven-plugin.version>
<spotbugs.version>4.1.2</spotbugs.version>
<spotbugs.version>4.1.3</spotbugs.version>
<spotbugs-maven-plugin.failOnError>true</spotbugs-maven-plugin.failOnError>
<hamcrest.version>2.2</hamcrest.version>
<okhttp3.version>4.4.1</okhttp3.version>
Expand Down Expand Up @@ -261,7 +261,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
<dependencies>
<dependency>
<groupId>org.apache.bcel</groupId>
Expand Down Expand Up @@ -543,7 +543,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.6.0</version>
<version>3.6.28</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/kohsuke/github/GHEventPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ public static class Status extends GHEventPayload {
private String description;
private GHCommitState state;
private GHCommit commit;
private String targetUrl;

/**
* Gets the status content.
Expand All @@ -1226,6 +1227,15 @@ public String getContext() {
return context;
}

/**
* The optional link added to the status.
*
* @return a url
*/
public String getTargetUrl() {
return targetUrl;
}

/**
* Gets the status description.
*
Expand Down
51 changes: 48 additions & 3 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,13 @@ public int getSize() {
return size;
}

/**
* Affiliation of a repository collaborator
*/
public enum CollaboratorAffiliation {
ALL, DIRECT, OUTSIDE
}

/**
* Gets the collaborators on this repository. This set always appear to include the owner.
*
Expand All @@ -841,6 +848,19 @@ public PagedIterable<GHUser> listCollaborators() throws IOException {
return listUsers("collaborators");
}

/**
* Lists up the collaborators on this repository.
*
* @param affiliation
* Filter users by affiliation
* @return Users paged iterable
* @throws IOException
* the io exception
*/
public PagedIterable<GHUser> listCollaborators(CollaboratorAffiliation affiliation) throws IOException {
return listUsers(root.createRequest().with("affiliation", affiliation), "collaborators");
}

/**
* Lists all
* <a href="https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/">the
Expand Down Expand Up @@ -888,6 +908,29 @@ public Set<String> getCollaboratorNames() throws IOException {
return r;
}

/**
* Gets the names of the collaborators on this repository. This method deviates from the principle of this library
* but it works a lot faster than {@link #getCollaborators()}.
*
* @param affiliation
* Filter users by affiliation
* @return the collaborator names
* @throws IOException
* the io exception
*/
public Set<String> getCollaboratorNames(CollaboratorAffiliation affiliation) throws IOException {
Set<String> r = new HashSet<>();
// no initializer - we just want to the logins
PagedIterable<GHUser> users = root.createRequest()
.withUrlPath(getApiTailUrl("collaborators"))
.with("affiliation", affiliation)
.toIterable(GHUser[].class, null);
for (GHUser u : users.toArray()) {
r.add(u.login);
}
return r;
}

/**
* Obtain permission for a given user in this repository.
*
Expand Down Expand Up @@ -2092,9 +2135,11 @@ public PagedIterable<GHStargazer> listStargazers2() {
}

private PagedIterable<GHUser> listUsers(final String suffix) {
return root.createRequest()
.withUrlPath(getApiTailUrl(suffix))
.toIterable(GHUser[].class, item -> item.wrapUp(root));
return listUsers(root.createRequest(), suffix);
}

private PagedIterable<GHUser> listUsers(Requester requester, final String suffix) {
return requester.withUrlPath(getApiTailUrl(suffix)).toIterable(GHUser[].class, item -> item.wrapUp(root));
}

/**
Expand Down
33 changes: 24 additions & 9 deletions src/main/java/org/kohsuke/github/GitHubRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private GitHubRequest(@Nonnull List<Entry> args,

/**
* Create a new {@link Builder}.
*
*
* @return a new {@link Builder}.
*/
public static Builder<?> newBuilder() {
Expand Down Expand Up @@ -165,7 +165,7 @@ public Map<String, Object> injectedMappingValues() {

/**
* The base GitHub API URL for this request represented as a {@link String}
*
*
* @return the url string
*/
@Nonnull
Expand All @@ -176,7 +176,7 @@ public String apiUrl() {
/**
* The url path to be added to the {@link #apiUrl()} for this request. If this does not start with a "/", it instead
* represents the full url string for this request.
*
*
* @return a url path or full url string
*/
@Nonnull
Expand All @@ -186,7 +186,7 @@ public String urlPath() {

/**
* The content type to to be sent by this request.
*
*
* @return the content type.
*/
@Nonnull
Expand All @@ -196,7 +196,7 @@ public String contentType() {

/**
* The {@link InputStream} to be sent as the body of this request.
*
*
* @return the {@link InputStream}.
*/
@CheckForNull
Expand All @@ -206,7 +206,7 @@ public InputStream body() {

/**
* The {@link URL} for this request. This is the actual URL the {@link GitHubClient} will send this request to.
*
*
* @return the request {@link URL}
*/
@Nonnull
Expand All @@ -216,7 +216,7 @@ public URL url() {

/**
* Whether arguments for this request should be included in the URL or in the body of the request.
*
*
* @return true if the arguements should be sent in the body of the request.
*/
public boolean inBody() {
Expand All @@ -226,7 +226,7 @@ public boolean inBody() {
/**
* Create a {@link Builder} from this request. Initial values of the builder will be the same as this
* {@link GitHubRequest}.
*
*
* @return a {@link Builder} based on this request.
*/
public Builder<?> toBuilder() {
Expand Down Expand Up @@ -346,7 +346,7 @@ private Builder(@Nonnull List<Entry> args,

/**
* Builds a {@link GitHubRequest} from this builder.
*
*
* @return a {@link GitHubRequest}
* @throws MalformedURLException
* if the GitHub API URL cannot be constructed
Expand Down Expand Up @@ -437,6 +437,21 @@ public B withPreview(String name) {
return withHeader("Accept", name);
}

/**
* With requester.
*
* @param Map
* map of key value pairs to add
* @return the request builder
*/
public B with(Map<String, Object> map) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
with(entry.getKey(), entry.getValue());
}

return (B) this;
}

/**
* With requester.
*
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/kohsuke/github/extras/OkHttpConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
*
* @author Roberto Tyley
* @author Kohsuke Kawaguchi
* @deprecated This class depends on an unsupported version of OkHttp. Switch to
* {@link org.kohsuke.github.extras.okhttp3.OkHttpConnector}.
* @see org.kohsuke.github.extras.okhttp3.OkHttpConnector
*/
@Deprecated
public class OkHttpConnector implements HttpConnector {
private static final String HEADER_NAME = "Cache-Control";
private final OkUrlFactory urlFactory;
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,14 @@ public void status() throws Exception {
assertThat(event.getState(), is(GHCommitState.SUCCESS));
assertThat(event.getCommit().getSHA1(), is("9049f1265b7d61be4a8904a9a27120d2064dab3b"));
assertThat(event.getRepository().getOwner().getLogin(), is("baxterthehacker"));
assertNull(event.getTargetUrl());
}

@Test
public void status2() throws Exception {
GHEventPayload.Status event = GitHub.offline()
.parseEventPayload(payload.asReader(), GHEventPayload.Status.class);
assertThat(event.getTargetUrl(), is("https://www.wikipedia.org/"));
}

// TODO implement support classes and write test
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,15 @@ public void listCollaborators() throws Exception {
assertThat(collaborators.size(), greaterThan(10));
}

@Test
public void listCollaboratorsFiltered() throws Exception {
GHRepository repo = getRepository();
List<GHUser> allCollaborators = repo.listCollaborators().toList();
List<GHUser> filteredCollaborators = repo.listCollaborators(GHRepository.CollaboratorAffiliation.OUTSIDE)
.toList();
assertThat(filteredCollaborators.size(), lessThan(allCollaborators.size()));
}

@Test
public void getCheckRuns() throws Exception {
final int expectedCount = 8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
"uuid": "bce97482-6a11-44e5-a112-29230b142636",
"persistent": true,
"insertionIndex": 4
}
}
Loading

0 comments on commit 5504d1f

Please sign in to comment.