Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create separate team update request #145

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion src/main/java/com/spotify/github/v3/clients/TeamClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.spotify.github.v3.orgs.TeamInvitation;
import com.spotify.github.v3.orgs.requests.MembershipCreate;
import com.spotify.github.v3.orgs.requests.TeamCreate;
import com.spotify.github.v3.orgs.requests.TeamUpdate;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -107,7 +108,7 @@ public CompletableFuture<List<Team>> listTeams() {
* @param slug slug of the team name
* @return team
*/
public CompletableFuture<Team> updateTeam(final TeamCreate request, final String slug) {
public CompletableFuture<Team> updateTeam(final TeamUpdate request, final String slug) {
final String path = String.format(TEAM_SLUG_TEMPLATE, org, slug);
log.debug("Updating team in: " + path);
return github.patch(path, github.json().toJsonUnchecked(request), Team.class);
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/com/spotify/github/v3/orgs/requests/TeamCreate.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.spotify.github.GithubStyle;
import java.util.ArrayList;
import java.util.Optional;
import javax.annotation.Nullable;
import org.immutables.value.Value;
Expand All @@ -40,17 +41,40 @@ public interface TeamCreate {
/** 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
*/
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
*/
@SuppressWarnings("checkstyle:methodname")
Optional<String> notification_setting();

/**
* List GitHub IDs for organization members who will
* become team maintainers.
*/
Optional<String> maintainers();
Optional<ArrayList<String>> maintainers();
Abhi347 marked this conversation as resolved.
Show resolved Hide resolved

/** The full name (e.g., "organization-name/repository-name")
* of repositories to add the team to.
*/
@SuppressWarnings("checkstyle:methodname")
Optional<String> repo_names();
Optional<ArrayList<String>> repo_names();
Abhi347 marked this conversation as resolved.
Show resolved Hide resolved

/** The ID of a team to set as the parent team. */
@SuppressWarnings("checkstyle:methodname")
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/com/spotify/github/v3/orgs/requests/TeamUpdate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*-
* -\-\-
* github-api
* --
* Copyright (C) 2016 - 2020 Spotify AB
* --
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* -/-/-
*/
package com.spotify.github.v3.orgs.requests;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.spotify.github.GithubStyle;
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 = ImmutableTeamUpdate.class)
@JsonDeserialize(as = ImmutableTeamUpdate.class)
public interface TeamUpdate {

/** 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
*/
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
*/
@SuppressWarnings("checkstyle:methodname")
Optional<String> notification_setting();


/** The ID of a team to set as the parent team. */
@SuppressWarnings("checkstyle:methodname")
Optional<String> parent_team_id();
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.spotify.github.v3.orgs.TeamInvitation;
import com.spotify.github.v3.orgs.requests.MembershipCreate;
import com.spotify.github.v3.orgs.requests.TeamCreate;
import com.spotify.github.v3.orgs.requests.TeamUpdate;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -127,16 +128,16 @@ public void createTeam() throws Exception {

@Test
public void updateTeam() throws Exception {
final TeamCreate teamCreateRequest =
final TeamUpdate teamUpdateRequest =
json.fromJson(
getFixture("teams_patch.json"),
TeamCreate.class);
TeamUpdate.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(teamCreateRequest, "justice-league");
final CompletableFuture<Team> actualResponse = teamClient.updateTeam(teamUpdateRequest, "justice-league");

assertThat(actualResponse.get().name(), is("Justice League2"));
}
Expand Down
Loading