Skip to content

Commit

Permalink
Switch to the new Teams API
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Mar 4, 2022
1 parent 1165c88 commit 5ff0e46
Show file tree
Hide file tree
Showing 443 changed files with 24,960 additions and 19,554 deletions.
11 changes: 9 additions & 2 deletions src/main/java/org/kohsuke/github/GHTeam.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.net.URL;
Expand Down Expand Up @@ -211,7 +212,7 @@ public Set<GHUser> getMembers() throws IOException {
*/
public boolean hasMember(GHUser user) {
try {
root().createRequest().withUrlPath("/teams/" + getId() + "/members/" + user.getLogin()).send();
root().createRequest().withUrlPath(api("/memberships/" + user.getLogin())).send();
return true;
} catch (IOException ignore) {
return false;
Expand Down Expand Up @@ -345,7 +346,13 @@ public void delete() throws IOException {
}

private String api(String tail) {
return "/teams/" + getId() + tail;
if (organization == null) {
// Teams returned from pull requests to do not have an organization. Attempt to use url.
final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");
return StringUtils.prependIfMissing(url.toString().replace(root().getApiUrl(), ""), "/") + tail;
}

return "/organizations/" + organization.getId() + "/team/" + getId() + tail;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/org/kohsuke/github/GHTeamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public void listMembersNoMatch() throws IOException {

@Test
public void testSetPrivacy() throws IOException {
String teamSlug = "dummy-team";
// we need to use a team that doesn't have child teams
// as secret privacy is not supported for parent teams
String teamSlug = "simple-team";
Privacy privacy = Privacy.CLOSED;

// Set the privacy.
Expand Down

This file was deleted.

Loading

0 comments on commit 5ff0e46

Please sign in to comment.