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

Support team, team_add, member and membership payloads #1818

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
167 changes: 166 additions & 1 deletion src/main/java/org/kohsuke/github/GHEventPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@
* A project v2 item was archived, converted, created, edited, restored, deleted, or reordered.
*
* @see <a href=
* "https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#projects_v2_item">star
* "https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#projects_v2_item">projects_v2_item
* event</a>
*/
public static class ProjectsV2Item extends GHEventPayload {
Expand All @@ -1839,4 +1839,169 @@
return changes;
}
}

/**
* A team_add event was triggered.
*
* @see <a href="https://docs.github.com/en/webhooks/webhook-events-and-payloads#team_add">team_add event</a>
*/
public static class TeamAdd extends GHEventPayload {

private GHTeam team;

/**
* Gets the team.
*
* @return the team
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public GHTeam getTeam() {
return team;
}

/**
* Late bind.
*/
@Override
void lateBind() {
if (team == null) {
throw new IllegalStateException(

Check warning on line 1868 in src/main/java/org/kohsuke/github/GHEventPayload.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kohsuke/github/GHEventPayload.java#L1868

Added line #L1868 was not covered by tests
"Expected team payload, but got something else. Maybe we've got another type of event?");
}
super.lateBind();
GHOrganization organization = getOrganization();
if (organization == null) {
throw new IllegalStateException("Organization must not be null");

Check warning on line 1874 in src/main/java/org/kohsuke/github/GHEventPayload.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kohsuke/github/GHEventPayload.java#L1874

Added line #L1874 was not covered by tests
}
team.wrapUp(organization);
}
}

/**
* A team event was triggered.
*
* @see <a href="https://docs.github.com/en/webhooks/webhook-events-and-payloads#team">team event</a>
*/
public static class Team extends GHEventPayload {

private GHTeam team;

private GHTeamChanges changes;

/**
* Gets the team.
*
* @return the team
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public GHTeam getTeam() {
return team;
}

/**
* Gets the changes made to the team.
*
* @return the changes made to the team
*/
bitwiseman marked this conversation as resolved.
Show resolved Hide resolved
public GHTeamChanges getChanges() {
return changes;
}

/**
* Late bind.
*/
@Override
void lateBind() {
if (team == null) {
throw new IllegalStateException(

Check warning on line 1916 in src/main/java/org/kohsuke/github/GHEventPayload.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kohsuke/github/GHEventPayload.java#L1916

Added line #L1916 was not covered by tests
"Expected team payload, but got something else. Maybe we've got another type of event?");
}
super.lateBind();
GHOrganization organization = getOrganization();
if (organization == null) {
throw new IllegalStateException("Organization must not be null");

Check warning on line 1922 in src/main/java/org/kohsuke/github/GHEventPayload.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kohsuke/github/GHEventPayload.java#L1922

Added line #L1922 was not covered by tests
}
team.wrapUp(organization);
}
}

/**
* A member event was triggered.
*
* @see <a href="https://docs.github.com/en/webhooks/webhook-events-and-payloads#member">member event</a>
*/
public static class Member extends GHEventPayload {

private GHUser member;

private GHMemberChanges changes;

/**
* Gets the member.
*
* @return the member
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public GHUser getMember() {
return member;
}

/**
* Gets the changes made to the member.
*
* @return the changes made to the member
*/
public GHMemberChanges getChanges() {
return changes;
}
}

/**
* A membership event was triggered.
*
* @see <a href="https://docs.github.com/en/webhooks/webhook-events-and-payloads#membership">membership event</a>
*/
public static class Membership extends GHEventPayload {

private GHTeam team;

private GHUser member;

/**
* Gets the team.
*
* @return the team
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public GHTeam getTeam() {
return team;
}

/**
* Gets the member.
*
* @return the member
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public GHUser getMember() {
return member;
}

/**
* Late bind.
*/
@Override
void lateBind() {
if (team == null) {
throw new IllegalStateException(

Check warning on line 1996 in src/main/java/org/kohsuke/github/GHEventPayload.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kohsuke/github/GHEventPayload.java#L1996

Added line #L1996 was not covered by tests
"Expected membership payload, but got something else. Maybe we've got another type of event?");
}
super.lateBind();
GHOrganization organization = getOrganization();
if (organization == null) {
throw new IllegalStateException("Organization must not be null");

Check warning on line 2002 in src/main/java/org/kohsuke/github/GHEventPayload.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kohsuke/github/GHEventPayload.java#L2002

Added line #L2002 was not covered by tests
}
team.wrapUp(organization);
}
}
}
52 changes: 52 additions & 0 deletions src/main/java/org/kohsuke/github/GHMemberChanges.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.kohsuke.github.internal.EnumUtils;

