Skip to content
This repository was archived by the owner on Apr 20, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Enable auto-env through the sdkman_auto_env config
Comment thread
Abhi347 marked this conversation as resolved.
# Add key=value pairs of SDKs to use below
java=11.0.20-amzn
maven=3.8.6
51 changes: 24 additions & 27 deletions src/main/java/com/spotify/github/v3/orgs/requests/TeamCreate.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,64 +19,61 @@
*/
package com.spotify.github.v3.orgs.requests;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.spotify.github.GithubStyle;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
import org.immutables.value.Value;

/** Request to create a team within a given organisation */
@Value.Immutable
@GithubStyle
@JsonSerialize(as = ImmutableTeamCreate.class)
@JsonDeserialize(as = ImmutableTeamCreate.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public interface TeamCreate {

/** The name of the team. */
@Nullable
String name();

/** The description of the team. */
Optional<String> description();

/**
* The level of privacy this team should have.
* For a non-nested team:
* secret - only visible to organization owners and members of this team.
* closed - visible to all members of this organization.
* Default: secret
* For a parent or child team:
* closed - visible to all members of this organization.
* Default for child team: closed
* Can be one of: secret, closed
* The level of privacy this team should have. For a non-nested team: secret - only visible to
* organization owners and members of this team. closed - visible to all members of this
* organization. Default: secret For a parent or child team: closed - visible to all members of
* this organization. Default for child team: closed Can be one of: secret, closed
*/
Optional<String> privacy();

/**
* The notification setting the team has chosen. The options are:
* notifications_enabled - team members receive notifications when the team is @mentioned.
* notifications_disabled - no one receives notifications.
* Default: notifications_enabled
* Can be one of: notifications_enabled, notifications_disabled
*
* <p>notifications_enabled - team members receive notifications when the team is @mentioned.
*
* <p>notifications_disabled - no one receives notifications.
*
* <p>Default: notifications_enabled
*
* <p>Can be one of: notifications_enabled, notifications_disabled
*/
@SuppressWarnings("checkstyle:methodname")
Optional<String> notification_setting();
@JsonProperty("notification_setting")
Optional<String> notificationSetting();

/**
* List GitHub IDs for organization members who will
* become team maintainers.
*/
/** List GitHub IDs for organization members who will become team maintainers. */
Optional<List<String>> maintainers();

/** The full name (e.g., "organization-name/repository-name")
* of repositories to add the team to.
/**
* The full name (e.g., "organization-name/repository-name") of repositories to add the team to.
*/
@SuppressWarnings("checkstyle:methodname")
Optional<List<String>> repo_names();
@JsonProperty("repo_names")
Optional<List<String>> repoNames();

/** The ID of a team to set as the parent team. */
@SuppressWarnings("checkstyle:methodname")
Optional<String> parent_team_id();
@JsonProperty("parent_team_id")
Optional<Integer> parentTeamId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package com.spotify.github.v3.orgs.requests;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.spotify.github.GithubStyle;
Expand All @@ -31,6 +33,7 @@
@GithubStyle
@JsonSerialize(as = ImmutableTeamUpdate.class)
@JsonDeserialize(as = ImmutableTeamUpdate.class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public interface TeamUpdate {

/** The name of the team. */
Expand Down Expand Up @@ -60,11 +63,11 @@ public interface TeamUpdate {
* Default: notifications_enabled
* Can be one of: notifications_enabled, notifications_disabled
*/
@SuppressWarnings("checkstyle:methodname")
Optional<String> notification_setting();
@JsonProperty("notification_setting")
Optional<String> notificationSetting();


/** The ID of a team to set as the parent team. */
@SuppressWarnings("checkstyle:methodname")
Optional<String> parent_team_id();
@JsonProperty("parent_team_id")
Optional<Integer> parentTeamId();
}
59 changes: 30 additions & 29 deletions src/test/java/com/spotify/github/v3/clients/TeamClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* -/-/-
*/


package com.spotify.github.v3.clients;

import static com.google.common.io.Resources.getResource;
Expand All @@ -31,8 +30,7 @@
import static org.hamcrest.core.Is.is;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

import com.google.common.io.Resources;
import com.spotify.github.jackson.Json;
Expand All @@ -57,7 +55,7 @@
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest({ Headers.class, ResponseBody.class, Response.class})
@PrepareForTest({Headers.class, ResponseBody.class, Response.class})
public class TeamClientTest {

private GitHubClient github;
Expand Down Expand Up @@ -113,42 +111,43 @@ public void deleteTeam() throws Exception {
@Test
public void createTeam() throws Exception {
final TeamCreate teamCreateRequest =
json.fromJson(
getFixture("teams_request.json"),
TeamCreate.class);
json.fromJson(getFixture("teams_request.json"), TeamCreate.class);

final CompletableFuture<Team> fixtureResponse = completedFuture(json.fromJson(
getFixture("team_get.json"),
Team.class));
final CompletableFuture<Team> fixtureResponse =
completedFuture(json.fromJson(getFixture("team_get.json"), Team.class));
when(github.post(any(), any(), eq(Team.class))).thenReturn(fixtureResponse);
final CompletableFuture<Team> actualResponse = teamClient.createTeam(teamCreateRequest);

assertThat(actualResponse.get().name(), is("Justice League"));
verify(github, times(1))
.post(eq("/orgs/github/teams"), eq("{\"name\":\"Justice League\"}"), eq(Team.class));
}

@Test
public void updateTeam() throws Exception {
final TeamUpdate teamUpdateRequest =
json.fromJson(
getFixture("teams_patch.json"),
TeamUpdate.class);
json.fromJson(getFixture("teams_patch.json"), TeamUpdate.class);

final CompletableFuture<Team> fixtureResponse = completedFuture(json.fromJson(
getFixture("teams_patch_response.json"),
Team.class));
final CompletableFuture<Team> fixtureResponse =
completedFuture(json.fromJson(getFixture("teams_patch_response.json"), Team.class));
when(github.patch(any(), any(), eq(Team.class))).thenReturn(fixtureResponse);
final CompletableFuture<Team> actualResponse = teamClient.updateTeam(teamUpdateRequest, "justice-league");
final CompletableFuture<Team> actualResponse =
teamClient.updateTeam(teamUpdateRequest, "justice-league");

assertThat(actualResponse.get().name(), is("Justice League2"));
verify(github, times(1))
.patch(eq("/orgs/github/teams/justice-league"), eq("{\"name\":\"Justice League2\"}"), eq(Team.class));
}

@Test
public void getMembership() throws Exception {
final CompletableFuture<Membership> fixture =
completedFuture(json.fromJson(getFixture("membership.json"), Membership.class));
when(github.request("/orgs/github/teams/1/memberships/octocat", Membership.class)).thenReturn(fixture);
when(github.request("/orgs/github/teams/1/memberships/octocat", Membership.class))
.thenReturn(fixture);
final Membership membership = teamClient.getMembership("1", "octocat").get();
assertThat(membership.url().toString(), is("https://api.github.com/teams/1/memberships/octocat"));
assertThat(
membership.url().toString(), is("https://api.github.com/teams/1/memberships/octocat"));
assertThat(membership.role(), is("maintainer"));
assertThat(membership.state(), is("active"));
}
Expand All @@ -167,15 +166,14 @@ public void listTeamMembers() throws Exception {
@Test
public void updateMembership() throws Exception {
final MembershipCreate membershipCreateRequest =
json.fromJson(
getFixture("membership_update.json"),
MembershipCreate.class);
json.fromJson(getFixture("membership_update.json"), MembershipCreate.class);

final CompletableFuture<Membership> fixtureResponse = completedFuture(json.fromJson(
getFixture("membership_update_response.json"),
Membership.class));
final CompletableFuture<Membership> fixtureResponse =
completedFuture(
json.fromJson(getFixture("membership_update_response.json"), Membership.class));
when(github.put(any(), any(), eq(Membership.class))).thenReturn(fixtureResponse);
final CompletableFuture<Membership> actualResponse = teamClient.updateMembership(membershipCreateRequest, "1", "octocat");
final CompletableFuture<Membership> actualResponse =
teamClient.updateMembership(membershipCreateRequest, "1", "octocat");

assertThat(actualResponse.get().role(), is("member"));
}
Expand All @@ -194,9 +192,12 @@ public void deleteMembership() throws Exception {
@Test
public void listPendingTeamInvitations() throws Exception {
final CompletableFuture<List<TeamInvitation>> fixture =
completedFuture(json.fromJson(getFixture("list_team_invitations.json"), LIST_PENDING_TEAM_INVITATIONS));
when(github.request("/orgs/github/teams/1/invitations", LIST_PENDING_TEAM_INVITATIONS)).thenReturn(fixture);
final List<TeamInvitation> pendingInvitations = teamClient.listPendingTeamInvitations("1").get();
completedFuture(
json.fromJson(getFixture("list_team_invitations.json"), LIST_PENDING_TEAM_INVITATIONS));
when(github.request("/orgs/github/teams/1/invitations", LIST_PENDING_TEAM_INVITATIONS))
.thenReturn(fixture);
final List<TeamInvitation> pendingInvitations =
teamClient.listPendingTeamInvitations("1").get();
assertThat(pendingInvitations.get(0).login(), is("octocat"));
assertThat(pendingInvitations.get(1).id(), is(2));
assertThat(pendingInvitations.size(), is(2));
Expand Down