Skip to content

Commit 8dadafe

Browse files
committed
refactor: use enum types for setPermission and setNotificationSetting
Addresses review feedback from @rozza-sb on #2219: - setNotificationSetting now takes a new GHTeam.NotificationSetting enum (NOTIFICATIONS_ENABLED / NOTIFICATIONS_DISABLED) instead of a raw String. The enum overrides toString() to return the exact API values and is passed to .with("notification_setting", ...) as a String so transformEnum() doesn't rewrite the underscores. - setPermission now takes GHOrganization.Permission (ADMIN, MAINTAIN, PULL, PUSH, TRIAGE) so callers can only pass valid values. The enum names lowercase cleanly into the API values the Teams endpoint expects, and reuses the enum that already exists in this package instead of inventing a new team-scoped one.
1 parent 76c5506 commit 8dadafe

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

src/main/java/org/kohsuke/github/GHTeam.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ public enum Privacy {
3434
UNKNOWN
3535
}
3636

37+
/**
38+
* Notification setting for a team. Controls whether members receive notifications when the team is mentioned.
39+
*/
40+
public enum NotificationSetting {
41+
42+
/** Notifications enabled: members receive notifications when the team is @mentioned. */
43+
NOTIFICATIONS_ENABLED("notifications_enabled"),
44+
/** Notifications disabled: mentions of the team do not generate notifications. */
45+
NOTIFICATIONS_DISABLED("notifications_disabled");
46+
47+
private final String apiValue;
48+
49+
NotificationSetting(String apiValue) {
50+
this.apiValue = apiValue;
51+
}
52+
53+
@Override
54+
public String toString() {
55+
return apiValue;
56+
}
57+
}
58+
3759
/**
3860
* Member's role in a team.
3961
*/
@@ -527,14 +549,14 @@ public void setName(String name) throws IOException {
527549
* Sets the team's notification setting.
528550
*
529551
* @param notificationSetting
530-
* the notification setting (e.g. "notifications_enabled" or "notifications_disabled")
552+
* the notification setting
531553
* @throws IOException
532554
* the io exception
533555
*/
534-
public void setNotificationSetting(String notificationSetting) throws IOException {
556+
public void setNotificationSetting(NotificationSetting notificationSetting) throws IOException {
535557
root().createRequest()
536558
.method("PATCH")
537-
.with("notification_setting", notificationSetting)
559+
.with("notification_setting", notificationSetting.toString())
538560
.withUrlPath(api(""))
539561
.send();
540562
}
@@ -543,11 +565,11 @@ public void setNotificationSetting(String notificationSetting) throws IOExceptio
543565
* Sets the team's permission.
544566
*
545567
* @param permission
546-
* the permission (e.g. "pull", "push", or "admin")
568+
* the permission
547569
* @throws IOException
548570
* the io exception
549571
*/
550-
public void setPermission(String permission) throws IOException {
572+
public void setPermission(GHOrganization.Permission permission) throws IOException {
551573
root().createRequest().method("PATCH").with("permission", permission).withUrlPath(api("")).send();
552574
}
553575

0 commit comments

Comments
 (0)