Skip to content

Commit

Permalink
Deprecated permission field in createTeam & provided alternate method
Browse files Browse the repository at this point in the history
  • Loading branch information
farmdawgnation authored and Anirudh Mathad committed Nov 20, 2019
1 parent a969509 commit d4d2792
Show file tree
Hide file tree
Showing 14 changed files with 932 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/org/kohsuke/github/GHOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ public enum Permission {
* @return the gh team
* @throws IOException
* the io exception
* @deprecated https://developer.github.com/v3/teams/#create-team deprecates permission field use
* {@link #createTeam(String, Collection)}
*/
@Deprecated
public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories) throws IOException {
Requester post = new Requester(root).with("name", name).with("permission", p);
List<String> repo_names = new ArrayList<String>();
Expand All @@ -407,11 +410,50 @@ public GHTeam createTeam(String name, Permission p, Collection<GHRepository> rep
* @return the gh team
* @throws IOException
* the io exception
* @deprecated https://developer.github.com/v3/teams/#create-team deprecates permission field use
* {@link #createTeam(String, GHRepository...)}
*/
@Deprecated
public GHTeam createTeam(String name, Permission p, GHRepository... repositories) throws IOException {
return createTeam(name, p, Arrays.asList(repositories));
}

/**
* Creates a new team and assigns the repositories.
*
* @param name
* the name
* @param repositories
* the repositories
* @return the gh team
* @throws IOException
* the io exception
*/
public GHTeam createTeam(String name, Collection<GHRepository> repositories) throws IOException {
Requester post = new Requester(root).with("name", name);
List<String> repo_names = new ArrayList<String>();
for (GHRepository r : repositories) {
repo_names.add(login + "/" + r.getName());
}
post.with("repo_names", repo_names);
return post.method("POST").to("/orgs/" + login + "/teams", GHTeam.class).wrapUp(this);
}

/**
* Create team gh team.
*
* @param name
* the name
* @param repositories
* the repositories
* @return the gh team
* @throws IOException
* the io exception
*/
public GHTeam createTeam(String name, GHRepository... repositories) throws IOException {
return createTeam(name, Arrays.asList(repositories));
}

/**
* List up repositories that has some open pull requests.
* <p>
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/kohsuke/github/GHOrganizationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.kohsuke.github.GHOrganization.Permission;

import java.io.IOException;

Expand Down Expand Up @@ -85,5 +86,20 @@ public void testCreateTeamWithRepoAccess() throws IOException {
// Create team with access to repository. Check access was granted.
GHTeam team = org.createTeam(TEAM_NAME_CREATE, GHOrganization.Permission.PUSH, repo);
Assert.assertTrue(team.getRepositories().containsKey(REPO_NAME));
Assert.assertEquals(Permission.PUSH.toString().toLowerCase(), team.getPermission());
}

@Test
public void testCreateTeam() throws IOException {
String REPO_NAME = "github-api";
String DEFAULT_PERMISSION = Permission.PULL.toString().toLowerCase();

GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHRepository repo = org.getRepository(REPO_NAME);

// Create team with no permission field. Verify that default permission is pull
GHTeam team = org.createTeam(TEAM_NAME_CREATE, repo);
Assert.assertTrue(team.getRepositories().containsKey(REPO_NAME));
Assert.assertEquals(DEFAULT_PERMISSION, team.getPermission());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"login": "github-api-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"url": "https://api.github.com/orgs/github-api-test-org",
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"description": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 10,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/github-api-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2015-04-20T00:42:30Z",
"type": "Organization",
"total_private_repos": 0,
"owned_private_repos": 0,
"private_gists": 0,
"disk_usage": 132,
"collaborators": 0,
"billing_email": "kk@kohsuke.org",
"default_repository_permission": "none",
"members_can_create_repositories": false,
"two_factor_requirement_enabled": false,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 0,
"filled_seats": 9,
"seats": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "create-team-test",
"id": 3531422,
"node_id": "MDQ6VGVhbTM1MzE0MjI=",
"slug": "create-team-test",
"description": null,
"privacy": "secret",
"url": "https://api.github.com/teams/3531422",
"html_url": "https://github.com/orgs/github-api-test-org/teams/create-team-test",
"members_url": "https://api.github.com/teams/3531422/members{/member}",
"repositories_url": "https://api.github.com/teams/3531422/repos",
"permission": "pull",
"created_at": "2019-11-20T01:07:57Z",
"updated_at": "2019-11-20T01:07:57Z",
"members_count": 0,
"repos_count": 1,
"organization": {
"login": "github-api-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"url": "https://api.github.com/orgs/github-api-test-org",
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"description": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 10,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/github-api-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2015-04-20T00:42:30Z",
"type": "Organization"
}
}
Loading

0 comments on commit d4d2792

Please sign in to comment.