Skip to content

Commit 5026262

Browse files
authored
Merge pull request hub4j#578 from martinvanzijl/issue_457_create_team_with_repo_access_fix
GHOrganization.createTeam now adds team to specified repositories
2 parents 5b53fba + 3892e6e commit 5026262

12 files changed

+816
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public GHTeam createTeam(String name, Permission p, Collection<GHRepository> rep
239239
Requester post = new Requester(root).with("name", name).with("permission", p);
240240
List<String> repo_names = new ArrayList<String>();
241241
for (GHRepository r : repositories) {
242-
repo_names.add(r.getName());
242+
repo_names.add(login + "/" + r.getName());
243243
}
244244
post.with("repo_names",repo_names);
245245
return post.method("POST").to("/orgs/" + login + "/teams", GHTeam.class).wrapUp(this);

src/test/java/org/kohsuke/github/GHOrganizationTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,24 @@
1111
public class GHOrganizationTest extends AbstractGitHubWireMockTest {
1212

1313
public static final String GITHUB_API_TEST = "github-api-test";
14+
public static final String TEAM_NAME_CREATE = "create-team-test";
1415

1516

17+
@Before
18+
@After
19+
public void cleanUpTeam() throws IOException {
20+
// Cleanup is only needed when proxying
21+
if (!mockGitHub.isUseProxy()) {
22+
return;
23+
}
24+
25+
GHTeam team = gitHubBeforeAfter.getOrganization(GITHUB_API_TEST_ORG).
26+
getTeamByName(TEAM_NAME_CREATE);
27+
if (team != null) {
28+
team.delete();
29+
}
30+
}
31+
1632
@Test
1733
public void testCreateRepository() throws IOException {
1834
cleanupRepository(GITHUB_API_TEST_ORG + '/' + GITHUB_API_TEST);
@@ -57,4 +73,17 @@ public void testInviteUser() throws IOException {
5773
// Check the invitation has worked.
5874
// assertTrue(org.hasMember(user));
5975
}
76+
77+
78+
@Test
79+
public void testCreateTeamWithRepoAccess() throws IOException {
80+
String REPO_NAME = "github-api";
81+
82+
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
83+
GHRepository repo = org.getRepository(REPO_NAME);
84+
85+
// Create team with access to repository. Check access was granted.
86+
GHTeam team = org.createTeam(TEAM_NAME_CREATE, GHOrganization.Permission.PUSH, repo);
87+
Assert.assertTrue(team.getRepositories().containsKey(REPO_NAME));
88+
}
6089
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"login": "github-api-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/github-api-test-org",
6+
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
13+
"description": null,
14+
"is_verified": false,
15+
"has_organization_projects": true,
16+
"has_repository_projects": true,
17+
"public_repos": 10,
18+
"public_gists": 0,
19+
"followers": 0,
20+
"following": 0,
21+
"html_url": "https://github.com/github-api-test-org",
22+
"created_at": "2014-05-10T19:39:11Z",
23+
"updated_at": "2015-04-20T00:42:30Z",
24+
"type": "Organization",
25+
"total_private_repos": 0,
26+
"owned_private_repos": 0,
27+
"private_gists": 0,
28+
"disk_usage": 132,
29+
"collaborators": 0,
30+
"billing_email": "kk@kohsuke.org",
31+
"default_repository_permission": "none",
32+
"members_can_create_repositories": false,
33+
"two_factor_requirement_enabled": false,
34+
"plan": {
35+
"name": "free",
36+
"space": 976562499,
37+
"private_repos": 0,
38+
"filled_seats": 7,
39+
"seats": 0
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "create-team-test",
3+
"id": 3501817,
4+
"node_id": "MDQ6VGVhbTM1MDE4MTc=",
5+
"slug": "create-team-test",
6+
"description": null,
7+
"privacy": "secret",
8+
"url": "https://api.github.com/teams/3501817",
9+
"html_url": "https://github.com/orgs/github-api-test-org/teams/create-team-test",
10+
"members_url": "https://api.github.com/teams/3501817/members{/member}",
11+
"repositories_url": "https://api.github.com/teams/3501817/repos",
12+
"permission": "push",
13+
"created_at": "2019-11-01T16:29:09Z",
14+
"updated_at": "2019-11-01T16:29:09Z",
15+
"members_count": 0,
16+
"repos_count": 1,
17+
"organization": {
18+
"login": "github-api-test-org",
19+
"id": 7544739,
20+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
21+
"url": "https://api.github.com/orgs/github-api-test-org",
22+
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
23+
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
24+
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
25+
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
26+
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
27+
"public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}",
28+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
29+
"description": null,
30+
"is_verified": false,
31+
"has_organization_projects": true,
32+
"has_repository_projects": true,
33+
"public_repos": 10,
34+
"public_gists": 0,
35+
"followers": 0,
36+
"following": 0,
37+
"html_url": "https://github.com/github-api-test-org",
38+
"created_at": "2014-05-10T19:39:11Z",
39+
"updated_at": "2015-04-20T00:42:30Z",
40+
"type": "Organization"
41+
}
42+
}

0 commit comments

Comments
 (0)