From 7c204fe9c4b8270df96dbb621b4a020adc35e122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Esteban=20Guti=C3=A9rrez?= Date: Mon, 8 Apr 2024 17:25:04 +0200 Subject: [PATCH 01/11] feat: List external groups in an organization --- .../github/EnterpriseManagedSupport.java | 66 +++++ .../GHEnterpriseManagedUsersException.java | 44 +++ src/main/java/org/kohsuke/github/GHError.java | 52 ++++ .../org/kohsuke/github/GHExternalGroup.java | 262 ++++++++++++++++++ .../org/kohsuke/github/GHExternalGroups.java | 28 ++ .../github/GHExternalGroupsIterable.java | 79 ++++++ ...tExternallyManagedEnterpriseException.java | 29 ++ .../org/kohsuke/github/GHOrganization.java | 33 +++ .../github/EnterpriseManagedSupportTest.java | 146 ++++++++++ .../github/ExternalGroupsTestingSupport.java | 99 +++++++ .../kohsuke/github/GHExternalGroupTest.java | 69 +++++ .../kohsuke/github/GHOrganizationTest.java | 116 ++++++++ .../__files/1-orgs_hub4j-test-org.json | 41 +++ .../mappings/1-orgs_hub4j-test-org.json | 48 ++++ .../__files/1-orgs_hub4j-test-org.json | 41 +++ .../mappings/1-orgs_hub4j-test-org.json | 48 ++++ .../__files/1-orgs_hub4j-test-org.json | 41 +++ .../mappings/1-orgs_hub4j-test-org.json | 48 ++++ .../__files/1-orgs_hub4j-test-org.json | 41 +++ .../mappings/1-orgs_hub4j-test-org.json | 48 ++++ .../__files/1-orgs_hub4j-test-org.json | 41 +++ .../mappings/1-orgs_hub4j-test-org.json | 48 ++++ .../__files/1-orgs_hub4j-test-org.json | 41 +++ .../__files/2-o_h_external-groups.json | 24 ++ .../mappings/1-orgs_hub4j-test-org.json | 50 ++++ .../mappings/2-o_h_external-groups.json | 49 ++++ .../__files/1-orgs_hub4j-test-org.json | 41 +++ .../__files/2-o_h_external-groups.json | 24 ++ .../__files/3-o_h_external-group_467431.json | 25 ++ .../mappings/1-orgs_hub4j-test-org.json | 48 ++++ .../mappings/2-o_h_external-groups.json | 47 ++++ .../mappings/3-o_h_external-group_467431.json | 47 ++++ .../__files/1-orgs_hub4j-test-org.json | 41 +++ .../__files/2-o_h_external-groups.json | 4 + .../mappings/1-orgs_hub4j-test-org.json | 48 ++++ .../mappings/2-o_h_external-groups.json | 47 ++++ .../__files/1-orgs_hub4j-test-org.json | 41 +++ .../__files/2-o_h_external-groups.json | 24 ++ .../mappings/1-orgs_hub4j-test-org.json | 48 ++++ .../mappings/2-o_h_external-groups.json | 47 ++++ .../__files/1-orgs_hub4j-test-org.json | 41 +++ .../__files/2-o_h_external-groups.json | 14 + .../__files/3-o_h_external-groups.json | 14 + .../mappings/1-orgs_hub4j-test-org.json | 48 ++++ .../mappings/2-o_h_external-groups.json | 49 ++++ .../mappings/3-o_h_external-groups.json | 47 ++++ .../__files/1-orgs_hub4j-test-org.json | 41 +++ .../__files/2-o_h_external-groups.json | 24 ++ .../mappings/1-orgs_hub4j-test-org.json | 48 ++++ .../mappings/2-o_h_external-groups.json | 47 ++++ 50 files changed, 2537 insertions(+) create mode 100644 src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java create mode 100644 src/main/java/org/kohsuke/github/GHEnterpriseManagedUsersException.java create mode 100644 src/main/java/org/kohsuke/github/GHError.java create mode 100644 src/main/java/org/kohsuke/github/GHExternalGroup.java create mode 100644 src/main/java/org/kohsuke/github/GHExternalGroups.java create mode 100644 src/main/java/org/kohsuke/github/GHExternalGroupsIterable.java create mode 100644 src/main/java/org/kohsuke/github/GHNotExternallyManagedEnterpriseException.java create mode 100644 src/test/java/org/kohsuke/github/EnterpriseManagedSupportTest.java create mode 100644 src/test/java/org/kohsuke/github/ExternalGroupsTestingSupport.java create mode 100644 src/test/java/org/kohsuke/github/GHExternalGroupTest.java create mode 100644 src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleEmbeddedNotPartOfExternallyManagedEnterpriseHttpException/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleEmbeddedNotPartOfExternallyManagedEnterpriseHttpException/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnknownErrorMessage/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnknownErrorMessage/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnparseableJson/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnparseableJson/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonBadRequestExceptions/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonBadRequestExceptions/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonHttpException/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonHttpException/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/__files/2-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/mappings/2-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/__files/2-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/__files/3-o_h_external-group_467431.json create mode 100644 src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/mappings/2-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/mappings/3-o_h_external-group_467431.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/__files/2-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/mappings/2-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/__files/2-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/mappings/2-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/__files/2-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/__files/3-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/mappings/2-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/mappings/3-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/__files/2-o_h_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/mappings/2-o_h_external-groups.json diff --git a/src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java b/src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java new file mode 100644 index 0000000000..379331fb3c --- /dev/null +++ b/src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java @@ -0,0 +1,66 @@ +package org.kohsuke.github; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Optional; +import java.util.logging.Logger; + +/** + * Utility class for helping with operation for enterprise managed resources. + * + * @author Miguel Esteban Gutiérrez + */ +class EnterpriseManagedSupport { + + static final String COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS = "Could not retrieve organization external groups"; + static final String NOT_PART_OF_EXTERNALLY_MANAGED_ENTERPRISE_ERROR = "This organization is not part of externally managed enterprise."; + + private static final Logger LOGGER = Logger.getLogger(EnterpriseManagedSupport.class.getName()); + + private final GHOrganization organization; + + private EnterpriseManagedSupport(GHOrganization organization) { + this.organization = organization; + } + + Optional handleException(final HttpException he, final String scenario) { + if (he.getResponseCode() == 400) { + final String responseMessage = he.getMessage(); + try { + final GHError error = GitHubClient.getMappingObjectReader(this.organization.root()) + .forType(GHError.class) + .readValue(responseMessage); + if (NOT_PART_OF_EXTERNALLY_MANAGED_ENTERPRISE_ERROR.equals(error.getMessage())) { + return Optional.of(new GHNotExternallyManagedEnterpriseException(scenario, error, he)); + } + } catch (final JsonProcessingException e) { + // We can ignore it + LOGGER.warning(() -> logUnexpectedFailure(e, responseMessage)); + } + } + return Optional.empty(); + } + + Optional handleException(final GHException e) { + if (e.getCause() instanceof HttpException) { + final HttpException he = (HttpException) e.getCause(); + return handleException(he, COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS) + .map(translated -> new GHException(COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS, translated)); + } + return Optional.empty(); + } + + static EnterpriseManagedSupport forOrganization(final GHOrganization org) { + return new EnterpriseManagedSupport(org); + } + + private static String logUnexpectedFailure(final JsonProcessingException exception, final String payload) { + final StringWriter sw = new StringWriter(); + final PrintWriter pw = new PrintWriter(sw); + exception.printStackTrace(pw); + return String.format("Could not parse GitHub error response: '%s'. Full stacktrace follows:%n%s", payload, sw); + } + +} diff --git a/src/main/java/org/kohsuke/github/GHEnterpriseManagedUsersException.java b/src/main/java/org/kohsuke/github/GHEnterpriseManagedUsersException.java new file mode 100644 index 0000000000..9f237da599 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHEnterpriseManagedUsersException.java @@ -0,0 +1,44 @@ +package org.kohsuke.github; + +/** + * Failure related to Enterprise Managed Users operations. + * + * @author Miguel Esteban Gutiérrez + */ +public class GHEnterpriseManagedUsersException extends GHIOException { + + /** + * The serial version UID of the exception. + */ + private static final long serialVersionUID = 1980051901L; + + /** + * The error that caused the exception. + */ + private final GHError error; + + /** + * Instantiates a new exception. + * + * @param message + * the message + * @param error + * the error that caused the exception + * @param cause + * the cause + */ + public GHEnterpriseManagedUsersException(final String message, final GHError error, final Throwable cause) { + super(message, cause); + this.error = error; + } + + /** + * Get the error that caused the exception. + * + * @return the error + */ + public GHError getError() { + return error; + } + +} diff --git a/src/main/java/org/kohsuke/github/GHError.java b/src/main/java/org/kohsuke/github/GHError.java new file mode 100644 index 0000000000..ed2e52502c --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHError.java @@ -0,0 +1,52 @@ +package org.kohsuke.github; + +import com.fasterxml.jackson.annotation.JsonProperty; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +import java.io.Serializable; +import java.net.URL; + +/** + * Represents an error from GitHub. + * + * @author Miguel Esteban Gutiérrez + */ +public class GHError implements Serializable { + + /** + * The serial version UID of the error + */ + private static final long serialVersionUID = 2008071901; + + /** + * The error message. + */ + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private String message; + + /** + * The URL to the documentation for the error. + */ + @JsonProperty("documentation_url") + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private String documentation; + + /** + * Get the error message. + * + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * Get the URL to the documentation for the error. + * + * @return the url + */ + public URL getDocumentationUrl() { + return GitHubClient.parseURL(documentation); + } + +} diff --git a/src/main/java/org/kohsuke/github/GHExternalGroup.java b/src/main/java/org/kohsuke/github/GHExternalGroup.java new file mode 100644 index 0000000000..aa3e229b20 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHExternalGroup.java @@ -0,0 +1,262 @@ +package org.kohsuke.github; + +import com.fasterxml.jackson.annotation.JsonProperty; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +import java.io.IOException; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +/** + * An external group available in a GitHub organization. + * + * @author Miguel Esteban Gutiérrez + */ +public class GHExternalGroup extends GitHubInteractiveObject implements Refreshable { + + /** + * A reference of a team linked to an external group + * + * @author Miguel Esteban Gutiérrez + */ + public static class GHLinkedTeam { + + /** + * The identifier of the team + */ + @JsonProperty("team_id") + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private long id; + + /** + * The name of the team + */ + @JsonProperty("team_name") + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private String name; + + /** + * Get the linked team identifier + * + * @return the id + */ + public long getId() { + return id; + } + + /** + * Get the linked team name + * + * @return the name + */ + public String getName() { + return name; + } + + } + + /** + * A reference of an external member linked to an external group + */ + public static class GHLinkedExternalMember { + + /** + * The internal user ID of the identity + */ + @JsonProperty("member_id") + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private long id; + + /** + * The handle/login for the user + */ + @JsonProperty("member_login") + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private String login; + + /** + * The user display name/profile name + */ + @JsonProperty("member_name") + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private String name; + + /** + * The email attached to the user + */ + @JsonProperty("member_email") + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private String email; + + /** + * Get the linked member identifier + * + * @return the id + */ + public long getId() { + return id; + } + + /** + * Get the linked member login + * + * @return the login + */ + public String getLogin() { + return login; + } + + /** + * Get the linked member name + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Get the linked member email + * + * @return the email + */ + public String getEmail() { + return email; + } + + } + + /** + * The identifier of the external group + */ + @JsonProperty("group_id") + + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private long id; + + /** + * The name of the external group + */ + @JsonProperty("group_name") + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private String name; + + /** + * The date when the group was last updated at + */ + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private String updatedAt; + + /** + * The teams linked to this group + */ + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private List teams; + + /** + * The external members linked to this group + */ + @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") + private List members; + + GHExternalGroup() { + this.teams = Collections.emptyList(); + this.members = Collections.emptyList(); + } + + private GHOrganization organization; + + /** + * Wrap up. + * + * @param owner + * the owner + */ + void wrapUp(final GHOrganization owner) { + this.organization = owner; + } + + /** + * Wrap up. + * + * @param root + * the root + */ + void wrapUp(final GitHub root) { // auto-wrapUp when organization is known from GET /orgs/{org}/external-groups + wrapUp(organization); + } + + /** + * Gets organization. + * + * @return the organization + * @throws IOException + * the io exception + */ + @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") + public GHOrganization getOrganization() throws IOException { + return organization; + } + + /** + * Get the external group id. + * + * @return the id + */ + public long getId() { + return id; + } + + /** + * Get the external group name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Get the external group last update date. + * + * @return the date + */ + public Date getUpdatedAt() { + return GitHubClient.parseDate(updatedAt); + } + + /** + * Get the teams linked to this group. + * + * @return the teams + */ + public List getTeams() { + return Collections.unmodifiableList(teams); + } + + /** + * Get the external members linked to this group. + * + * @return the external members + */ + public List getMembers() { + return Collections.unmodifiableList(members); + } + + /** + * Refresh. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Override + public void refresh() throws IOException { + root().createRequest().withUrlPath(api("")).fetchInto(this).wrapUp(root()); + } + + private String api(final String tail) { + return "/orgs/" + organization.getLogin() + "/external-group/" + getId() + tail; + } + +} diff --git a/src/main/java/org/kohsuke/github/GHExternalGroups.java b/src/main/java/org/kohsuke/github/GHExternalGroups.java new file mode 100644 index 0000000000..351c15f085 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHExternalGroups.java @@ -0,0 +1,28 @@ +package org.kohsuke.github; + +import java.util.Collections; +import java.util.List; + +/** + * A list of external groups. + * + * @author Miguel Esteban Gutiérrez + */ +public class GHExternalGroups { + + private List groups; + + GHExternalGroups() { + this.groups = Collections.emptyList(); + } + + /** + * Gets the groups. + * + * @return the groups + */ + public List getGroups() { + return Collections.unmodifiableList(groups); + } + +} diff --git a/src/main/java/org/kohsuke/github/GHExternalGroupsIterable.java b/src/main/java/org/kohsuke/github/GHExternalGroupsIterable.java new file mode 100644 index 0000000000..ab11f32687 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHExternalGroupsIterable.java @@ -0,0 +1,79 @@ +package org.kohsuke.github; + +import java.util.Iterator; + +import javax.annotation.Nonnull; + +// TODO: Auto-generated Javadoc + +/** + * Iterable for external group listing. + * + * @author Miguel Esteban Gutiérrez + */ +class GHExternalGroupsIterable extends PagedIterable { + + private static final GHExternalGroup[] GH_EXTERNAL_GROUPS = new GHExternalGroup[0]; + + private final GHOrganization owner; + + private final GitHubRequest request; + + private GHExternalGroups result; + + /** + * Instantiates a new GH external groups iterable. + * + * @param owner + * the owner + * @param requestBuilder + * the request builder + */ + GHExternalGroupsIterable(final GHOrganization owner, final GitHubRequest.Builder requestBuilder) { + this.owner = owner; + this.request = requestBuilder.build(); + } + + /** + * Iterator. + * + * @param pageSize + * the page size + * @return the paged iterator + */ + @Nonnull + @Override + public PagedIterator _iterator(int pageSize) { + return new PagedIterator<>( + adapt(GitHubPageIterator.create(owner.root().getClient(), GHExternalGroups.class, request, pageSize)), + null); + } + + /** + * Adapt. + * + * @param base + * the base + * @return the iterator + */ + private Iterator adapt(final Iterator base) { + return new Iterator() { + public boolean hasNext() { + try { + return base.hasNext(); + } catch (final GHException e) { + throw EnterpriseManagedSupport.forOrganization(owner).handleException(e).orElse(e); + } + } + + public GHExternalGroup[] next() { + GHExternalGroups v = base.next(); + if (result == null) { + result = v; + } + v.getGroups().forEach(g -> g.wrapUp(owner)); + return v.getGroups().toArray(GH_EXTERNAL_GROUPS); + } + }; + } +} diff --git a/src/main/java/org/kohsuke/github/GHNotExternallyManagedEnterpriseException.java b/src/main/java/org/kohsuke/github/GHNotExternallyManagedEnterpriseException.java new file mode 100644 index 0000000000..252413d0e2 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHNotExternallyManagedEnterpriseException.java @@ -0,0 +1,29 @@ +package org.kohsuke.github; + +/** + * Failure when the operation cannot be carried out because the resource is not part of an externally managed + * enterprise. + * + * @author Miguel Esteban Gutiérrez + */ +public class GHNotExternallyManagedEnterpriseException extends GHEnterpriseManagedUsersException { + + /** + * The serial version UID of the exception. + */ + private static final long serialVersionUID = 1978052201L; + + /** + * Instantiates a new exception. + * + * @param message + * the message + * @param error + * the error that caused the exception + * @param cause + * the cause + */ + public GHNotExternallyManagedEnterpriseException(final String message, final GHError error, final Throwable cause) { + super(message, error, cause); + } +} diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index e0a0eab88e..48a183d58c 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -188,6 +188,39 @@ public GHTeam getTeamBySlug(String slug) throws IOException { .wrapUp(this); } + /** + * List up all the external groups. + * + * @return the paged iterable + * @throws IOException + * the io exception + * @see documentation + */ + public PagedIterable listExternalGroups() throws IOException { + return listExternalGroups(null); + } + + /** + * List up all the external groups with a given text in their name + * + * @param displayName + * the text that must be part of the returned groups name + * @return the paged iterable + * @throws IOException + * the io exception + * @see documentation + */ + public PagedIterable listExternalGroups(final String displayName) throws IOException { + final Requester requester = root().createRequest() + .withUrlPath(String.format("/orgs/%s/external-groups", login)); + if (displayName != null) { + requester.with("display_name", displayName); + } + return new GHExternalGroupsIterable(this, requester); + } + /** * Member's role in an organization. */ diff --git a/src/test/java/org/kohsuke/github/EnterpriseManagedSupportTest.java b/src/test/java/org/kohsuke/github/EnterpriseManagedSupportTest.java new file mode 100644 index 0000000000..4d16012b40 --- /dev/null +++ b/src/test/java/org/kohsuke/github/EnterpriseManagedSupportTest.java @@ -0,0 +1,146 @@ +package org.kohsuke.github; + +import org.junit.Test; + +import java.io.IOException; +import java.util.Optional; + +import static org.hamcrest.Matchers.*; + +// TODO: Auto-generated Javadoc + +/** + * The Class EnterpriseManagedSupportTest. + */ +public class EnterpriseManagedSupportTest extends AbstractGitHubWireMockTest { + + private static final String NOT_PART_OF_EXTERNALLY_MANAGED_ENTERPRISE_ERROR = "{\"message\":\"This organization is not part of externally managed enterprise.\"," + + "\"documentation_url\": \"https://docs.github.com/rest/teams/external-groups#list-external-groups-in-an-organization\"}"; + + private static final String UNKNOWN_ERROR = "{\"message\":\"Unknown error\"," + + "\"documentation_url\": \"https://docs.github.com/rest/unknown#unknown\"}"; + + /** + * Test to ensure that only HttpExceptions are handled + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testIgnoreNonHttpException() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + final GHException inputCause = new GHException("Cause"); + final GHException inputException = new GHException("Test", inputCause); + + final Optional maybeException = EnterpriseManagedSupport.forOrganization(org) + .handleException(inputException); + + assertThat(maybeException.isPresent(), is(false)); + } + + /** + * Test to ensure that only BadRequests HttpExceptions are handled + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testIgnoreNonBadRequestExceptions() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + final HttpException inputCause = new HttpException(NOT_PART_OF_EXTERNALLY_MANAGED_ENTERPRISE_ERROR, + 404, + "Error", + org.getUrl().toString()); + final GHException inputException = new GHException("Test", inputCause); + + final Optional maybeException = EnterpriseManagedSupport.forOrganization(org) + .handleException(inputException); + + assertThat(maybeException.isPresent(), is(false)); + } + + /** + * Test to ensure that only BadRequests HttpExceptions with parseable JSON payload are handled + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testIgnoreBadRequestsWithUnparseableJson() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + final HttpException inputCause = new HttpException("Error", 400, "Error", org.getUrl().toString()); + final GHException inputException = new GHException("Test", inputCause); + + final Optional maybeException = EnterpriseManagedSupport.forOrganization(org) + .handleException(inputException); + + assertThat(maybeException.isPresent(), is(false)); + } + + /** + * Test to ensure that only BadRequests HttpExceptions with known error message are handled + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testIgnoreBadRequestsWithUnknownErrorMessage() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + final HttpException inputCause = new HttpException(UNKNOWN_ERROR, 400, "Error", org.getUrl().toString()); + final GHException inputException = new GHException("Test", inputCause); + + final Optional maybeException = EnterpriseManagedSupport.forOrganization(org) + .handleException(inputException); + + assertThat(maybeException.isPresent(), is(false)); + } + + /** + * Test to validate compliant use case. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testHandleEmbeddedNotPartOfExternallyManagedEnterpriseHttpException() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + final HttpException inputCause = new HttpException(NOT_PART_OF_EXTERNALLY_MANAGED_ENTERPRISE_ERROR, + 400, + "Error", + org.getUrl().toString()); + final GHException inputException = new GHException("Test", inputCause); + + final Optional maybeException = EnterpriseManagedSupport.forOrganization(org) + .handleException(inputException); + + assertThat(maybeException.isPresent(), is(true)); + + final GHException exception = maybeException.get(); + + assertThat(exception.getMessage(), + equalTo(EnterpriseManagedSupport.COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS)); + + final Throwable cause = exception.getCause(); + + assertThat(cause, instanceOf(GHNotExternallyManagedEnterpriseException.class)); + + final GHNotExternallyManagedEnterpriseException failure = (GHNotExternallyManagedEnterpriseException) cause; + + assertThat(failure.getCause(), is(inputCause)); + assertThat(failure.getMessage(), + equalTo(EnterpriseManagedSupport.COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS)); + + final GHError error = failure.getError(); + + assertThat(error, notNullValue()); + assertThat(error.getMessage(), + equalTo(EnterpriseManagedSupport.NOT_PART_OF_EXTERNALLY_MANAGED_ENTERPRISE_ERROR)); + assertThat(error.getDocumentationUrl(), notNullValue()); + } + +} diff --git a/src/test/java/org/kohsuke/github/ExternalGroupsTestingSupport.java b/src/test/java/org/kohsuke/github/ExternalGroupsTestingSupport.java new file mode 100644 index 0000000000..73cb162ec5 --- /dev/null +++ b/src/test/java/org/kohsuke/github/ExternalGroupsTestingSupport.java @@ -0,0 +1,99 @@ +package org.kohsuke.github; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeDiagnosingMatcher; + +import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +/** + * Supporting stuff for testing external groups + */ +class ExternalGroupsTestingSupport { + + static GHExternalGroup findExternalGroup(List groups, Predicate predicate) { + return groups.stream().filter(predicate).findFirst().orElseThrow(AssertionError::new); + } + + static Predicate hasName(String anObject) { + return g -> g.getName().equals(anObject); + } + + static List groupSummary(List groups) { + return collect(groups, ExternalGroupsTestingSupport::describeGroup); + } + + static List teamSummary(GHExternalGroup sut) { + return collect(sut.getTeams(), ExternalGroupsTestingSupport::describeTeam); + } + + static List membersSummary(GHExternalGroup sut) { + return collect(sut.getMembers(), ExternalGroupsTestingSupport::describeMember); + } + + private static List collect(List collection, Function transformation) { + return collection.stream().map(transformation).collect(Collectors.toList()); + } + + private static String describeGroup(GHExternalGroup g) { + return String.format("%d:%s", g.getId(), g.getName()); + } + + private static String describeTeam(GHExternalGroup.GHLinkedTeam t) { + return String.format("%d:%s", t.getId(), t.getName()); + } + + private static String describeMember(GHExternalGroup.GHLinkedExternalMember m) { + return String.format("%d:%s:%s:%s", m.getId(), m.getLogin(), m.getName(), m.getEmail()); + } + + static class Matchers { + + static Matcher isExternalGroupSummary() { + return new IsExternalGroupSummary(); + } + + } + + private static class IsExternalGroupSummary extends TypeSafeDiagnosingMatcher { + @Override + protected boolean matchesSafely(GHExternalGroup group, Description mismatchDescription) { + boolean result = true; + if (group == null) { + mismatchDescription.appendText("group is null"); + result = false; + } + if (group.getName() == null) { + mismatchDescription.appendText("name is null"); + result = false; + } + if (group.getUpdatedAt() == null) { + mismatchDescription.appendText("updated at is null"); + result = false; + } + if (group.getTeams() == null) { + mismatchDescription.appendText("teams is null"); + result = false; + } else if (!group.getTeams().isEmpty()) { + mismatchDescription.appendText("has teams"); + result = false; + } + if (group.getMembers() == null) { + mismatchDescription.appendText("members is null"); + result = false; + } else if (!group.getMembers().isEmpty()) { + mismatchDescription.appendText("has members"); + result = false; + } + return result; + } + + @Override + public void describeTo(Description description) { + description.appendText("is a summary"); + } + } +} diff --git a/src/test/java/org/kohsuke/github/GHExternalGroupTest.java b/src/test/java/org/kohsuke/github/GHExternalGroupTest.java new file mode 100644 index 0000000000..ef7e7ec7d8 --- /dev/null +++ b/src/test/java/org/kohsuke/github/GHExternalGroupTest.java @@ -0,0 +1,69 @@ +package org.kohsuke.github; + +import org.junit.Test; + +import java.io.IOException; +import java.util.List; + +import static org.hamcrest.Matchers.*; +import static org.kohsuke.github.ExternalGroupsTestingSupport.*; +import static org.kohsuke.github.ExternalGroupsTestingSupport.Matchers.*; + +// TODO: Auto-generated Javadoc + +/** + * The Class GHExternalGroupTest. + */ +public class GHExternalGroupTest extends AbstractGitHubWireMockTest { + + /** + * Test refresh bound external group. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testRefreshBoundExternalGroup() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + List groups = org.listExternalGroups().toList(); + final GHExternalGroup sut = findExternalGroup(groups, hasName("acme-developers")); + + assertThat(sut, isExternalGroupSummary()); + + sut.refresh(); + + assertThat(sut.getId(), equalTo(467431L)); + assertThat(sut.getName(), equalTo("acme-developers")); + assertThat(sut.getUpdatedAt(), notNullValue()); + + assertThat(sut.getMembers(), notNullValue()); + assertThat(membersSummary(sut), + hasItems("158311279:john-doe_acme:John Doe:john.doe@acme.corp", + "166731041:jane-doe_acme:Jane Doe:jane.doe@acme.corp")); + + assertThat(sut.getTeams(), notNullValue()); + assertThat(teamSummary(sut), hasItems("9891173:ACME-DEVELOPERS")); + } + + /** + * Test get organization. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testGetOrganization() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + List groups = org.listExternalGroups().toList(); + final GHExternalGroup sut = findExternalGroup(groups, hasName("acme-developers")); + + assertThat(sut, isExternalGroupSummary()); + + final GHOrganization other = sut.getOrganization(); + + assertThat(other, is(org)); + } + +} diff --git a/src/test/java/org/kohsuke/github/GHOrganizationTest.java b/src/test/java/org/kohsuke/github/GHOrganizationTest.java index 20cacfad52..e4ab1f80db 100644 --- a/src/test/java/org/kohsuke/github/GHOrganizationTest.java +++ b/src/test/java/org/kohsuke/github/GHOrganizationTest.java @@ -1,5 +1,6 @@ package org.kohsuke.github; +import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -12,6 +13,8 @@ import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertThrows; +import static org.kohsuke.github.ExternalGroupsTestingSupport.*; +import static org.kohsuke.github.ExternalGroupsTestingSupport.Matchers.*; // TODO: Auto-generated Javadoc @@ -29,6 +32,16 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest { /** The Constant TEAM_NAME_CREATE. */ public static final String TEAM_NAME_CREATE = "create-team-test"; + /** + * Enable response templating to allow support validating pagination of external groups + * + * @return the updated WireMock options + */ + @Override + protected WireMockConfiguration getWireMockOptions() { + return super.getWireMockOptions().extensions(templating.newResponseTransformer()); + } + /** * Clean up team. * @@ -578,4 +591,107 @@ public void testEnableOrganizationProjects() throws IOException { // Assert assertThat(org.areOrganizationProjectsEnabled(), is(false)); } + + /** + * Test list external groups without pagination. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testListExternalGroupsWithoutPagination() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + List groups = org.listExternalGroups().toList(); + + assertThat(groups, notNullValue()); + // In case more are added in the future + assertThat(groups.size(), greaterThanOrEqualTo(4)); + assertThat(groupSummary(groups), + hasItems("467430:acme-asset-owners", + "467431:acme-developers", + "467432:acme-product-owners", + "467433:acme-technical-leads")); + + groups.forEach(group -> assertThat(group, isExternalGroupSummary())); + + // We are doing one request to get the organization and one to get the external groups + assertThat(mockGitHub.getRequestCount(), greaterThanOrEqualTo(2)); + } + + /** + * Test list external groups with pagination. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testListExternalGroupsWithPagination() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + List groups = org.listExternalGroups().withPageSize(2).toList(); + + assertThat(groups, notNullValue()); + // In case more are added in the future + assertThat(groups.size(), greaterThanOrEqualTo(4)); + assertThat(groupSummary(groups), + hasItems("467430:acme-asset-owners", + "467431:acme-developers", + "467432:acme-product-owners", + "467433:acme-technical-leads")); + + groups.forEach(group -> assertThat(group, isExternalGroupSummary())); + + // We are doing one request to get the organization and two to traverse the two pages + assertThat(mockGitHub.getRequestCount(), greaterThanOrEqualTo(3)); + } + + /** + * Test list external groups with name filtering. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testListExternalGroupsWithFilter() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + List groups = org.listExternalGroups("acme").toList(); + + assertThat(groups, notNullValue()); + // In case more are added in the future + assertThat(groups.size(), greaterThanOrEqualTo(4)); + assertThat(groupSummary(groups), + hasItems("467430:acme-asset-owners", + "467431:acme-developers", + "467432:acme-product-owners", + "467433:acme-technical-leads")); + + groups.forEach(group -> assertThat(group, isExternalGroupSummary())); + } + + /** + * Test list external groups without pagination for non enterprise managed organization. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testListExternalGroupsNotEnterpriseManagedOrganization() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + final GHNotExternallyManagedEnterpriseException failure = assertThrows( + GHNotExternallyManagedEnterpriseException.class, + () -> org.listExternalGroups().toList()); + + assertThat(failure.getMessage(), equalTo("Could not retrieve organization external groups")); + + final GHError error = failure.getError(); + + assertThat(error, notNullValue()); + assertThat(error.getMessage(), + equalTo(EnterpriseManagedSupport.NOT_PART_OF_EXTERNALLY_MANAGED_ENTERPRISE_ERROR)); + assertThat(error.getDocumentationUrl(), notNullValue()); + } + } diff --git a/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleEmbeddedNotPartOfExternallyManagedEnterpriseHttpException/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleEmbeddedNotPartOfExternallyManagedEnterpriseHttpException/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleEmbeddedNotPartOfExternallyManagedEnterpriseHttpException/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleEmbeddedNotPartOfExternallyManagedEnterpriseHttpException/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleEmbeddedNotPartOfExternallyManagedEnterpriseHttpException/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleEmbeddedNotPartOfExternallyManagedEnterpriseHttpException/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnknownErrorMessage/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnknownErrorMessage/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnknownErrorMessage/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnknownErrorMessage/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnknownErrorMessage/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnknownErrorMessage/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnparseableJson/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnparseableJson/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnparseableJson/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnparseableJson/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnparseableJson/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreBadRequestsWithUnparseableJson/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonBadRequestExceptions/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonBadRequestExceptions/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonBadRequestExceptions/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonBadRequestExceptions/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonBadRequestExceptions/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonBadRequestExceptions/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonHttpException/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonHttpException/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonHttpException/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonHttpException/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonHttpException/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testIgnoreNonHttpException/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/__files/2-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/__files/2-o_h_external-groups.json new file mode 100644 index 0000000000..6ca002d837 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/__files/2-o_h_external-groups.json @@ -0,0 +1,24 @@ +{ + "groups": [ + { + "group_id": 467430, + "group_name": "acme-asset-owners", + "updated_at": "2023-09-13T16:41:29Z" + }, + { + "group_id": 467431, + "group_name": "acme-developers", + "updated_at": "2023-09-13T16:41:28Z" + }, + { + "group_id": 467432, + "group_name": "acme-product-owners", + "updated_at": "2023-09-13T16:41:27Z" + }, + { + "group_id": 467433, + "group_name": "acme-technical-leads", + "updated_at": "2023-09-13T16:41:28Z" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..3109f17dca --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,50 @@ +{ + "name": "orgs_hub4j-test-org", + "scenarioName": "Refresh", + "requiredScenarioState": "Started", + "newScenarioState": "OrgRetrieved", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/mappings/2-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/mappings/2-o_h_external-groups.json new file mode 100644 index 0000000000..4cf7a58444 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testGetOrganization/mappings/2-o_h_external-groups.json @@ -0,0 +1,49 @@ +{ + "name": "orgs_hub4j-test-org_external-groups", + "scenarioName": "Refresh", + "requiredScenarioState": "OrgRetrieved", + "newScenarioState": "ExternalGroupsRetrieved", + "request": { + "url": "/orgs/hub4j-test-org/external-groups", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:06 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4983", + "X-RateLimit-Reset": "1582644475", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"631de12e6bc586863218257765331a70\"", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF8C:78624D:5E553201" + } + }, + "uuid": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/__files/2-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/__files/2-o_h_external-groups.json new file mode 100644 index 0000000000..6ca002d837 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/__files/2-o_h_external-groups.json @@ -0,0 +1,24 @@ +{ + "groups": [ + { + "group_id": 467430, + "group_name": "acme-asset-owners", + "updated_at": "2023-09-13T16:41:29Z" + }, + { + "group_id": 467431, + "group_name": "acme-developers", + "updated_at": "2023-09-13T16:41:28Z" + }, + { + "group_id": 467432, + "group_name": "acme-product-owners", + "updated_at": "2023-09-13T16:41:27Z" + }, + { + "group_id": 467433, + "group_name": "acme-technical-leads", + "updated_at": "2023-09-13T16:41:28Z" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/__files/3-o_h_external-group_467431.json b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/__files/3-o_h_external-group_467431.json new file mode 100644 index 0000000000..43bc55fc41 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/__files/3-o_h_external-group_467431.json @@ -0,0 +1,25 @@ +{ + "group_id": 467431, + "group_name": "acme-developers", + "updated_at": "2023-09-13T16:41:28Z", + "members": [ + { + "member_id": 158311279, + "member_login": "john-doe_acme", + "member_name": "John Doe", + "member_email": "john.doe@acme.corp" + }, + { + "member_id": 166731041, + "member_login": "jane-doe_acme", + "member_name": "Jane Doe", + "member_email": "jane.doe@acme.corp" + } + ], + "teams": [ + { + "team_id": 9891173, + "team_name": "ACME-DEVELOPERS" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/mappings/2-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/mappings/2-o_h_external-groups.json new file mode 100644 index 0000000000..56f284f32d --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/mappings/2-o_h_external-groups.json @@ -0,0 +1,47 @@ +{ + "id": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "name": "orgs_hub4j-test-org_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/external-groups", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:06 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4983", + "X-RateLimit-Reset": "1582644475", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"631de12e6bc586863218257765331a70\"", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF8C:78624D:5E553201" + } + }, + "uuid": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/mappings/3-o_h_external-group_467431.json b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/mappings/3-o_h_external-group_467431.json new file mode 100644 index 0000000000..9ebe4dac3e --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHExternalGroupTest/wiremock/testRefreshBoundExternalGroup/mappings/3-o_h_external-group_467431.json @@ -0,0 +1,47 @@ +{ + "id": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "name": "orgs_hub4j-test-org_external-group_467431", + "request": { + "url": "/orgs/hub4j-test-org/external-group/467431", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "3-o_h_external-group_467431.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:06 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4983", + "X-RateLimit-Reset": "1582644475", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"631de12e6bc586863218257765331a70\"", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF8C:78624D:5E553201" + } + }, + "uuid": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/__files/2-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/__files/2-o_h_external-groups.json new file mode 100644 index 0000000000..ef5f4606c4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/__files/2-o_h_external-groups.json @@ -0,0 +1,4 @@ +{ + "message": "This organization is not part of externally managed enterprise.", + "documentation_url": "https://docs.github.com/rest/teams/external-groups#list-external-groups-in-an-organization" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/mappings/2-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/mappings/2-o_h_external-groups.json new file mode 100644 index 0000000000..3d1a147da7 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsNotEnterpriseManagedOrganization/mappings/2-o_h_external-groups.json @@ -0,0 +1,47 @@ +{ + "id": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "name": "orgs_hub4j-test-org_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/external-groups", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 400, + "bodyFileName": "2-o_h_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:06 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "400 Bad Request", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4983", + "X-RateLimit-Reset": "1582644475", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"631de12e6bc586863218257765331a70\"", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF8C:78624D:5E553201" + } + }, + "uuid": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/__files/2-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/__files/2-o_h_external-groups.json new file mode 100644 index 0000000000..6ca002d837 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/__files/2-o_h_external-groups.json @@ -0,0 +1,24 @@ +{ + "groups": [ + { + "group_id": 467430, + "group_name": "acme-asset-owners", + "updated_at": "2023-09-13T16:41:29Z" + }, + { + "group_id": 467431, + "group_name": "acme-developers", + "updated_at": "2023-09-13T16:41:28Z" + }, + { + "group_id": 467432, + "group_name": "acme-product-owners", + "updated_at": "2023-09-13T16:41:27Z" + }, + { + "group_id": 467433, + "group_name": "acme-technical-leads", + "updated_at": "2023-09-13T16:41:28Z" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/mappings/2-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/mappings/2-o_h_external-groups.json new file mode 100644 index 0000000000..87ccb5c729 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithFilter/mappings/2-o_h_external-groups.json @@ -0,0 +1,47 @@ +{ + "id": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "name": "orgs_hub4j-test-org_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/external-groups?display_name=acme", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:06 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4983", + "X-RateLimit-Reset": "1582644475", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"631de12e6bc586863218257765331a70\"", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF8C:78624D:5E553201" + } + }, + "uuid": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/__files/2-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/__files/2-o_h_external-groups.json new file mode 100644 index 0000000000..cb56150f56 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/__files/2-o_h_external-groups.json @@ -0,0 +1,14 @@ +{ + "groups": [ + { + "group_id": 467430, + "group_name": "acme-asset-owners", + "updated_at": "2023-09-13T16:41:29Z" + }, + { + "group_id": 467431, + "group_name": "acme-developers", + "updated_at": "2023-09-13T16:41:28Z" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/__files/3-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/__files/3-o_h_external-groups.json new file mode 100644 index 0000000000..a0ae5bb160 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/__files/3-o_h_external-groups.json @@ -0,0 +1,14 @@ +{ + "groups": [ + { + "group_id": 467432, + "group_name": "acme-product-owners", + "updated_at": "2023-09-13T16:41:27Z" + }, + { + "group_id": 467433, + "group_name": "acme-technical-leads", + "updated_at": "2023-09-13T16:41:28Z" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/mappings/2-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/mappings/2-o_h_external-groups.json new file mode 100644 index 0000000000..535a742003 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/mappings/2-o_h_external-groups.json @@ -0,0 +1,49 @@ +{ + "id": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "name": "orgs_hub4j-test-org_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/external-groups?per_page=2", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:06 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4983", + "X-RateLimit-Reset": "1582644475", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"631de12e6bc586863218257765331a70\"", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF8C:78624D:5E553201", + "Link": "; rel=\"next\", ; rel=\"last\"" + }, + "transformers": ["response-template"] + }, + "uuid": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/mappings/3-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/mappings/3-o_h_external-groups.json new file mode 100644 index 0000000000..1048f58184 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithPagination/mappings/3-o_h_external-groups.json @@ -0,0 +1,47 @@ +{ + "id": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "name": "orgs_hub4j-test-org_members", + "request": { + "url": "/orgs/hub4j-test-org/external-groups?per_page=2&page=2", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "3-o_h_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:06 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4983", + "X-RateLimit-Reset": "1582644475", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"631de12e6bc586863218257765331a70\"", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF8C:78624D:5E553201" + } + }, + "uuid": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/__files/2-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/__files/2-o_h_external-groups.json new file mode 100644 index 0000000000..6ca002d837 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/__files/2-o_h_external-groups.json @@ -0,0 +1,24 @@ +{ + "groups": [ + { + "group_id": 467430, + "group_name": "acme-asset-owners", + "updated_at": "2023-09-13T16:41:29Z" + }, + { + "group_id": 467431, + "group_name": "acme-developers", + "updated_at": "2023-09-13T16:41:28Z" + }, + { + "group_id": 467432, + "group_name": "acme-product-owners", + "updated_at": "2023-09-13T16:41:27Z" + }, + { + "group_id": 467433, + "group_name": "acme-technical-leads", + "updated_at": "2023-09-13T16:41:28Z" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/mappings/2-o_h_external-groups.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/mappings/2-o_h_external-groups.json new file mode 100644 index 0000000000..56f284f32d --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testListExternalGroupsWithoutPagination/mappings/2-o_h_external-groups.json @@ -0,0 +1,47 @@ +{ + "id": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "name": "orgs_hub4j-test-org_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/external-groups", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:06 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4983", + "X-RateLimit-Reset": "1582644475", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"631de12e6bc586863218257765331a70\"", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF8C:78624D:5E553201" + } + }, + "uuid": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file From 102e114bd3a727735b33d315a03f0f3fade903e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Esteban=20Guti=C3=A9rrez?= Date: Mon, 8 Apr 2024 17:25:40 +0200 Subject: [PATCH 02/11] feat: Get an external group in an organization --- .../org/kohsuke/github/GHExternalGroup.java | 3 +- .../org/kohsuke/github/GHOrganization.java | 24 ++++++++++ .../kohsuke/github/GHOrganizationTest.java | 43 +++++++++++++++++ .../__files/1-orgs_hub4j-test-org.json | 41 ++++++++++++++++ .../__files/2-o_h_external-group_467431.json | 25 ++++++++++ .../mappings/1-orgs_hub4j-test-org.json | 48 +++++++++++++++++++ .../mappings/2-o_h_external-group_467431.json | 47 ++++++++++++++++++ .../__files/1-orgs_hub4j-test-org.json | 41 ++++++++++++++++ .../__files/2-o_h_external-group_12345.json | 4 ++ .../mappings/1-orgs_hub4j-test-org.json | 48 +++++++++++++++++++ .../mappings/2-o_h_external-group_12345.json | 47 ++++++++++++++++++ 11 files changed, 370 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/__files/2-o_h_external-group_467431.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/mappings/2-o_h_external-group_467431.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/__files/2-o_h_external-group_12345.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/mappings/2-o_h_external-group_12345.json diff --git a/src/main/java/org/kohsuke/github/GHExternalGroup.java b/src/main/java/org/kohsuke/github/GHExternalGroup.java index aa3e229b20..01b3f84241 100644 --- a/src/main/java/org/kohsuke/github/GHExternalGroup.java +++ b/src/main/java/org/kohsuke/github/GHExternalGroup.java @@ -173,8 +173,9 @@ public String getEmail() { * @param owner * the owner */ - void wrapUp(final GHOrganization owner) { + GHExternalGroup wrapUp(final GHOrganization owner) { this.organization = owner; + return this; } /** diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 48a183d58c..3ab3d53b20 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -221,6 +221,30 @@ public PagedIterable listExternalGroups(final String displayNam return new GHExternalGroupsIterable(this, requester); } + /** + * Gets a single external group by ID. + * + * @param groupId + * id of the external group that we want to query for + * @return the external group + * @throws IOException + * the io exception + * @see documentation + */ + public GHExternalGroup getExternalGroup(final long groupId) throws IOException { + try { + return root().createRequest() + .withUrlPath(String.format("/orgs/%s/external-group/%d", login, groupId)) + .fetch(GHExternalGroup.class) + .wrapUp(this); + } catch (final HttpException e) { + throw EnterpriseManagedSupport.forOrganization(this) + .handleException(e, "Could not retrieve organization external group") + .orElse(e); + } + } + /** * Member's role in an organization. */ diff --git a/src/test/java/org/kohsuke/github/GHOrganizationTest.java b/src/test/java/org/kohsuke/github/GHOrganizationTest.java index e4ab1f80db..6cd384e09f 100644 --- a/src/test/java/org/kohsuke/github/GHOrganizationTest.java +++ b/src/test/java/org/kohsuke/github/GHOrganizationTest.java @@ -694,4 +694,47 @@ public void testListExternalGroupsNotEnterpriseManagedOrganization() throws IOEx assertThat(error.getDocumentationUrl(), notNullValue()); } + /** + * Test get external group + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testGetExternalGroup() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + GHExternalGroup group = org.getExternalGroup(467431L); + + assertThat(group, not(isExternalGroupSummary())); + + assertThat(group.getId(), equalTo(467431L)); + assertThat(group.getName(), equalTo("acme-developers")); + assertThat(group.getUpdatedAt(), notNullValue()); + + assertThat(group.getMembers(), notNullValue()); + assertThat(membersSummary(group), + hasItems("158311279:john-doe_acme:John Doe:john.doe@acme.corp", + "166731041:jane-doe_acme:Jane Doe:jane.doe@acme.corp")); + + assertThat(group.getTeams(), notNullValue()); + assertThat(teamSummary(group), hasItems("9891173:ACME-DEVELOPERS")); + } + + /** + * Test get external group for not enterprise managed organization + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testGetExternalGroupNotEnterpriseManagedOrganization() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + final GHIOException failure = assertThrows(GHNotExternallyManagedEnterpriseException.class, + () -> org.getExternalGroup(12345)); + + assertThat(failure.getMessage(), equalTo("Could not retrieve organization external group")); + } + } diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/__files/2-o_h_external-group_467431.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/__files/2-o_h_external-group_467431.json new file mode 100644 index 0000000000..43bc55fc41 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/__files/2-o_h_external-group_467431.json @@ -0,0 +1,25 @@ +{ + "group_id": 467431, + "group_name": "acme-developers", + "updated_at": "2023-09-13T16:41:28Z", + "members": [ + { + "member_id": 158311279, + "member_login": "john-doe_acme", + "member_name": "John Doe", + "member_email": "john.doe@acme.corp" + }, + { + "member_id": 166731041, + "member_login": "jane-doe_acme", + "member_name": "Jane Doe", + "member_email": "jane.doe@acme.corp" + } + ], + "teams": [ + { + "team_id": 9891173, + "team_name": "ACME-DEVELOPERS" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/mappings/2-o_h_external-group_467431.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/mappings/2-o_h_external-group_467431.json new file mode 100644 index 0000000000..ca99942d4f --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroup/mappings/2-o_h_external-group_467431.json @@ -0,0 +1,47 @@ +{ + "id": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "name": "orgs_hub4j-test-org_external-group_467431", + "request": { + "url": "/orgs/hub4j-test-org/external-group/467431", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_external-group_467431.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:06 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4983", + "X-RateLimit-Reset": "1582644475", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"631de12e6bc586863218257765331a70\"", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF8C:78624D:5E553201" + } + }, + "uuid": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/__files/2-o_h_external-group_12345.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/__files/2-o_h_external-group_12345.json new file mode 100644 index 0000000000..ef5f4606c4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/__files/2-o_h_external-group_12345.json @@ -0,0 +1,4 @@ +{ + "message": "This organization is not part of externally managed enterprise.", + "documentation_url": "https://docs.github.com/rest/teams/external-groups#list-external-groups-in-an-organization" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/mappings/2-o_h_external-group_12345.json b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/mappings/2-o_h_external-group_12345.json new file mode 100644 index 0000000000..7367c3fa17 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHOrganizationTest/wiremock/testGetExternalGroupNotEnterpriseManagedOrganization/mappings/2-o_h_external-group_12345.json @@ -0,0 +1,47 @@ +{ + "id": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "name": "orgs_hub4j-test-org_external-group_12345", + "request": { + "url": "/orgs/hub4j-test-org/external-group/12345", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 400, + "bodyFileName": "2-o_h_external-group_12345.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:06 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4983", + "X-RateLimit-Reset": "1582644475", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"631de12e6bc586863218257765331a70\"", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF8C:78624D:5E553201" + } + }, + "uuid": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file From 33065b9e24ae1c1c58030f8413f0bac966180e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Esteban=20Guti=C3=A9rrez?= Date: Mon, 8 Apr 2024 17:28:33 +0200 Subject: [PATCH 03/11] feat: List a connection between an external group and a team --- .../github/EnterpriseManagedSupport.java | 3 + src/main/java/org/kohsuke/github/GHTeam.java | 39 +++++++++-- ...eamCannotBeExternallyManagedException.java | 28 ++++++++ .../github/EnterpriseManagedSupportTest.java | 38 ++++++++++ .../java/org/kohsuke/github/GHTeamTest.java | 69 +++++++++++++++++-- .../__files/1-orgs_hub4j-test-org.json | 41 +++++++++++ .../mappings/1-orgs_hub4j-test-org.json | 48 +++++++++++++ .../__files/1-orgs_hub4j-test-org.json | 55 +++++++++++++++ .../__files/2-o_h_t_acme-developers.json | 49 +++++++++++++ ...o_h_t_acme-developers_external-groups.json | 9 +++ .../mappings/1-orgs_hub4j-test-org.json | 47 +++++++++++++ .../mappings/2-o_h_t_acme-developers.json | 47 +++++++++++++ ...o_h_t_acme-developers_external-groups.json | 46 +++++++++++++ .../__files/1-orgs_hub4j-test-org.json | 55 +++++++++++++++ .../__files/2-o_h_t_acme-developers.json | 49 +++++++++++++ ...o_h_t_acme-developers_external-groups.json | 4 ++ .../mappings/1-orgs_hub4j-test-org.json | 47 +++++++++++++ .../mappings/2-o_h_t_acme-developers.json | 47 +++++++++++++ ...o_h_t_acme-developers_external-groups.json | 46 +++++++++++++ .../__files/1-orgs_hub4j-test-org.json | 55 +++++++++++++++ .../__files/2-o_h_t_acme-developers.json | 49 +++++++++++++ ...o_h_t_acme-developers_external-groups.json | 4 ++ .../mappings/1-orgs_hub4j-test-org.json | 47 +++++++++++++ .../mappings/2-o_h_t_acme-developers.json | 47 +++++++++++++ ...o_h_t_acme-developers_external-groups.json | 46 +++++++++++++ 25 files changed, 1004 insertions(+), 11 deletions(-) create mode 100644 src/main/java/org/kohsuke/github/GHTeamCannotBeExternallyManagedException.java create mode 100644 src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleTeamCannotBeExternallyManagedHttpException/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleTeamCannotBeExternallyManagedHttpException/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/__files/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/__files/3-o_h_t_acme-developers_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/mappings/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/mappings/3-o_h_t_acme-developers_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/__files/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/__files/3-o_h_t_acme-developers_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/mappings/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/mappings/3-o_h_t_acme-developers_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/__files/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/__files/3-o_h_t_acme-developers_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/mappings/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/mappings/3-o_h_t_acme-developers_external-groups.json diff --git a/src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java b/src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java index 379331fb3c..a8b4745529 100644 --- a/src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java +++ b/src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java @@ -16,6 +16,7 @@ class EnterpriseManagedSupport { static final String COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS = "Could not retrieve organization external groups"; static final String NOT_PART_OF_EXTERNALLY_MANAGED_ENTERPRISE_ERROR = "This organization is not part of externally managed enterprise."; + static final String TEAM_CANNOT_BE_EXTERNALLY_MANAGED_ERROR = "This team cannot be externally managed since it has explicit members."; private static final Logger LOGGER = Logger.getLogger(EnterpriseManagedSupport.class.getName()); @@ -34,6 +35,8 @@ Optional handleException(final HttpException he, final String sce .readValue(responseMessage); if (NOT_PART_OF_EXTERNALLY_MANAGED_ENTERPRISE_ERROR.equals(error.getMessage())) { return Optional.of(new GHNotExternallyManagedEnterpriseException(scenario, error, he)); + } else if (TEAM_CANNOT_BE_EXTERNALLY_MANAGED_ERROR.equals(error.getMessage())) { + return Optional.of(new GHTeamCannotBeExternallyManagedException(scenario, error, he)); } } catch (final JsonProcessingException e) { // We can ignore it diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index 89bae4336a..eb7601c182 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -6,11 +6,7 @@ import java.io.IOException; import java.net.URL; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.TreeMap; +import java.util.*; import javax.annotation.Nonnull; @@ -23,6 +19,12 @@ * @author Kohsuke Kawaguchi */ public class GHTeam extends GHObject implements Refreshable { + + /** + * Path for external group-related operations + */ + private static final String EXTERNAL_GROUPS = "/external-groups"; + private String html_url; private String name; private String permission; @@ -409,6 +411,10 @@ private String api(String tail) { return "/organizations/" + organization.getId() + "/team/" + getId() + tail; } + private String publicApi(String tail) throws IOException { + return "/orgs/" + getOrganization().login + "/teams/" + getSlug() + tail; + } + /** * Begins the creation of a new instance. * @@ -424,6 +430,29 @@ public GHDiscussion.Creator createDiscussion(String title) throws IOException { return GHDiscussion.create(this).title(title); } + /** + * Get the external groups connected to the team + * + * @return the external groups + * @throws IOException + * the io exception + * @see documentation + */ + public List getExternalGroups() throws IOException { + try { + return root().createRequest() + .method("GET") + .withUrlPath(publicApi(EXTERNAL_GROUPS)) + .fetch(GHExternalGroups.class) + .getGroups(); + } catch (final HttpException e) { + throw EnterpriseManagedSupport.forOrganization(getOrganization()) + .handleException(e, "Could not retrieve team external groups") + .orElse(e); + } + } + /** * Gets organization. * diff --git a/src/main/java/org/kohsuke/github/GHTeamCannotBeExternallyManagedException.java b/src/main/java/org/kohsuke/github/GHTeamCannotBeExternallyManagedException.java new file mode 100644 index 0000000000..42ca81c764 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHTeamCannotBeExternallyManagedException.java @@ -0,0 +1,28 @@ +package org.kohsuke.github; + +/** + * Failure when the operation cannot be carried out because the team cannot be externally managed. + * + * @author Kohsuke Kawaguchi + */ +public class GHTeamCannotBeExternallyManagedException extends GHEnterpriseManagedUsersException { + + /** + * The serial version UID of the exception. + */ + private static final long serialVersionUID = 2013101301L; + + /** + * Instantiates a new exception. + * + * @param message + * the message + * @param error + * the error that caused the exception + * @param cause + * the cause + */ + public GHTeamCannotBeExternallyManagedException(final String message, final GHError error, final Throwable cause) { + super(message, error, cause); + } +} diff --git a/src/test/java/org/kohsuke/github/EnterpriseManagedSupportTest.java b/src/test/java/org/kohsuke/github/EnterpriseManagedSupportTest.java index 4d16012b40..60fd797f46 100644 --- a/src/test/java/org/kohsuke/github/EnterpriseManagedSupportTest.java +++ b/src/test/java/org/kohsuke/github/EnterpriseManagedSupportTest.java @@ -20,6 +20,9 @@ public class EnterpriseManagedSupportTest extends AbstractGitHubWireMockTest { private static final String UNKNOWN_ERROR = "{\"message\":\"Unknown error\"," + "\"documentation_url\": \"https://docs.github.com/rest/unknown#unknown\"}"; + private static final String TEAM_CANNOT_BE_EXTERNALLY_MANAGED_ERROR = "{\"message\":\"This team cannot be externally managed since it has explicit members.\"," + + "\"documentation_url\": \"https://docs.github.com/rest/teams/external-groups#list-a-connection-between-an-external-group-and-a-team\"}"; + /** * Test to ensure that only HttpExceptions are handled * @@ -143,4 +146,39 @@ public void testHandleEmbeddedNotPartOfExternallyManagedEnterpriseHttpException( assertThat(error.getDocumentationUrl(), notNullValue()); } + /** + * Test to validate another compliant use case. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testHandleTeamCannotBeExternallyManagedHttpException() throws IOException { + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + + final HttpException inputException = new HttpException(TEAM_CANNOT_BE_EXTERNALLY_MANAGED_ERROR, + 400, + "Error", + org.getUrl().toString()); + + final Optional maybeException = EnterpriseManagedSupport.forOrganization(org) + .handleException(inputException, "Scenario"); + + assertThat(maybeException.isPresent(), is(true)); + + final GHIOException exception = maybeException.get(); + + assertThat(exception.getMessage(), equalTo("Scenario")); + assertThat(exception.getCause(), is(inputException)); + + assertThat(exception, instanceOf(GHTeamCannotBeExternallyManagedException.class)); + + final GHTeamCannotBeExternallyManagedException failure = (GHTeamCannotBeExternallyManagedException) exception; + + final GHError error = failure.getError(); + + assertThat(error, notNullValue()); + assertThat(error.getMessage(), equalTo(EnterpriseManagedSupport.TEAM_CANNOT_BE_EXTERNALLY_MANAGED_ERROR)); + assertThat(error.getDocumentationUrl(), notNullValue()); + } } diff --git a/src/test/java/org/kohsuke/github/GHTeamTest.java b/src/test/java/org/kohsuke/github/GHTeamTest.java index b1db8ddf0f..1b0794285f 100644 --- a/src/test/java/org/kohsuke/github/GHTeamTest.java +++ b/src/test/java/org/kohsuke/github/GHTeamTest.java @@ -8,12 +8,11 @@ import java.util.List; import java.util.Set; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.hasItems; +import static org.junit.Assert.assertThrows; +import static org.kohsuke.github.ExternalGroupsTestingSupport.Matchers.isExternalGroupSummary; +import static org.kohsuke.github.ExternalGroupsTestingSupport.groupSummary; // TODO: Auto-generated Javadoc /** @@ -263,4 +262,62 @@ public void addRemoveMember() throws IOException { } } } + + /** + * Test get external groups. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testGetExternalGroups() throws IOException { + String teamSlug = "acme-developers"; + + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + GHTeam team = org.getTeamBySlug(teamSlug); + final List groups = team.getExternalGroups(); + + assertThat(groups, notNullValue()); + assertThat(groups.size(), equalTo(1)); + assertThat(groupSummary(groups), hasItems("467431:acme-developers")); + + groups.forEach(group -> assertThat(group, isExternalGroupSummary())); + } + + /** + * Test get external groups from not enterprise managed organization. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testGetExternalGroupsNotEnterpriseManagedOrganization() throws IOException { + String teamSlug = "acme-developers"; + + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + GHTeam team = org.getTeamBySlug(teamSlug); + + final GHIOException failure = assertThrows(GHNotExternallyManagedEnterpriseException.class, + () -> team.getExternalGroups()); + assertThat(failure.getMessage(), equalTo("Could not retrieve team external groups")); + } + + /** + * Test get external groups from team that cannot be externally managed. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testGetExternalGroupsTeamCannotBeExternallyManaged() throws IOException { + String teamSlug = "acme-developers"; + + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + GHTeam team = org.getTeamBySlug(teamSlug); + + final GHIOException failure = assertThrows(GHTeamCannotBeExternallyManagedException.class, + () -> team.getExternalGroups()); + assertThat(failure.getMessage(), equalTo("Could not retrieve team external groups")); + } + } diff --git a/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleTeamCannotBeExternallyManagedHttpException/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleTeamCannotBeExternallyManagedHttpException/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..731f707098 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleTeamCannotBeExternallyManagedHttpException/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 11, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 147, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 12, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleTeamCannotBeExternallyManagedHttpException/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleTeamCannotBeExternallyManagedHttpException/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..88d93869d4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/EnterpriseManagedSupportTest/wiremock/testHandleTeamCannotBeExternallyManagedHttpException/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:05 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4984", + "X-RateLimit-Reset": "1582644474", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"712644daa44df3089a27d6ef60979929\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF7E:786110:5E5531FF" + } + }, + "uuid": "3ed48345-73c2-4d8e-9c65-f4a140356d59", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..162ceb1c73 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,55 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization", + "total_private_repos": 3, + "owned_private_repos": 3, + "private_gists": 0, + "disk_usage": 11979, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "members_allowed_repository_creation_type": "none", + "members_can_create_public_repositories": false, + "members_can_create_private_repositories": false, + "members_can_create_internal_repositories": false, + "members_can_create_pages": true, + "members_can_fork_private_repositories": false, + "members_can_create_public_pages": true, + "members_can_create_private_pages": true, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 10000, + "filled_seats": 35, + "seats": 3 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/__files/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/__files/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..7642889a58 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/__files/2-o_h_t_acme-developers.json @@ -0,0 +1,49 @@ +{ + "name": "acme-developers", + "id": 34519961, + "node_id": "MDQ6VGVhbTM0NTE5OTY=", + "slug": "acme-developers", + "description": "Updated by API TestModified", + "privacy": "closed", + "url": "https://api.github.com/organizations/7544739/team/3451996", + "html_url": "https://github.com/orgs/hub4j-test-org/teams/acme-developers", + "members_url": "https://api.github.com/organizations/7544739/team/3451996/members{/member}", + "repositories_url": "https://api.github.com/organizations/7544739/team/3451996/repos", + "permission": "pull", + "created_at": "2019-10-03T21:46:12Z", + "updated_at": "2022-03-04T10:36:59Z", + "members_count": 1, + "repos_count": 1, + "organization": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization" + }, + "parent": null +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/__files/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/__files/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..09e99b6517 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/__files/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,9 @@ +{ + "groups": [ + { + "group_id": 467431, + "group_name": "acme-developers", + "updated_at": "2023-09-13T16:41:28Z" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..18868d99d1 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,47 @@ +{ + "id": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:36:59 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"861b38147d37bd59e507771e76ec048def20dd6e5ac5b75aceb01c8b9f0ef4f5\"", + "Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4990", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "10", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F4:5E65:1A3BC41:1AAFE9E:6221EBCB" + } + }, + "uuid": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/mappings/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/mappings/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..1f5c8081f9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/mappings/2-o_h_t_acme-developers.json @@ -0,0 +1,47 @@ +{ + "id": "e688e202-0c96-4144-b415-cb16f315d478", + "name": "orgs_hub4j-test-org_teams_acme-developers", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_t_acme-developers.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1fbce0cbfea113fefff1877b37929ef1d7cb9c8989a5b223df3e9ea092502191\"", + "Last-Modified": "Fri, 04 Mar 2022 10:36:59 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4989", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "11", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F6:361D:2C7B93A:2D76BBD:6221EBCB" + } + }, + "uuid": "e688e202-0c96-4144-b415-cb16f315d478", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/mappings/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/mappings/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..e379c1a50a --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroups/mappings/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,46 @@ +{ + "id": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "name": "orgs_hub4j-test-org_teams_acme-developers_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers/external-groups", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "3-o_h_t_acme-developers_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1f1e7f72a8c1d013af016c2df9831d999124f580cd508cb53404fdd0981ef698\"", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4988", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "12", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F8:BF13:1A327EC:1B0A6BE:6221EBCC" + } + }, + "uuid": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..162ceb1c73 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,55 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization", + "total_private_repos": 3, + "owned_private_repos": 3, + "private_gists": 0, + "disk_usage": 11979, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "members_allowed_repository_creation_type": "none", + "members_can_create_public_repositories": false, + "members_can_create_private_repositories": false, + "members_can_create_internal_repositories": false, + "members_can_create_pages": true, + "members_can_fork_private_repositories": false, + "members_can_create_public_pages": true, + "members_can_create_private_pages": true, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 10000, + "filled_seats": 35, + "seats": 3 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/__files/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/__files/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..7642889a58 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/__files/2-o_h_t_acme-developers.json @@ -0,0 +1,49 @@ +{ + "name": "acme-developers", + "id": 34519961, + "node_id": "MDQ6VGVhbTM0NTE5OTY=", + "slug": "acme-developers", + "description": "Updated by API TestModified", + "privacy": "closed", + "url": "https://api.github.com/organizations/7544739/team/3451996", + "html_url": "https://github.com/orgs/hub4j-test-org/teams/acme-developers", + "members_url": "https://api.github.com/organizations/7544739/team/3451996/members{/member}", + "repositories_url": "https://api.github.com/organizations/7544739/team/3451996/repos", + "permission": "pull", + "created_at": "2019-10-03T21:46:12Z", + "updated_at": "2022-03-04T10:36:59Z", + "members_count": 1, + "repos_count": 1, + "organization": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization" + }, + "parent": null +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/__files/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/__files/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..b1569e2099 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/__files/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,4 @@ +{ + "message": "This organization is not part of externally managed enterprise.", + "documentation_url": "https://docs.github.com/rest/teams/external-groups#list-a-connection-between-an-external-group-and-a-team" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..18868d99d1 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,47 @@ +{ + "id": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:36:59 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"861b38147d37bd59e507771e76ec048def20dd6e5ac5b75aceb01c8b9f0ef4f5\"", + "Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4990", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "10", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F4:5E65:1A3BC41:1AAFE9E:6221EBCB" + } + }, + "uuid": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/mappings/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/mappings/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..1f5c8081f9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/mappings/2-o_h_t_acme-developers.json @@ -0,0 +1,47 @@ +{ + "id": "e688e202-0c96-4144-b415-cb16f315d478", + "name": "orgs_hub4j-test-org_teams_acme-developers", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_t_acme-developers.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1fbce0cbfea113fefff1877b37929ef1d7cb9c8989a5b223df3e9ea092502191\"", + "Last-Modified": "Fri, 04 Mar 2022 10:36:59 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4989", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "11", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F6:361D:2C7B93A:2D76BBD:6221EBCB" + } + }, + "uuid": "e688e202-0c96-4144-b415-cb16f315d478", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/mappings/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/mappings/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..cffbfcabb5 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsNotEnterpriseManagedOrganization/mappings/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,46 @@ +{ + "id": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "name": "orgs_hub4j-test-org_teams_acme-developers_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers/external-groups", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 400, + "bodyFileName": "3-o_h_t_acme-developers_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1f1e7f72a8c1d013af016c2df9831d999124f580cd508cb53404fdd0981ef698\"", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4988", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "12", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F8:BF13:1A327EC:1B0A6BE:6221EBCC" + } + }, + "uuid": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..162ceb1c73 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,55 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization", + "total_private_repos": 3, + "owned_private_repos": 3, + "private_gists": 0, + "disk_usage": 11979, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "members_allowed_repository_creation_type": "none", + "members_can_create_public_repositories": false, + "members_can_create_private_repositories": false, + "members_can_create_internal_repositories": false, + "members_can_create_pages": true, + "members_can_fork_private_repositories": false, + "members_can_create_public_pages": true, + "members_can_create_private_pages": true, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 10000, + "filled_seats": 35, + "seats": 3 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/__files/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/__files/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..7642889a58 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/__files/2-o_h_t_acme-developers.json @@ -0,0 +1,49 @@ +{ + "name": "acme-developers", + "id": 34519961, + "node_id": "MDQ6VGVhbTM0NTE5OTY=", + "slug": "acme-developers", + "description": "Updated by API TestModified", + "privacy": "closed", + "url": "https://api.github.com/organizations/7544739/team/3451996", + "html_url": "https://github.com/orgs/hub4j-test-org/teams/acme-developers", + "members_url": "https://api.github.com/organizations/7544739/team/3451996/members{/member}", + "repositories_url": "https://api.github.com/organizations/7544739/team/3451996/repos", + "permission": "pull", + "created_at": "2019-10-03T21:46:12Z", + "updated_at": "2022-03-04T10:36:59Z", + "members_count": 1, + "repos_count": 1, + "organization": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization" + }, + "parent": null +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/__files/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/__files/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..16b477dd1e --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/__files/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,4 @@ +{ + "message": "This team cannot be externally managed since it has explicit members.", + "documentation_url": "https://docs.github.com/rest/teams/external-groups#list-a-connection-between-an-external-group-and-a-team" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..18868d99d1 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,47 @@ +{ + "id": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:36:59 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"861b38147d37bd59e507771e76ec048def20dd6e5ac5b75aceb01c8b9f0ef4f5\"", + "Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4990", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "10", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F4:5E65:1A3BC41:1AAFE9E:6221EBCB" + } + }, + "uuid": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/mappings/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/mappings/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..1f5c8081f9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/mappings/2-o_h_t_acme-developers.json @@ -0,0 +1,47 @@ +{ + "id": "e688e202-0c96-4144-b415-cb16f315d478", + "name": "orgs_hub4j-test-org_teams_acme-developers", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_t_acme-developers.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1fbce0cbfea113fefff1877b37929ef1d7cb9c8989a5b223df3e9ea092502191\"", + "Last-Modified": "Fri, 04 Mar 2022 10:36:59 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4989", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "11", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F6:361D:2C7B93A:2D76BBD:6221EBCB" + } + }, + "uuid": "e688e202-0c96-4144-b415-cb16f315d478", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/mappings/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/mappings/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..cffbfcabb5 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testGetExternalGroupsTeamCannotBeExternallyManaged/mappings/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,46 @@ +{ + "id": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "name": "orgs_hub4j-test-org_teams_acme-developers_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers/external-groups", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 400, + "bodyFileName": "3-o_h_t_acme-developers_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1f1e7f72a8c1d013af016c2df9831d999124f580cd508cb53404fdd0981ef698\"", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4988", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "12", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F8:BF13:1A327EC:1B0A6BE:6221EBCC" + } + }, + "uuid": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file From 4032144b4ed4b1083c8c1bfce68df58602993c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Esteban=20Guti=C3=A9rrez?= Date: Mon, 8 Apr 2024 17:29:08 +0200 Subject: [PATCH 04/11] feat: Update the connection between an external group and a team --- src/main/java/org/kohsuke/github/GHTeam.java | 41 ++++++++ .../java/org/kohsuke/github/GHTeamTest.java | 93 ++++++++++++++++++- .../__files/1-orgs_hub4j-test-org.json | 55 +++++++++++ .../__files/2-o_h_t_acme-developers.json | 49 ++++++++++ .../3-o_h_t_external-group_467431.json | 19 ++++ ...o_h_t_acme-developers_external-groups.json | 25 +++++ .../mappings/1-orgs_hub4j-test-org.json | 47 ++++++++++ .../mappings/2-o_h_t_acme-developers.json | 47 ++++++++++ .../3-o_h_t_external-group_467431.json | 47 ++++++++++ ...o_h_t_acme-developers_external-groups.json | 53 +++++++++++ .../__files/1-orgs_hub4j-test-org.json | 55 +++++++++++ .../__files/2-o_h_t_acme-developers.json | 49 ++++++++++ ...o_h_t_acme-developers_external-groups.json | 25 +++++ .../mappings/1-orgs_hub4j-test-org.json | 47 ++++++++++ .../mappings/2-o_h_t_acme-developers.json | 47 ++++++++++ ...o_h_t_acme-developers_external-groups.json | 53 +++++++++++ .../__files/1-orgs_hub4j-test-org.json | 55 +++++++++++ .../__files/2-o_h_t_acme-developers.json | 49 ++++++++++ ...o_h_t_acme-developers_external-groups.json | 4 + .../mappings/1-orgs_hub4j-test-org.json | 47 ++++++++++ .../mappings/2-o_h_t_acme-developers.json | 47 ++++++++++ ...o_h_t_acme-developers_external-groups.json | 53 +++++++++++ .../__files/1-orgs_hub4j-test-org.json | 55 +++++++++++ .../__files/2-o_h_t_acme-developers.json | 49 ++++++++++ ...o_h_t_acme-developers_external-groups.json | 4 + .../mappings/1-orgs_hub4j-test-org.json | 47 ++++++++++ .../mappings/2-o_h_t_acme-developers.json | 47 ++++++++++ ...o_h_t_acme-developers_external-groups.json | 53 +++++++++++ 28 files changed, 1261 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/3-o_h_t_external-group_467431.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/4-o_h_t_acme-developers_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/3-o_h_t_external-group_467431.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/4-o_h_t_acme-developers_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/__files/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/__files/3-o_h_t_acme-developers_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/mappings/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/mappings/3-o_h_t_acme-developers_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/__files/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/__files/3-o_h_t_acme-developers_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/mappings/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/mappings/3-o_h_t_acme-developers_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/__files/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/__files/3-o_h_t_acme-developers_external-groups.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/mappings/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/mappings/3-o_h_t_acme-developers_external-groups.json diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index eb7601c182..700a6394fa 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -453,6 +453,47 @@ public List getExternalGroups() throws IOException { } } + /** + * Connect an external group to the team + * + * @param group + * the group to connect + * @return the external group + * @throws IOException + * in case of failure + * @see documentation + */ + public GHExternalGroup connectToExternalGroup(final GHExternalGroup group) throws IOException { + return connectToExternalGroup(group.getId()); + } + + /** + * Connect an external group to the team + * + * @param group_id + * the identifier of the group to connect + * @return the external group + * @throws IOException + * in case of failure + * @see documentation + */ + public GHExternalGroup connectToExternalGroup(final long group_id) throws IOException { + try { + return root().createRequest() + .method("PATCH") + .with("group_id", group_id) + .withUrlPath(publicApi(EXTERNAL_GROUPS)) + .fetch(GHExternalGroup.class) + .wrapUp(getOrganization()); + } catch (final HttpException e) { + throw EnterpriseManagedSupport.forOrganization(getOrganization()) + .handleException(e, "Could not connect team to external group") + .orElse(e); + } + } + /** * Gets organization. * diff --git a/src/test/java/org/kohsuke/github/GHTeamTest.java b/src/test/java/org/kohsuke/github/GHTeamTest.java index 1b0794285f..2773e367c5 100644 --- a/src/test/java/org/kohsuke/github/GHTeamTest.java +++ b/src/test/java/org/kohsuke/github/GHTeamTest.java @@ -11,8 +11,8 @@ import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.hasItems; import static org.junit.Assert.assertThrows; +import static org.kohsuke.github.ExternalGroupsTestingSupport.*; import static org.kohsuke.github.ExternalGroupsTestingSupport.Matchers.isExternalGroupSummary; -import static org.kohsuke.github.ExternalGroupsTestingSupport.groupSummary; // TODO: Auto-generated Javadoc /** @@ -320,4 +320,95 @@ public void testGetExternalGroupsTeamCannotBeExternallyManaged() throws IOExcept assertThat(failure.getMessage(), equalTo("Could not retrieve team external groups")); } + /** + * Test connect to external group by id. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testConnectToExternalGroupById() throws IOException { + String teamSlug = "acme-developers"; + + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + GHTeam team = org.getTeamBySlug(teamSlug); + + final GHExternalGroup group = team.connectToExternalGroup(467431); + + assertThat(group.getId(), equalTo(467431L)); + assertThat(group.getName(), equalTo("acme-developers")); + assertThat(group.getUpdatedAt(), notNullValue()); + + assertThat(group.getMembers(), notNullValue()); + assertThat(membersSummary(group), + hasItems("158311279:john-doe_acme:John Doe:john.doe@acme.corp", + "166731041:jane-doe_acme:Jane Doe:jane.doe@acme.corp")); + + assertThat(group.getTeams(), notNullValue()); + assertThat(teamSummary(group), hasItems("34519919:ACME-DEVELOPERS")); + } + + /** + * Test fail to connect to external group from other organization. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testConnectToExternalGroupByGroup() throws IOException { + String teamSlug = "acme-developers"; + + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + GHTeam team = org.getTeamBySlug(teamSlug); + GHExternalGroup group = org.getExternalGroup(467431); + + GHExternalGroup connectedGroup = team.connectToExternalGroup(group); + + assertThat(connectedGroup.getId(), equalTo(467431L)); + assertThat(connectedGroup.getName(), equalTo("acme-developers")); + assertThat(connectedGroup.getUpdatedAt(), notNullValue()); + + assertThat(connectedGroup.getMembers(), notNullValue()); + assertThat(membersSummary(connectedGroup), + hasItems("158311279:john-doe_acme:John Doe:john.doe@acme.corp", + "166731041:jane-doe_acme:Jane Doe:jane.doe@acme.corp")); + + assertThat(group.getTeams(), notNullValue()); + assertThat(teamSummary(connectedGroup), hasItems("34519919:ACME-DEVELOPERS")); + } + + /** + * Test failure when connecting to external group by id. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testFailConnectToExternalGroupWhenTeamHasMembers() throws IOException { + String teamSlug = "acme-developers"; + + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + GHTeam team = org.getTeamBySlug(teamSlug); + + final GHIOException failure = assertThrows(GHTeamCannotBeExternallyManagedException.class, + () -> team.connectToExternalGroup(467431)); + assertThat(failure.getMessage(), equalTo("Could not connect team to external group")); + } + + /** + * Test failure when connecting to external group by id. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testFailConnectToExternalGroupTeamIsNotAvailableInOrg() throws IOException { + String teamSlug = "acme-developers"; + + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + GHTeam team = org.getTeamBySlug(teamSlug); + + assertThrows(GHFileNotFoundException.class, () -> team.connectToExternalGroup(12345)); + } + } diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..162ceb1c73 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,55 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization", + "total_private_repos": 3, + "owned_private_repos": 3, + "private_gists": 0, + "disk_usage": 11979, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "members_allowed_repository_creation_type": "none", + "members_can_create_public_repositories": false, + "members_can_create_private_repositories": false, + "members_can_create_internal_repositories": false, + "members_can_create_pages": true, + "members_can_fork_private_repositories": false, + "members_can_create_public_pages": true, + "members_can_create_private_pages": true, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 10000, + "filled_seats": 35, + "seats": 3 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..d79e7c6f1a --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/2-o_h_t_acme-developers.json @@ -0,0 +1,49 @@ +{ + "name": "ACME-DEVELOPERS", + "id": 34519919, + "node_id": "MDQ6VGVhbTM0NTE5OTY=", + "slug": "acme-developers", + "description": "Updated by API TestModified", + "privacy": "closed", + "url": "https://api.github.com/organizations/7544739/team/3451996", + "html_url": "https://github.com/orgs/hub4j-test-org/teams/acme-developers", + "members_url": "https://api.github.com/organizations/7544739/team/3451996/members{/member}", + "repositories_url": "https://api.github.com/organizations/7544739/team/3451996/repos", + "permission": "pull", + "created_at": "2019-10-03T21:46:12Z", + "updated_at": "2022-03-04T10:36:59Z", + "members_count": 1, + "repos_count": 1, + "organization": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization" + }, + "parent": null +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/3-o_h_t_external-group_467431.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/3-o_h_t_external-group_467431.json new file mode 100644 index 0000000000..92f54df964 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/3-o_h_t_external-group_467431.json @@ -0,0 +1,19 @@ +{ + "group_id": 467431, + "group_name": "acme-developers", + "updated_at": "2023-09-13T16:41:28Z", + "members": [ + { + "member_id": 158311279, + "member_login": "john-doe_acme", + "member_name": "John Doe", + "member_email": "john.doe@acme.corp" + }, + { + "member_id": 166731041, + "member_login": "jane-doe_acme", + "member_name": "Jane Doe", + "member_email": "jane.doe@acme.corp" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/4-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/4-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..9c13f5dca4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/__files/4-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,25 @@ +{ + "group_id": 467431, + "group_name": "acme-developers", + "updated_at": "2023-09-13T16:41:28Z", + "members": [ + { + "member_id": 158311279, + "member_login": "john-doe_acme", + "member_name": "John Doe", + "member_email": "john.doe@acme.corp" + }, + { + "member_id": 166731041, + "member_login": "jane-doe_acme", + "member_name": "Jane Doe", + "member_email": "jane.doe@acme.corp" + } + ], + "teams": [ + { + "team_id": 34519919, + "team_name": "ACME-DEVELOPERS" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..18868d99d1 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,47 @@ +{ + "id": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:36:59 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"861b38147d37bd59e507771e76ec048def20dd6e5ac5b75aceb01c8b9f0ef4f5\"", + "Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4990", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "10", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F4:5E65:1A3BC41:1AAFE9E:6221EBCB" + } + }, + "uuid": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..1f5c8081f9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/2-o_h_t_acme-developers.json @@ -0,0 +1,47 @@ +{ + "id": "e688e202-0c96-4144-b415-cb16f315d478", + "name": "orgs_hub4j-test-org_teams_acme-developers", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_t_acme-developers.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1fbce0cbfea113fefff1877b37929ef1d7cb9c8989a5b223df3e9ea092502191\"", + "Last-Modified": "Fri, 04 Mar 2022 10:36:59 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4989", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "11", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F6:361D:2C7B93A:2D76BBD:6221EBCB" + } + }, + "uuid": "e688e202-0c96-4144-b415-cb16f315d478", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/3-o_h_t_external-group_467431.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/3-o_h_t_external-group_467431.json new file mode 100644 index 0000000000..5680cec01f --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/3-o_h_t_external-group_467431.json @@ -0,0 +1,47 @@ +{ + "id": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "name": "orgs_hub4j-test-org_external-group_467431", + "request": { + "url": "/orgs/hub4j-test-org/external-group/467431", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "3-o_h_t_external-group_467431.json", + "headers": { + "Server": "GitHub.com", + "Date": "Tue, 25 Feb 2020 14:41:06 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4983", + "X-RateLimit-Reset": "1582644475", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"631de12e6bc586863218257765331a70\"", + "X-OAuth-Scopes": "delete_repo, repo, user", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "EB37:2979:3EAF8C:78624D:5E553201" + } + }, + "uuid": "ef9f50f7-160c-4410-a82e-68d3e14fb250", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/4-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/4-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..52522b211a --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupByGroup/mappings/4-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,53 @@ +{ + "id": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "name": "orgs_hub4j-test-org_teams_acme-developers_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers/external-groups", + "method": "PATCH", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + }, + "bodyPatterns": [ + { + "equalToJson": "{\"group_id\":467431}", + "ignoreArrayOrder": true, + "ignoreExtraElements": false + } + ] + }, + "response": { + "status": 200, + "bodyFileName": "4-o_h_t_acme-developers_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1f1e7f72a8c1d013af016c2df9831d999124f580cd508cb53404fdd0981ef698\"", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4988", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "12", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F8:BF13:1A327EC:1B0A6BE:6221EBCC" + } + }, + "uuid": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..162ceb1c73 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,55 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization", + "total_private_repos": 3, + "owned_private_repos": 3, + "private_gists": 0, + "disk_usage": 11979, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "members_allowed_repository_creation_type": "none", + "members_can_create_public_repositories": false, + "members_can_create_private_repositories": false, + "members_can_create_internal_repositories": false, + "members_can_create_pages": true, + "members_can_fork_private_repositories": false, + "members_can_create_public_pages": true, + "members_can_create_private_pages": true, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 10000, + "filled_seats": 35, + "seats": 3 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/__files/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/__files/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..d79e7c6f1a --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/__files/2-o_h_t_acme-developers.json @@ -0,0 +1,49 @@ +{ + "name": "ACME-DEVELOPERS", + "id": 34519919, + "node_id": "MDQ6VGVhbTM0NTE5OTY=", + "slug": "acme-developers", + "description": "Updated by API TestModified", + "privacy": "closed", + "url": "https://api.github.com/organizations/7544739/team/3451996", + "html_url": "https://github.com/orgs/hub4j-test-org/teams/acme-developers", + "members_url": "https://api.github.com/organizations/7544739/team/3451996/members{/member}", + "repositories_url": "https://api.github.com/organizations/7544739/team/3451996/repos", + "permission": "pull", + "created_at": "2019-10-03T21:46:12Z", + "updated_at": "2022-03-04T10:36:59Z", + "members_count": 1, + "repos_count": 1, + "organization": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization" + }, + "parent": null +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/__files/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/__files/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..9c13f5dca4 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/__files/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,25 @@ +{ + "group_id": 467431, + "group_name": "acme-developers", + "updated_at": "2023-09-13T16:41:28Z", + "members": [ + { + "member_id": 158311279, + "member_login": "john-doe_acme", + "member_name": "John Doe", + "member_email": "john.doe@acme.corp" + }, + { + "member_id": 166731041, + "member_login": "jane-doe_acme", + "member_name": "Jane Doe", + "member_email": "jane.doe@acme.corp" + } + ], + "teams": [ + { + "team_id": 34519919, + "team_name": "ACME-DEVELOPERS" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..18868d99d1 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,47 @@ +{ + "id": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:36:59 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"861b38147d37bd59e507771e76ec048def20dd6e5ac5b75aceb01c8b9f0ef4f5\"", + "Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4990", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "10", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F4:5E65:1A3BC41:1AAFE9E:6221EBCB" + } + }, + "uuid": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/mappings/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/mappings/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..1f5c8081f9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/mappings/2-o_h_t_acme-developers.json @@ -0,0 +1,47 @@ +{ + "id": "e688e202-0c96-4144-b415-cb16f315d478", + "name": "orgs_hub4j-test-org_teams_acme-developers", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_t_acme-developers.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1fbce0cbfea113fefff1877b37929ef1d7cb9c8989a5b223df3e9ea092502191\"", + "Last-Modified": "Fri, 04 Mar 2022 10:36:59 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4989", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "11", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F6:361D:2C7B93A:2D76BBD:6221EBCB" + } + }, + "uuid": "e688e202-0c96-4144-b415-cb16f315d478", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/mappings/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/mappings/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..9db0056a2f --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testConnectToExternalGroupById/mappings/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,53 @@ +{ + "id": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "name": "orgs_hub4j-test-org_teams_acme-developers_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers/external-groups", + "method": "PATCH", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + }, + "bodyPatterns": [ + { + "equalToJson": "{\"group_id\":467431}", + "ignoreArrayOrder": true, + "ignoreExtraElements": false + } + ] + }, + "response": { + "status": 200, + "bodyFileName": "3-o_h_t_acme-developers_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1f1e7f72a8c1d013af016c2df9831d999124f580cd508cb53404fdd0981ef698\"", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4988", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "12", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F8:BF13:1A327EC:1B0A6BE:6221EBCC" + } + }, + "uuid": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..162ceb1c73 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,55 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization", + "total_private_repos": 3, + "owned_private_repos": 3, + "private_gists": 0, + "disk_usage": 11979, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "members_allowed_repository_creation_type": "none", + "members_can_create_public_repositories": false, + "members_can_create_private_repositories": false, + "members_can_create_internal_repositories": false, + "members_can_create_pages": true, + "members_can_fork_private_repositories": false, + "members_can_create_public_pages": true, + "members_can_create_private_pages": true, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 10000, + "filled_seats": 35, + "seats": 3 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/__files/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/__files/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..d79e7c6f1a --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/__files/2-o_h_t_acme-developers.json @@ -0,0 +1,49 @@ +{ + "name": "ACME-DEVELOPERS", + "id": 34519919, + "node_id": "MDQ6VGVhbTM0NTE5OTY=", + "slug": "acme-developers", + "description": "Updated by API TestModified", + "privacy": "closed", + "url": "https://api.github.com/organizations/7544739/team/3451996", + "html_url": "https://github.com/orgs/hub4j-test-org/teams/acme-developers", + "members_url": "https://api.github.com/organizations/7544739/team/3451996/members{/member}", + "repositories_url": "https://api.github.com/organizations/7544739/team/3451996/repos", + "permission": "pull", + "created_at": "2019-10-03T21:46:12Z", + "updated_at": "2022-03-04T10:36:59Z", + "members_count": 1, + "repos_count": 1, + "organization": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization" + }, + "parent": null +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/__files/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/__files/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..8ba8e63db9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/__files/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,4 @@ +{ + "message": "Not Found", + "documentation_url": "https://docs.github.com/rest/teams/external-groups#update-the-connection-between-an-external-group-and-a-team" +} diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..18868d99d1 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,47 @@ +{ + "id": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:36:59 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"861b38147d37bd59e507771e76ec048def20dd6e5ac5b75aceb01c8b9f0ef4f5\"", + "Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4990", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "10", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F4:5E65:1A3BC41:1AAFE9E:6221EBCB" + } + }, + "uuid": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/mappings/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/mappings/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..1f5c8081f9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/mappings/2-o_h_t_acme-developers.json @@ -0,0 +1,47 @@ +{ + "id": "e688e202-0c96-4144-b415-cb16f315d478", + "name": "orgs_hub4j-test-org_teams_acme-developers", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_t_acme-developers.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1fbce0cbfea113fefff1877b37929ef1d7cb9c8989a5b223df3e9ea092502191\"", + "Last-Modified": "Fri, 04 Mar 2022 10:36:59 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4989", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "11", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F6:361D:2C7B93A:2D76BBD:6221EBCB" + } + }, + "uuid": "e688e202-0c96-4144-b415-cb16f315d478", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/mappings/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/mappings/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..40b4774fa6 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupTeamIsNotAvailableInOrg/mappings/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,53 @@ +{ + "id": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "name": "orgs_hub4j-test-org_teams_acme-developers_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers/external-groups", + "method": "PATCH", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + }, + "bodyPatterns": [ + { + "equalToJson": "{\"group_id\":12345}", + "ignoreArrayOrder": true, + "ignoreExtraElements": false + } + ] + }, + "response": { + "status": 404, + "bodyFileName": "3-o_h_t_acme-developers_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1f1e7f72a8c1d013af016c2df9831d999124f580cd508cb53404fdd0981ef698\"", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4988", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "12", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F8:BF13:1A327EC:1B0A6BE:6221EBCC" + } + }, + "uuid": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..162ceb1c73 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,55 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization", + "total_private_repos": 3, + "owned_private_repos": 3, + "private_gists": 0, + "disk_usage": 11979, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "members_allowed_repository_creation_type": "none", + "members_can_create_public_repositories": false, + "members_can_create_private_repositories": false, + "members_can_create_internal_repositories": false, + "members_can_create_pages": true, + "members_can_fork_private_repositories": false, + "members_can_create_public_pages": true, + "members_can_create_private_pages": true, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 10000, + "filled_seats": 35, + "seats": 3 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/__files/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/__files/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..d79e7c6f1a --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/__files/2-o_h_t_acme-developers.json @@ -0,0 +1,49 @@ +{ + "name": "ACME-DEVELOPERS", + "id": 34519919, + "node_id": "MDQ6VGVhbTM0NTE5OTY=", + "slug": "acme-developers", + "description": "Updated by API TestModified", + "privacy": "closed", + "url": "https://api.github.com/organizations/7544739/team/3451996", + "html_url": "https://github.com/orgs/hub4j-test-org/teams/acme-developers", + "members_url": "https://api.github.com/organizations/7544739/team/3451996/members{/member}", + "repositories_url": "https://api.github.com/organizations/7544739/team/3451996/repos", + "permission": "pull", + "created_at": "2019-10-03T21:46:12Z", + "updated_at": "2022-03-04T10:36:59Z", + "members_count": 1, + "repos_count": 1, + "organization": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization" + }, + "parent": null +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/__files/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/__files/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..16b477dd1e --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/__files/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,4 @@ +{ + "message": "This team cannot be externally managed since it has explicit members.", + "documentation_url": "https://docs.github.com/rest/teams/external-groups#list-a-connection-between-an-external-group-and-a-team" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..18868d99d1 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,47 @@ +{ + "id": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:36:59 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"861b38147d37bd59e507771e76ec048def20dd6e5ac5b75aceb01c8b9f0ef4f5\"", + "Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4990", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "10", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F4:5E65:1A3BC41:1AAFE9E:6221EBCB" + } + }, + "uuid": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/mappings/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/mappings/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..1f5c8081f9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/mappings/2-o_h_t_acme-developers.json @@ -0,0 +1,47 @@ +{ + "id": "e688e202-0c96-4144-b415-cb16f315d478", + "name": "orgs_hub4j-test-org_teams_acme-developers", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_t_acme-developers.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1fbce0cbfea113fefff1877b37929ef1d7cb9c8989a5b223df3e9ea092502191\"", + "Last-Modified": "Fri, 04 Mar 2022 10:36:59 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4989", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "11", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F6:361D:2C7B93A:2D76BBD:6221EBCB" + } + }, + "uuid": "e688e202-0c96-4144-b415-cb16f315d478", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/mappings/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/mappings/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..1ee400391e --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testFailConnectToExternalGroupWhenTeamHasMembers/mappings/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,53 @@ +{ + "id": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "name": "orgs_hub4j-test-org_teams_acme-developers_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers/external-groups", + "method": "PATCH", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + }, + "bodyPatterns": [ + { + "equalToJson": "{\"group_id\":467431}", + "ignoreArrayOrder": true, + "ignoreExtraElements": false + } + ] + }, + "response": { + "status": 400, + "bodyFileName": "3-o_h_t_acme-developers_external-groups.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1f1e7f72a8c1d013af016c2df9831d999124f580cd508cb53404fdd0981ef698\"", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4988", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "12", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F8:BF13:1A327EC:1B0A6BE:6221EBCC" + } + }, + "uuid": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file From 6c10a0341e3fdd023fbc94feef1af1dfe057e859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Esteban=20Guti=C3=A9rrez?= Date: Mon, 8 Apr 2024 17:29:30 +0200 Subject: [PATCH 05/11] feat: Remove the connection between an external group and a team --- src/main/java/org/kohsuke/github/GHTeam.java | 12 ++++ .../java/org/kohsuke/github/GHTeamTest.java | 23 ++++++++ .../__files/1-orgs_hub4j-test-org.json | 55 +++++++++++++++++++ .../__files/2-o_h_t_acme-developers.json | 49 +++++++++++++++++ .../mappings/1-orgs_hub4j-test-org.json | 47 ++++++++++++++++ .../mappings/2-o_h_t_acme-developers.json | 47 ++++++++++++++++ ...o_h_t_acme-developers_external-groups.json | 45 +++++++++++++++ 7 files changed, 278 insertions(+) create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/__files/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/__files/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/mappings/1-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/mappings/2-o_h_t_acme-developers.json create mode 100644 src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/mappings/3-o_h_t_acme-developers_external-groups.json diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index 700a6394fa..aa83eb5ea9 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -494,6 +494,18 @@ public GHExternalGroup connectToExternalGroup(final long group_id) throws IOExce } } + /** + * Remove the connection of the team to an external group + * + * @throws IOException + * in case of failure + * @see documentation + */ + public void deleteExternalGroupConnection() throws IOException { + root().createRequest().method("DELETE").withUrlPath(publicApi(EXTERNAL_GROUPS)).send(); + } + /** * Gets organization. * diff --git a/src/test/java/org/kohsuke/github/GHTeamTest.java b/src/test/java/org/kohsuke/github/GHTeamTest.java index 2773e367c5..8deba28c2b 100644 --- a/src/test/java/org/kohsuke/github/GHTeamTest.java +++ b/src/test/java/org/kohsuke/github/GHTeamTest.java @@ -8,6 +8,8 @@ import java.util.List; import java.util.Set; +import static com.github.tomakehurst.wiremock.client.WireMock.deleteRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.hasItems; import static org.junit.Assert.assertThrows; @@ -411,4 +413,25 @@ public void testFailConnectToExternalGroupTeamIsNotAvailableInOrg() throws IOExc assertThrows(GHFileNotFoundException.class, () -> team.connectToExternalGroup(12345)); } + /** + * Test delete connection to external group + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void testDeleteExternalGroupConnection() throws IOException { + String teamSlug = "acme-developers"; + + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + GHTeam team = org.getTeamBySlug(teamSlug); + + team.deleteExternalGroupConnection(); + + mockGitHub.apiServer() + .verify(1, + deleteRequestedFor(urlPathEqualTo("/orgs/" + team.getOrganization().getLogin() + "/teams/" + + team.getSlug() + "/external-groups"))); + } + } diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/__files/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/__files/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..162ceb1c73 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/__files/1-orgs_hub4j-test-org.json @@ -0,0 +1,55 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization", + "total_private_repos": 3, + "owned_private_repos": 3, + "private_gists": 0, + "disk_usage": 11979, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "members_allowed_repository_creation_type": "none", + "members_can_create_public_repositories": false, + "members_can_create_private_repositories": false, + "members_can_create_internal_repositories": false, + "members_can_create_pages": true, + "members_can_fork_private_repositories": false, + "members_can_create_public_pages": true, + "members_can_create_private_pages": true, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 10000, + "filled_seats": 35, + "seats": 3 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/__files/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/__files/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..7642889a58 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/__files/2-o_h_t_acme-developers.json @@ -0,0 +1,49 @@ +{ + "name": "acme-developers", + "id": 34519961, + "node_id": "MDQ6VGVhbTM0NTE5OTY=", + "slug": "acme-developers", + "description": "Updated by API TestModified", + "privacy": "closed", + "url": "https://api.github.com/organizations/7544739/team/3451996", + "html_url": "https://github.com/orgs/hub4j-test-org/teams/acme-developers", + "members_url": "https://api.github.com/organizations/7544739/team/3451996/members{/member}", + "repositories_url": "https://api.github.com/organizations/7544739/team/3451996/repos", + "permission": "pull", + "created_at": "2019-10-03T21:46:12Z", + "updated_at": "2022-03-04T10:36:59Z", + "members_count": 1, + "repos_count": 1, + "organization": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", + "description": "Hub4j Test Org Description (this could be null or blank too)", + "name": "Hub4j Test Org Name (this could be null or blank too)", + "company": null, + "blog": "https://hub4j.url.io/could/be/null", + "location": "Hub4j Test Org Location (this could be null or blank too)", + "email": "hub4jtestorgemail@could.be.null.com", + "twitter_username": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 49, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2020-06-04T05:56:10Z", + "type": "Organization" + }, + "parent": null +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/mappings/1-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/mappings/1-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..18868d99d1 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/mappings/1-orgs_hub4j-test-org.json @@ -0,0 +1,47 @@ +{ + "id": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-orgs_hub4j-test-org.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:36:59 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"861b38147d37bd59e507771e76ec048def20dd6e5ac5b75aceb01c8b9f0ef4f5\"", + "Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4990", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "10", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F4:5E65:1A3BC41:1AAFE9E:6221EBCB" + } + }, + "uuid": "780bda7a-e76d-4840-87e4-ba6411cfc9c2", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/mappings/2-o_h_t_acme-developers.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/mappings/2-o_h_t_acme-developers.json new file mode 100644 index 0000000000..1f5c8081f9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/mappings/2-o_h_t_acme-developers.json @@ -0,0 +1,47 @@ +{ + "id": "e688e202-0c96-4144-b415-cb16f315d478", + "name": "orgs_hub4j-test-org_teams_acme-developers", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-o_h_t_acme-developers.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1fbce0cbfea113fefff1877b37929ef1d7cb9c8989a5b223df3e9ea092502191\"", + "Last-Modified": "Fri, 04 Mar 2022 10:36:59 GMT", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4989", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "11", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F6:361D:2C7B93A:2D76BBD:6221EBCB" + } + }, + "uuid": "e688e202-0c96-4144-b415-cb16f315d478", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/mappings/3-o_h_t_acme-developers_external-groups.json b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/mappings/3-o_h_t_acme-developers_external-groups.json new file mode 100644 index 0000000000..bc87120395 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHTeamTest/wiremock/testDeleteExternalGroupConnection/mappings/3-o_h_t_acme-developers_external-groups.json @@ -0,0 +1,45 @@ +{ + "id": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "name": "orgs_hub4j-test-org_teams_acme-developers_external-groups", + "request": { + "url": "/orgs/hub4j-test-org/teams/acme-developers/external-groups", + "method": "DELETE", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 204, + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 04 Mar 2022 10:37:00 GMT", + "Content-Type": "application/json; charset=utf-8", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With" + ], + "ETag": "W/\"1f1e7f72a8c1d013af016c2df9831d999124f580cd508cb53404fdd0981ef698\"", + "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "github.v3; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4988", + "X-RateLimit-Reset": "1646393817", + "X-RateLimit-Used": "12", + "X-RateLimit-Resource": "core", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "B9F8:BF13:1A327EC:1B0A6BE:6221EBCC" + } + }, + "uuid": "100fc073-1fdc-4715-94c1-fbf410d74da0", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file From 576c69eec5fd2f23ed7887ac9797401762ad486a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Esteban=20Guti=C3=A9rrez?= Date: Fri, 14 Jun 2024 20:00:38 +0200 Subject: [PATCH 06/11] impr: Remove unnecessary Jackson annotations --- .../org/kohsuke/github/GHExternalGroup.java | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHExternalGroup.java b/src/main/java/org/kohsuke/github/GHExternalGroup.java index 01b3f84241..b5bba0f266 100644 --- a/src/main/java/org/kohsuke/github/GHExternalGroup.java +++ b/src/main/java/org/kohsuke/github/GHExternalGroup.java @@ -1,6 +1,5 @@ package org.kohsuke.github; -import com.fasterxml.jackson.annotation.JsonProperty; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; @@ -25,16 +24,14 @@ public static class GHLinkedTeam { /** * The identifier of the team */ - @JsonProperty("team_id") @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") - private long id; + private long teamId; /** * The name of the team */ - @JsonProperty("team_name") @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") - private String name; + private String teamName; /** * Get the linked team identifier @@ -42,7 +39,7 @@ public static class GHLinkedTeam { * @return the id */ public long getId() { - return id; + return teamId; } /** @@ -51,7 +48,7 @@ public long getId() { * @return the name */ public String getName() { - return name; + return teamName; } } @@ -64,30 +61,26 @@ public static class GHLinkedExternalMember { /** * The internal user ID of the identity */ - @JsonProperty("member_id") @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") - private long id; + private long memberId; /** * The handle/login for the user */ - @JsonProperty("member_login") @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") - private String login; + private String memberLogin; /** * The user display name/profile name */ - @JsonProperty("member_name") @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") - private String name; + private String memberName; /** * The email attached to the user */ - @JsonProperty("member_email") @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") - private String email; + private String memberEmail; /** * Get the linked member identifier @@ -95,7 +88,7 @@ public static class GHLinkedExternalMember { * @return the id */ public long getId() { - return id; + return memberId; } /** @@ -104,7 +97,7 @@ public long getId() { * @return the login */ public String getLogin() { - return login; + return memberLogin; } /** @@ -113,7 +106,7 @@ public String getLogin() { * @return the name */ public String getName() { - return name; + return memberName; } /** @@ -122,7 +115,7 @@ public String getName() { * @return the email */ public String getEmail() { - return email; + return memberEmail; } } @@ -130,17 +123,14 @@ public String getEmail() { /** * The identifier of the external group */ - @JsonProperty("group_id") - @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") - private long id; + private long groupId; /** * The name of the external group */ - @JsonProperty("group_name") @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization") - private String name; + private String groupName; /** * The date when the group was last updated at @@ -206,7 +196,7 @@ public GHOrganization getOrganization() throws IOException { * @return the id */ public long getId() { - return id; + return groupId; } /** @@ -215,7 +205,7 @@ public long getId() { * @return the name */ public String getName() { - return name; + return groupName; } /** From 92e06f1234b95cf2d79ea7272f93ee9927d9a7a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Esteban=20Guti=C3=A9rrez?= Date: Fri, 14 Jun 2024 20:03:32 +0200 Subject: [PATCH 07/11] refactor: Rename external group iterable class --- ...ternalGroupsIterable.java => GHExternalGroupIterable.java} | 4 ++-- src/main/java/org/kohsuke/github/GHOrganization.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/main/java/org/kohsuke/github/{GHExternalGroupsIterable.java => GHExternalGroupIterable.java} (91%) diff --git a/src/main/java/org/kohsuke/github/GHExternalGroupsIterable.java b/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java similarity index 91% rename from src/main/java/org/kohsuke/github/GHExternalGroupsIterable.java rename to src/main/java/org/kohsuke/github/GHExternalGroupIterable.java index ab11f32687..2695f185f3 100644 --- a/src/main/java/org/kohsuke/github/GHExternalGroupsIterable.java +++ b/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java @@ -11,7 +11,7 @@ * * @author Miguel Esteban Gutiérrez */ -class GHExternalGroupsIterable extends PagedIterable { +class GHExternalGroupIterable extends PagedIterable { private static final GHExternalGroup[] GH_EXTERNAL_GROUPS = new GHExternalGroup[0]; @@ -29,7 +29,7 @@ class GHExternalGroupsIterable extends PagedIterable { * @param requestBuilder * the request builder */ - GHExternalGroupsIterable(final GHOrganization owner, final GitHubRequest.Builder requestBuilder) { + GHExternalGroupIterable(final GHOrganization owner, final GitHubRequest.Builder requestBuilder) { this.owner = owner; this.request = requestBuilder.build(); } diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index 3ab3d53b20..db49c5f43c 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -218,7 +218,7 @@ public PagedIterable listExternalGroups(final String displayNam if (displayName != null) { requester.with("display_name", displayName); } - return new GHExternalGroupsIterable(this, requester); + return new GHExternalGroupIterable(this, requester); } /** From a3b9ee047df2e7183d9847479c95cce83fbae0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Esteban=20Guti=C3=A9rrez?= Date: Fri, 14 Jun 2024 20:05:08 +0200 Subject: [PATCH 08/11] docs: Remove unnecessary documentation TODO note --- src/main/java/org/kohsuke/github/GHExternalGroupIterable.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java b/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java index 2695f185f3..f73cfd1d7f 100644 --- a/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java +++ b/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java @@ -4,8 +4,6 @@ import javax.annotation.Nonnull; -// TODO: Auto-generated Javadoc - /** * Iterable for external group listing. * From f291f480b63d6eddf1cc0f74a03d8f014a813636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Esteban=20Guti=C3=A9rrez?= Date: Fri, 14 Jun 2024 20:08:12 +0200 Subject: [PATCH 09/11] refactor: Rename exception handling methods to better reflect intent --- .../org/kohsuke/github/EnterpriseManagedSupport.java | 8 ++++---- .../org/kohsuke/github/GHExternalGroupIterable.java | 2 +- src/main/java/org/kohsuke/github/GHOrganization.java | 2 +- src/main/java/org/kohsuke/github/GHTeam.java | 4 ++-- .../kohsuke/github/EnterpriseManagedSupportTest.java | 12 ++++++------ 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java b/src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java index a8b4745529..5b4c62be6b 100644 --- a/src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java +++ b/src/main/java/org/kohsuke/github/EnterpriseManagedSupport.java @@ -8,7 +8,7 @@ import java.util.logging.Logger; /** - * Utility class for helping with operation for enterprise managed resources. + * Utility class for helping with operations for enterprise managed resources. * * @author Miguel Esteban Gutiérrez */ @@ -26,7 +26,7 @@ private EnterpriseManagedSupport(GHOrganization organization) { this.organization = organization; } - Optional handleException(final HttpException he, final String scenario) { + Optional filterException(final HttpException he, final String scenario) { if (he.getResponseCode() == 400) { final String responseMessage = he.getMessage(); try { @@ -46,10 +46,10 @@ Optional handleException(final HttpException he, final String sce return Optional.empty(); } - Optional handleException(final GHException e) { + Optional filterException(final GHException e) { if (e.getCause() instanceof HttpException) { final HttpException he = (HttpException) e.getCause(); - return handleException(he, COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS) + return filterException(he, COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS) .map(translated -> new GHException(COULD_NOT_RETRIEVE_ORGANIZATION_EXTERNAL_GROUPS, translated)); } return Optional.empty(); diff --git a/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java b/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java index f73cfd1d7f..5c71d4ae11 100644 --- a/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java +++ b/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java @@ -60,7 +60,7 @@ public boolean hasNext() { try { return base.hasNext(); } catch (final GHException e) { - throw EnterpriseManagedSupport.forOrganization(owner).handleException(e).orElse(e); + throw EnterpriseManagedSupport.forOrganization(owner).filterException(e).orElse(e); } } diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index db49c5f43c..864057e1c9 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -240,7 +240,7 @@ public GHExternalGroup getExternalGroup(final long groupId) throws IOException { .wrapUp(this); } catch (final HttpException e) { throw EnterpriseManagedSupport.forOrganization(this) - .handleException(e, "Could not retrieve organization external group") + .filterException(e, "Could not retrieve organization external group") .orElse(e); } } diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index aa83eb5ea9..0f3c5324fb 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -448,7 +448,7 @@ public List getExternalGroups() throws IOException { .getGroups(); } catch (final HttpException e) { throw EnterpriseManagedSupport.forOrganization(getOrganization()) - .handleException(e, "Could not retrieve team external groups") + .filterException(e, "Could not retrieve team external groups") .orElse(e); } } @@ -489,7 +489,7 @@ public GHExternalGroup connectToExternalGroup(final long group_id) throws IOExce .wrapUp(getOrganization()); } catch (final HttpException e) { throw EnterpriseManagedSupport.forOrganization(getOrganization()) - .handleException(e, "Could not connect team to external group") + .filterException(e, "Could not connect team to external group") .orElse(e); } } diff --git a/src/test/java/org/kohsuke/github/EnterpriseManagedSupportTest.java b/src/test/java/org/kohsuke/github/EnterpriseManagedSupportTest.java index 60fd797f46..9ddc72ea66 100644 --- a/src/test/java/org/kohsuke/github/EnterpriseManagedSupportTest.java +++ b/src/test/java/org/kohsuke/github/EnterpriseManagedSupportTest.java @@ -37,7 +37,7 @@ public void testIgnoreNonHttpException() throws IOException { final GHException inputException = new GHException("Test", inputCause); final Optional maybeException = EnterpriseManagedSupport.forOrganization(org) - .handleException(inputException); + .filterException(inputException); assertThat(maybeException.isPresent(), is(false)); } @@ -59,7 +59,7 @@ public void testIgnoreNonBadRequestExceptions() throws IOException { final GHException inputException = new GHException("Test", inputCause); final Optional maybeException = EnterpriseManagedSupport.forOrganization(org) - .handleException(inputException); + .filterException(inputException); assertThat(maybeException.isPresent(), is(false)); } @@ -78,7 +78,7 @@ public void testIgnoreBadRequestsWithUnparseableJson() throws IOException { final GHException inputException = new GHException("Test", inputCause); final Optional maybeException = EnterpriseManagedSupport.forOrganization(org) - .handleException(inputException); + .filterException(inputException); assertThat(maybeException.isPresent(), is(false)); } @@ -97,7 +97,7 @@ public void testIgnoreBadRequestsWithUnknownErrorMessage() throws IOException { final GHException inputException = new GHException("Test", inputCause); final Optional maybeException = EnterpriseManagedSupport.forOrganization(org) - .handleException(inputException); + .filterException(inputException); assertThat(maybeException.isPresent(), is(false)); } @@ -119,7 +119,7 @@ public void testHandleEmbeddedNotPartOfExternallyManagedEnterpriseHttpException( final GHException inputException = new GHException("Test", inputCause); final Optional maybeException = EnterpriseManagedSupport.forOrganization(org) - .handleException(inputException); + .filterException(inputException); assertThat(maybeException.isPresent(), is(true)); @@ -162,7 +162,7 @@ public void testHandleTeamCannotBeExternallyManagedHttpException() throws IOExce org.getUrl().toString()); final Optional maybeException = EnterpriseManagedSupport.forOrganization(org) - .handleException(inputException, "Scenario"); + .filterException(inputException, "Scenario"); assertThat(maybeException.isPresent(), is(true)); From a363a043533d9d9c8b14cf6ff400ab3d674e0814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Esteban=20Guti=C3=A9rrez?= Date: Fri, 14 Jun 2024 21:44:42 +0200 Subject: [PATCH 10/11] refactor: Apply page pattern for handling sets of external groups --- .../github/GHExternalGroupIterable.java | 16 ++++----- .../kohsuke/github/GHExternalGroupPage.java | 34 +++++++++++++++++++ .../org/kohsuke/github/GHExternalGroups.java | 28 --------------- src/main/java/org/kohsuke/github/GHTeam.java | 7 ++-- 4 files changed, 46 insertions(+), 39 deletions(-) create mode 100644 src/main/java/org/kohsuke/github/GHExternalGroupPage.java delete mode 100644 src/main/java/org/kohsuke/github/GHExternalGroups.java diff --git a/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java b/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java index 5c71d4ae11..f921fdd920 100644 --- a/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java +++ b/src/main/java/org/kohsuke/github/GHExternalGroupIterable.java @@ -1,5 +1,6 @@ package org.kohsuke.github; +import java.util.Arrays; import java.util.Iterator; import javax.annotation.Nonnull; @@ -11,13 +12,11 @@ */ class GHExternalGroupIterable extends PagedIterable { - private static final GHExternalGroup[] GH_EXTERNAL_GROUPS = new GHExternalGroup[0]; - private final GHOrganization owner; private final GitHubRequest request; - private GHExternalGroups result; + private GHExternalGroupPage result; /** * Instantiates a new GH external groups iterable. @@ -43,7 +42,8 @@ class GHExternalGroupIterable extends PagedIterable { @Override public PagedIterator _iterator(int pageSize) { return new PagedIterator<>( - adapt(GitHubPageIterator.create(owner.root().getClient(), GHExternalGroups.class, request, pageSize)), + adapt(GitHubPageIterator + .create(owner.root().getClient(), GHExternalGroupPage.class, request, pageSize)), null); } @@ -54,7 +54,7 @@ public PagedIterator _iterator(int pageSize) { * the base * @return the iterator */ - private Iterator adapt(final Iterator base) { + private Iterator adapt(final Iterator base) { return new Iterator() { public boolean hasNext() { try { @@ -65,12 +65,12 @@ public boolean hasNext() { } public GHExternalGroup[] next() { - GHExternalGroups v = base.next(); + GHExternalGroupPage v = base.next(); if (result == null) { result = v; } - v.getGroups().forEach(g -> g.wrapUp(owner)); - return v.getGroups().toArray(GH_EXTERNAL_GROUPS); + Arrays.stream(v.getGroups()).forEach(g -> g.wrapUp(owner)); + return v.getGroups(); } }; } diff --git a/src/main/java/org/kohsuke/github/GHExternalGroupPage.java b/src/main/java/org/kohsuke/github/GHExternalGroupPage.java new file mode 100644 index 0000000000..0f3742462f --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHExternalGroupPage.java @@ -0,0 +1,34 @@ +package org.kohsuke.github; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +/** + * A list of external groups. + * + * @author Miguel Esteban Gutiérrez + */ +public class GHExternalGroupPage { + + private static final GHExternalGroup[] GH_EXTERNAL_GROUPS = new GHExternalGroup[0]; + + private GHExternalGroup[] groups; + + GHExternalGroupPage() { + this(GH_EXTERNAL_GROUPS); + } + + GHExternalGroupPage(GHExternalGroup[] groups) { + this.groups = groups; + } + + /** + * Gets the groups. + * + * @return the groups + */ + @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") + public GHExternalGroup[] getGroups() { + return groups; + } + +} diff --git a/src/main/java/org/kohsuke/github/GHExternalGroups.java b/src/main/java/org/kohsuke/github/GHExternalGroups.java deleted file mode 100644 index 351c15f085..0000000000 --- a/src/main/java/org/kohsuke/github/GHExternalGroups.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.kohsuke.github; - -import java.util.Collections; -import java.util.List; - -/** - * A list of external groups. - * - * @author Miguel Esteban Gutiérrez - */ -public class GHExternalGroups { - - private List groups; - - GHExternalGroups() { - this.groups = Collections.emptyList(); - } - - /** - * Gets the groups. - * - * @return the groups - */ - public List getGroups() { - return Collections.unmodifiableList(groups); - } - -} diff --git a/src/main/java/org/kohsuke/github/GHTeam.java b/src/main/java/org/kohsuke/github/GHTeam.java index 0f3c5324fb..4d94735aec 100644 --- a/src/main/java/org/kohsuke/github/GHTeam.java +++ b/src/main/java/org/kohsuke/github/GHTeam.java @@ -441,11 +441,11 @@ public GHDiscussion.Creator createDiscussion(String title) throws IOException { */ public List getExternalGroups() throws IOException { try { - return root().createRequest() + return Collections.unmodifiableList(Arrays.asList(root().createRequest() .method("GET") .withUrlPath(publicApi(EXTERNAL_GROUPS)) - .fetch(GHExternalGroups.class) - .getGroups(); + .fetch(GHExternalGroupPage.class) + .getGroups())); } catch (final HttpException e) { throw EnterpriseManagedSupport.forOrganization(getOrganization()) .filterException(e, "Could not retrieve team external groups") @@ -570,4 +570,5 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(name, getUrl(), permission, slug, description, privacy); } + } From c2ac4b0388d16ad4c60bb8868cd9748ab851d8e1 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Sun, 16 Jun 2024 01:06:34 -0700 Subject: [PATCH 11/11] Update src/main/java/org/kohsuke/github/GHExternalGroupPage.java --- src/main/java/org/kohsuke/github/GHExternalGroupPage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHExternalGroupPage.java b/src/main/java/org/kohsuke/github/GHExternalGroupPage.java index 0f3742462f..d47b49678c 100644 --- a/src/main/java/org/kohsuke/github/GHExternalGroupPage.java +++ b/src/main/java/org/kohsuke/github/GHExternalGroupPage.java @@ -7,7 +7,7 @@ * * @author Miguel Esteban Gutiérrez */ -public class GHExternalGroupPage { +class GHExternalGroupPage { private static final GHExternalGroup[] GH_EXTERNAL_GROUPS = new GHExternalGroup[0];