Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 345d619

Browse filesBrowse files
committed
Support for object deployment payloads.
1 parent a8ef0cd commit 345d619
Copy full SHA for 345d619
Expand file treeCollapse file tree

14 files changed

+604
-8
lines changed

‎src/main/java/org/kohsuke/github/GHDeployment.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHDeployment.java
+20-1Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.net.URL;
5+
import java.util.Map;
56

67
/**
78
* Represents a deployment
@@ -60,13 +61,31 @@ public String getTask() {
6061
}
6162

6263
/**
63-
* Gets payload.
64+
* Gets payload. <b>NOTE:</b> only use this method if you can guarantee the payload will be a simple string, otherwise use {@link #getPayloadObject()}.
6465
*
6566
* @return the payload
6667
*/
6768
public String getPayload() {
6869
return (String) payload;
6970
}
71+
72+
/**
73+
* Gets payload. <b>NOTE:</b> only use this method if you can guarantee the payload will be a JSON object (Map), otherwise use {@link #getPayloadObject()}.
74+
*
75+
* @return the payload
76+
*/
77+
public Map<String, Object> getPayloadMap() {
78+
return (Map<String, Object>) payload;
79+
}
80+
81+
/**
82+
* Gets payload without assuming its type. It could be a String or a Map.
83+
*
84+
* @return the payload
85+
*/
86+
public Object getPayloadObject() {
87+
return payload;
88+
}
7089

7190
/**
7291
* Gets environment.
+33-6Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,53 @@
11
package org.kohsuke.github;
22

3-
import org.junit.Test;
4-
53
import java.io.IOException;
4+
import java.util.Arrays;
5+
import java.util.Map;
6+
7+
import org.junit.Test;
68

79
/**
810
* @author Martin van Zijl
911
*/
1012
public class GHDeploymentTest extends AbstractGitHubWireMockTest {
1113

1214
@Test
13-
public void testGetDeploymentById() throws IOException {
14-
GHRepository repo = getRepository();
15-
GHDeployment deployment = repo.getDeployment(178653229);
15+
public void testGetDeploymentByIdStringPayload() throws IOException {
16+
final GHRepository repo = getRepository();
17+
final GHDeployment deployment = repo.getDeployment(178653229);
18+
assertNotNull(deployment);
19+
assertEquals(178653229, deployment.getId());
20+
assertEquals("production", deployment.getEnvironment());
21+
assertEquals("custom", deployment.getPayload());
22+
assertEquals("custom", deployment.getPayloadObject());
23+
assertEquals("master", deployment.getRef());
24+
assertEquals("3a09d2de4a9a1322a0ba2c3e2f54a919ca8fe353", deployment.getSha());
25+
assertEquals("deploy", deployment.getTask());
26+
}
27+
28+
@Test
29+
public void testGetDeploymentByIdObjectPayload() throws IOException {
30+
final GHRepository repo = getRepository();
31+
final GHDeployment deployment = repo.getDeployment(178653229);
1632
assertNotNull(deployment);
33+
assertEquals(178653229, deployment.getId());
34+
assertEquals("production", deployment.getEnvironment());
35+
assertEquals("master", deployment.getRef());
36+
assertEquals("3a09d2de4a9a1322a0ba2c3e2f54a919ca8fe353", deployment.getSha());
37+
assertEquals("deploy", deployment.getTask());
38+
final Map<String, Object> payload = deployment.getPayloadMap();
39+
assertEquals(4, payload.size());
40+
assertEquals(1, payload.get("custom1"));
41+
assertEquals("two", payload.get("custom2"));
42+
assertEquals(Arrays.asList("3", 3, "three"), payload.get("custom3"));
43+
assertNull(payload.get("custom4"));
1744
}
1845

1946
protected GHRepository getRepository() throws IOException {
2047
return getRepository(gitHub);
2148
}
2249

23-
private GHRepository getRepository(GitHub gitHub) throws IOException {
50+
private GHRepository getRepository(final GitHub gitHub) throws IOException {
2451
return gitHub.getOrganization("hub4j-test-org").getRepository("github-api");
2552
}
2653
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"url": "https://api.github.com/repos/hub4j-test-org/github-api/deployments/178653229",
3+
"id": 178653229,
4+
"node_id": "MDEwOkRlcGxveW1lbnQxNzg2NTMyMjk=",
5+
"sha": "3a09d2de4a9a1322a0ba2c3e2f54a919ca8fe353",
6+
"ref": "master",
7+
"task": "deploy",
8+
"payload": {
9+
"custom1": 1,
10+
"custom2": "two",
11+
"custom3": ["3", 3, "three"],
12+
"custom4": null
13+
},
14+
"original_environment": "production",
15+
"environment": "production",
16+
"description": null,
17+
"creator": {
18+
"login": "martinvanzijl",
19+
"id": 24422213,
20+
"node_id": "MDQ6VXNlcjI0NDIyMjEz",
21+
"avatar_url": "https://avatars0.githubusercontent.com/u/24422213?v=4",
22+
"gravatar_id": "",
23+
"url": "https://api.github.com/users/martinvanzijl",
24+
"html_url": "https://github.com/martinvanzijl",
25+
"followers_url": "https://api.github.com/users/martinvanzijl/followers",
26+
"following_url": "https://api.github.com/users/martinvanzijl/following{/other_user}",
27+
"gists_url": "https://api.github.com/users/martinvanzijl/gists{/gist_id}",
28+
"starred_url": "https://api.github.com/users/martinvanzijl/starred{/owner}{/repo}",
29+
"subscriptions_url": "https://api.github.com/users/martinvanzijl/subscriptions",
30+
"organizations_url": "https://api.github.com/users/martinvanzijl/orgs",
31+
"repos_url": "https://api.github.com/users/martinvanzijl/repos",
32+
"events_url": "https://api.github.com/users/martinvanzijl/events{/privacy}",
33+
"received_events_url": "https://api.github.com/users/martinvanzijl/received_events",
34+
"type": "User",
35+
"site_admin": false
36+
},
37+
"created_at": "2019-10-30T00:03:34Z",
38+
"updated_at": "2019-10-30T00:03:34Z",
39+
"statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api/deployments/178653229/statuses",
40+
"repository_url": "https://api.github.com/repos/hub4j-test-org/github-api"
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"login": "hub4j-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/hub4j-test-org",
6+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j-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/hub4j-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+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.