Skip to content

Commit

Permalink
Merge pull request #478 from martinvanzijl/issue_460_team_description…
Browse files Browse the repository at this point in the history
…_field

Added description field to GHTeam class.
  • Loading branch information
bitwiseman committed Oct 4, 2019
2 parents 563507c + 872d713 commit f622114
Show file tree
Hide file tree
Showing 175 changed files with 26,155 additions and 634 deletions.
12 changes: 11 additions & 1 deletion src/main/java/org/kohsuke/github/GHTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @author Kohsuke Kawaguchi
*/
public class GHTeam {
private String name,permission,slug;
private String name,permission,slug,description;
private int id;
private GHOrganization organization; // populated by GET /user/teams where Teams+Orgs are returned together

Expand Down Expand Up @@ -59,6 +59,16 @@ public String getSlug() {
return slug;
}

public String getDescription() {
return description;
}

public void setDescription(String description) throws IOException {
org.root.retrieve().method("PATCH")
.with("description", description)
.to(api(""));
}

public int getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ protected GitHubBuilder getGitHubBuilder() {
// This sets the user and password to a placeholder for wiremock testing
// This makes the tests believe they are running with permissions
// The recorded stubs will behave like they running with permissions
builder.oauthToken = null;
builder.withPassword(STUBBED_USER_LOGIN, STUBBED_USER_PASSWORD);
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ public void listLanguages() throws IOException {

@Test // Issue #261
public void listEmptyContributors() throws IOException {
GitHub gh = GitHub.connect();
for (GHRepository.Contributor c : gh.getRepository(GITHUB_API_TEST_ORG + "/empty").listContributors()) {
for (GHRepository.Contributor c : gitHub.getRepository(GITHUB_API_TEST_ORG + "/empty").listContributors()) {
System.out.println(c);
fail("This list should be empty, but should return a valid empty iterable.");
}
}

Expand Down
33 changes: 33 additions & 0 deletions src/test/java/org/kohsuke/github/GHTeamTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.kohsuke.github;

import org.junit.Test;

import java.io.IOException;
import java.util.Random;

public class GHTeamTest extends AbstractGitHubApiWireMockTest {

@Test
public void testSetDescription() throws IOException {

String description = "Updated by API Test";
String teamSlug = "dummy-team";

// Set the description.
GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
team.setDescription(description);

// Check that it was set correctly.
team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
assertEquals(description, team.getDescription());

description += "Modified";

// Set the description.
team.setDescription(description);

// Check that it was set correctly.
team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
assertEquals(description, team.getDescription());
}
}
49 changes: 39 additions & 10 deletions src/test/java/org/kohsuke/github/junit/GitHubApiWireMockRule.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
package org.kohsuke.github.junit;

import com.github.tomakehurst.wiremock.common.FileSource;
import com.github.tomakehurst.wiremock.common.InputStreamSource;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.extension.Parameters;
import com.github.tomakehurst.wiremock.extension.ResponseTransformer;
import com.github.tomakehurst.wiremock.http.HttpHeader;
import com.github.tomakehurst.wiremock.http.HttpHeaders;
import com.github.tomakehurst.wiremock.http.Request;
import com.github.tomakehurst.wiremock.http.Response;
import com.google.gson.*;
import com.jcraft.jsch.IO;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.client.WireMock.status;
import static com.github.tomakehurst.wiremock.common.Gzip.gzip;
import static com.github.tomakehurst.wiremock.common.Gzip.unGzipToString;

/**
* @author Liam Newman
Expand All @@ -42,18 +50,35 @@ public GitHubApiWireMockRule(WireMockConfiguration options, boolean failOnUnmatc
@Override
public Response transform(Request request, Response response, FileSource files,
Parameters parameters) {
Response.Builder builder = Response.Builder.like(response);
Collection<HttpHeader> headers = response.getHeaders().all();
HttpHeader linkHeader = response.getHeaders().getHeader("Link");
if (linkHeader.isPresent()) {
headers.removeIf(item -> item.keyEquals("Link"));
headers.add(HttpHeader.httpHeader("Link", linkHeader.firstValue()
.replace("https://api.github.com/",
"http://localhost:" + request.getPort() + "/")));
}

if ("application/json"
.equals(response.getHeaders().getContentTypeHeader().mimeTypePart())
&& !response.getHeaders().getHeader("Content-Encoding").containsValue("gzip")) {
return Response.Builder.like(response)
.but()
.body(response.getBodyAsString()
.replace("https://api.github.com/",
"http://localhost:" + request.getPort() + "/")
)
.build();
.equals(response.getHeaders().getContentTypeHeader().mimeTypePart())) {

String body;
if (response.getHeaders().getHeader("Content-Encoding").containsValue("gzip")) {
headers.removeIf(item -> item.keyEquals("Content-Encoding"));
body = unGzipToString(response.getBody());
} else {
body = response.getBodyAsString();
}

builder.body(body
.replace("https://api.github.com/",
"http://localhost:" + request.getPort() + "/"));

}
return response;
builder.headers(new HttpHeaders(headers));

return builder.build();
}

@Override
Expand Down Expand Up @@ -126,6 +151,10 @@ public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContex
try {
if (filePath.toString().endsWith(".json")) {
String fileText = new String(Files.readAllBytes(filePath));
// while recording responses we replaced all github calls localhost
// now we reverse that for storage.
fileText = fileText.replace(this.baseUrl(),
"https://api.github.com");
// Can be Array or Map
Object parsedObject = g.fromJson(fileText, Object.class);
if (parsedObject instanceof Map && filePath.toString().contains("mappings")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"total_private_repos": 0,
"owned_private_repos": 0,
"private_gists": 0,
"disk_usage": 11899,
"disk_usage": 12072,
"collaborators": 0,
"billing_email": "bitwiseman@gmail.com",
"default_repository_permission": "read",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
"releases_url": "https://api.github.com/repos/github-api/github-api/releases{/id}",
"deployments_url": "https://api.github.com/repos/github-api/github-api/deployments",
"created_at": "2010-04-19T04:13:03Z",
"updated_at": "2019-10-03T09:41:10Z",
"pushed_at": "2019-10-02T22:27:45Z",
"updated_at": "2019-10-03T21:38:52Z",
"pushed_at": "2019-10-03T23:00:11Z",
"git_url": "git://github.com/github-api/github-api.git",
"ssh_url": "git@github.com:github-api/github-api.git",
"clone_url": "https://github.com/github-api/github-api.git",
"svn_url": "https://github.com/github-api/github-api",
"homepage": "http://github-api.kohsuke.org/",
"size": 11899,
"size": 12072,
"stargazers_count": 557,
"watchers_count": 557,
"language": "Java",
Expand All @@ -85,7 +85,7 @@
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 90,
"open_issues_count": 89,
"license": {
"key": "mit",
"name": "MIT License",
Expand All @@ -94,7 +94,7 @@
"node_id": "MDc6TGljZW5zZTEz"
},
"forks": 428,
"open_issues": 90,
"open_issues": 89,
"watchers": 557,
"default_branch": "master",
"permissions": {
Expand Down
Loading

0 comments on commit f622114

Please sign in to comment.