Skip to content

Commit a68a9f2

Browse files
authored
feat: create separate team update request (#145)
* feat: create separate team update request * feat: change string to array list * feat: update from arraylist to list
1 parent 9635ea5 commit a68a9f2

File tree

4 files changed

+102
-6
lines changed

4 files changed

+102
-6
lines changed

src/main/java/com/spotify/github/v3/clients/TeamClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.spotify.github.v3.orgs.TeamInvitation;
3333
import com.spotify.github.v3.orgs.requests.MembershipCreate;
3434
import com.spotify.github.v3.orgs.requests.TeamCreate;
35+
import com.spotify.github.v3.orgs.requests.TeamUpdate;
3536
import java.lang.invoke.MethodHandles;
3637
import java.util.List;
3738
import java.util.concurrent.CompletableFuture;
@@ -107,7 +108,7 @@ public CompletableFuture<List<Team>> listTeams() {
107108
* @param slug slug of the team name
108109
* @return team
109110
*/
110-
public CompletableFuture<Team> updateTeam(final TeamCreate request, final String slug) {
111+
public CompletableFuture<Team> updateTeam(final TeamUpdate request, final String slug) {
111112
final String path = String.format(TEAM_SLUG_TEMPLATE, org, slug);
112113
log.debug("Updating team in: " + path);
113114
return github.patch(path, github.json().toJsonUnchecked(request), Team.class);

src/main/java/com/spotify/github/v3/orgs/requests/TeamCreate.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2323
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2424
import com.spotify.github.GithubStyle;
25+
import java.util.List;
2526
import java.util.Optional;
2627
import javax.annotation.Nullable;
2728
import org.immutables.value.Value;
@@ -40,17 +41,40 @@ public interface TeamCreate {
4041
/** The description of the team. */
4142
Optional<String> description();
4243

44+
/**
45+
* The level of privacy this team should have.
46+
* For a non-nested team:
47+
* secret - only visible to organization owners and members of this team.
48+
* closed - visible to all members of this organization.
49+
* Default: secret
50+
* For a parent or child team:
51+
* closed - visible to all members of this organization.
52+
* Default for child team: closed
53+
* Can be one of: secret, closed
54+
*/
55+
Optional<String> privacy();
56+
57+
/**
58+
* The notification setting the team has chosen. The options are:
59+
* notifications_enabled - team members receive notifications when the team is @mentioned.
60+
* notifications_disabled - no one receives notifications.
61+
* Default: notifications_enabled
62+
* Can be one of: notifications_enabled, notifications_disabled
63+
*/
64+
@SuppressWarnings("checkstyle:methodname")
65+
Optional<String> notification_setting();
66+
4367
/**
4468
* List GitHub IDs for organization members who will
4569
* become team maintainers.
4670
*/
47-
Optional<String> maintainers();
71+
Optional<List<String>> maintainers();
4872

4973
/** The full name (e.g., "organization-name/repository-name")
5074
* of repositories to add the team to.
5175
*/
5276
@SuppressWarnings("checkstyle:methodname")
53-
Optional<String> repo_names();
77+
Optional<List<String>> repo_names();
5478

5579
/** The ID of a team to set as the parent team. */
5680
@SuppressWarnings("checkstyle:methodname")
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*-
2+
* -\-\-
3+
* github-api
4+
* --
5+
* Copyright (C) 2016 - 2020 Spotify AB
6+
* --
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* -/-/-
19+
*/
20+
package com.spotify.github.v3.orgs.requests;
21+
22+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
23+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
24+
import com.spotify.github.GithubStyle;
25+
import java.util.Optional;
26+
import javax.annotation.Nullable;
27+
import org.immutables.value.Value;
28+
29+
/** Request to create a team within a given organisation */
30+
@Value.Immutable
31+
@GithubStyle
32+
@JsonSerialize(as = ImmutableTeamUpdate.class)
33+
@JsonDeserialize(as = ImmutableTeamUpdate.class)
34+
public interface TeamUpdate {
35+
36+
/** The name of the team. */
37+
@Nullable
38+
String name();
39+
40+
/** The description of the team. */
41+
Optional<String> description();
42+
43+
/**
44+
* The level of privacy this team should have.
45+
* For a non-nested team:
46+
* secret - only visible to organization owners and members of this team.
47+
* closed - visible to all members of this organization.
48+
* Default: secret
49+
* For a parent or child team:
50+
* closed - visible to all members of this organization.
51+
* Default for child team: closed
52+
* Can be one of: secret, closed
53+
*/
54+
Optional<String> privacy();
55+
56+
/**
57+
* The notification setting the team has chosen. The options are:
58+
* notifications_enabled - team members receive notifications when the team is @mentioned.
59+
* notifications_disabled - no one receives notifications.
60+
* Default: notifications_enabled
61+
* Can be one of: notifications_enabled, notifications_disabled
62+
*/
63+
@SuppressWarnings("checkstyle:methodname")
64+
Optional<String> notification_setting();
65+
66+
67+
/** The ID of a team to set as the parent team. */
68+
@SuppressWarnings("checkstyle:methodname")
69+
Optional<String> parent_team_id();
70+
}

src/test/java/com/spotify/github/v3/clients/TeamClientTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.spotify.github.v3.orgs.TeamInvitation;
4343
import com.spotify.github.v3.orgs.requests.MembershipCreate;
4444
import com.spotify.github.v3.orgs.requests.TeamCreate;
45+
import com.spotify.github.v3.orgs.requests.TeamUpdate;
4546
import java.io.IOException;
4647
import java.util.List;
4748
import java.util.concurrent.CompletableFuture;
@@ -127,16 +128,16 @@ public void createTeam() throws Exception {
127128

128129
@Test
129130
public void updateTeam() throws Exception {
130-
final TeamCreate teamCreateRequest =
131+
final TeamUpdate teamUpdateRequest =
131132
json.fromJson(
132133
getFixture("teams_patch.json"),
133-
TeamCreate.class);
134+
TeamUpdate.class);
134135

135136
final CompletableFuture<Team> fixtureResponse = completedFuture(json.fromJson(
136137
getFixture("teams_patch_response.json"),
137138
Team.class));
138139
when(github.patch(any(), any(), eq(Team.class))).thenReturn(fixtureResponse);
139-
final CompletableFuture<Team> actualResponse = teamClient.updateTeam(teamCreateRequest, "justice-league");
140+
final CompletableFuture<Team> actualResponse = teamClient.updateTeam(teamUpdateRequest, "justice-league");
140141

141142
assertThat(actualResponse.get().name(), is("Justice League2"));
142143
}

0 commit comments

Comments
 (0)