/**
* Changes made to a team.
*/
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
public class GHMemberChanges {

private FromToPermission permission;

/**
* Get changes to permission.
*
* @return changes to permission
*/
public FromToPermission getPermission() {
return permission;
Comment on lines +12 to +20
Copy link
Member

@bitwiseman bitwiseman Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gsmet
Ugh. The events api is all over the place. The added action has a role_name and states that permission is obsolete. But the edited action has permission and old_permission, with no note about either of those being obsolete. And they both are returned under the changes parameter.

https://docs.github.com/en/webhooks/webhook-events-and-payloads?actionType=added#member
https://docs.github.com/en/webhooks/webhook-events-and-payloads?actionType=edited#member

I guess this class is okay. It is incomplete, but the other fields can be added later without causing a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some tests for permission and old_permission wasn’t there.

I need to check for role_name though. I will have a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah so that's what I thought, role_name wasn't in the payload I obtained...

They might change it at some point, I don't know. I'll have a look at adding role_name for a future version but it's going to be untested.

}

/**
* Changes to permission.
*/
public static class FromToPermission {

private String from;

private String to;

/**
* Gets the from.
*
* @return the from
*/
public GHOrganization.Permission getFrom() {
return EnumUtils
.getNullableEnumOrDefault(GHOrganization.Permission.class, from, GHOrganization.Permission.UNKNOWN);
}

/**
* Gets the to.
*
* @return the to
*/
public GHOrganization.Permission getTo() {
return EnumUtils
.getNullableEnumOrDefault(GHOrganization.Permission.class, to, GHOrganization.Permission.UNKNOWN);
}
}
}
4 changes: 3 additions & 1 deletion src/main/java/org/kohsuke/github/GHOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ public enum Permission {
/** The triage. */
TRIAGE,
/** The pull. */
PULL
PULL,
/** Unknown, before we add the new permission to the enum */
UNKNOWN
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public GHDeploymentStatusBuilder createDeployStatus(int deploymentId, GHDeployme
return getDeployment(deploymentId).createStatus(ghDeploymentState);
}

private static class GHRepoPermission {
static class GHRepoPermission {
boolean pull, push, admin;
}

Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/kohsuke/github/GHTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.StringUtils;
import org.kohsuke.github.internal.EnumUtils;

import java.io.IOException;
import java.net.URL;
Expand All @@ -27,7 +28,7 @@ public class GHTeam extends GHObject implements Refreshable {
private String permission;
private String slug;
private String description;
private Privacy privacy;
private String privacy;

private GHOrganization organization; // populated by GET /user/teams where Teams+Orgs are returned together

Expand All @@ -40,7 +41,9 @@ public enum Privacy {
SECRET,
/** The closed. */
// only visible to organization owners and members of this team.
CLOSED // visible to all members of this organization.
CLOSED, // visible to all members of this organization.
/** Unknown privacy value */
UNKNOWN
}

/**
Expand Down Expand Up @@ -122,7 +125,7 @@ public String getDescription() {
* @return the privacy state.
*/
public Privacy getPrivacy() {
return privacy;
return EnumUtils.getNullableEnumOrDefault(Privacy.class, privacy, Privacy.UNKNOWN);
}

/**
Expand Down Expand Up @@ -473,7 +476,7 @@ public boolean equals(Object o) {
GHTeam ghTeam = (GHTeam) o;
return Objects.equals(name, ghTeam.name) && Objects.equals(getUrl(), ghTeam.getUrl())
&& Objects.equals(permission, ghTeam.permission) && Objects.equals(slug, ghTeam.slug)
&& Objects.equals(description, ghTeam.description) && privacy == ghTeam.privacy;
&& Objects.equals(description, ghTeam.description) && Objects.equals(privacy, ghTeam.privacy);
}

/**
Expand Down
Loading