Skip to content

Commit 8e73065

Browse files
Support make_latest when creating/updating a release (#1676)
* Support make_latest when creating/updating a release * Add tests * Update src/main/java/org/kohsuke/github/GHReleaseBuilder.java --------- Co-authored-by: Liam Newman <[email protected]>
1 parent 8b80485 commit 8e73065

21 files changed

+1025
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
44

55
import java.io.IOException;
6+
import java.util.Locale;
67

78
// TODO: Auto-generated Javadoc
89
/**
@@ -103,6 +104,41 @@ public GHReleaseBuilder categoryName(String categoryName) {
103104
return this;
104105
}
105106

107+
/**
108+
* Values for whether this release should be the latest.
109+
*/
110+
public static enum MakeLatest {
111+
112+
/** Make this the latest release */
113+
TRUE,
114+
/** Do not make this the latest release */
115+
FALSE,
116+
/** Latest release is determined by date and higher semantic version */
117+
LEGACY;
118+
119+
/**
120+
* To string.
121+
*
122+
* @return the string
123+
*/
124+
@Override
125+
public String toString() {
126+
return name().toLowerCase(Locale.ROOT);
127+
}
128+
}
129+
130+
/**
131+
* Optional.
132+
*
133+
* @param latest
134+
* Whether to make this the latest release. Default is {@code TRUE}
135+
* @return the gh release builder
136+
*/
137+
public GHReleaseBuilder makeLatest(MakeLatest latest) {
138+
builder.with("make_latest", latest);
139+
return this;
140+
}
141+
106142
/**
107143
* Create gh release.
108144
*

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ public GHReleaseUpdater categoryName(String categoryName) {
110110
return this;
111111
}
112112

113+
/**
114+
* Optional.
115+
*
116+
* @param latest
117+
* Whether to make this the latest release. Default is {@code TRUE}
118+
* @return the gh release builder
119+
*/
120+
public GHReleaseUpdater makeLatest(GHReleaseBuilder.MakeLatest latest) {
121+
builder.with("make_latest", latest);
122+
return this;
123+
}
124+
113125
/**
114126
* Update gh release.
115127
*

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.kohsuke.github;
22

33
import org.junit.Test;
4+
import org.kohsuke.github.GHReleaseBuilder.MakeLatest;
45

56
import static org.hamcrest.Matchers.*;
67
import static org.junit.Assert.assertThrows;
@@ -162,4 +163,39 @@ public void testDeleteRelease() throws Exception {
162163
assertThat(repo.getRelease(release.getId()), nullValue());
163164

164165
}
166+
167+
/**
168+
* Test making a release the latest
169+
*
170+
* @throws Exception
171+
* the exception
172+
*/
173+
@Test
174+
public void testMakeLatestRelease() throws Exception {
175+
GHRepository repo = getTempRepository();
176+
177+
GHRelease release1 = repo.createRelease("tag1").create();
178+
GHRelease release2 = null;
179+
180+
try {
181+
// Newly created release should also be the latest.
182+
GHRelease latestRelease = repo.getLatestRelease();
183+
assertThat(release1.getNodeId(), is(latestRelease.getNodeId()));
184+
185+
// Create a second release, explicitly set it not to be latest, confirm it isn't
186+
release2 = repo.createRelease("tag2").makeLatest(MakeLatest.FALSE).create();
187+
latestRelease = repo.getLatestRelease();
188+
assertThat(release1.getNodeId(), is(latestRelease.getNodeId()));
189+
190+
// Update the second release to be latest, confirm it is.
191+
release2.update().makeLatest(MakeLatest.TRUE).update();
192+
latestRelease = repo.getLatestRelease();
193+
assertThat(release2.getNodeId(), is(latestRelease.getNodeId()));
194+
} finally {
195+
release1.delete();
196+
if (release2 != null) {
197+
release2.delete();
198+
}
199+
}
200+
}
165201
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"id": 653172669,
3+
"node_id": "R_kgDOJu6fvQ",
4+
"name": "temp-testMakeLatestRelease",
5+
"full_name": "hub4j-test-org/temp-testMakeLatestRelease",
6+
"private": false,
7+
"owner": {
8+
"login": "hub4j-test-org",
9+
"id": 7544739,
10+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/hub4j-test-org",
14+
"html_url": "https://github.com/hub4j-test-org",
15+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
16+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
20+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
21+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
22+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
24+
"type": "Organization",
25+
"site_admin": false
26+
},
27+
"html_url": "https://github.com/hub4j-test-org/temp-testMakeLatestRelease",
28+
"description": "A test repository for testing the github-api project: temp-testMakeLatestRelease",
29+
"fork": false,
30+
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease",
31+
"forks_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/forks",
32+
"keys_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/keys{/key_id}",
33+
"collaborators_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/collaborators{/collaborator}",
34+
"teams_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/teams",
35+
"hooks_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/hooks",
36+
"issue_events_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/issues/events{/number}",
37+
"events_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/events",
38+
"assignees_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/assignees{/user}",
39+
"branches_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/branches{/branch}",
40+
"tags_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/tags",
41+
"blobs_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/git/blobs{/sha}",
42+
"git_tags_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/git/tags{/sha}",
43+
"git_refs_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/git/refs{/sha}",
44+
"trees_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/git/trees{/sha}",
45+
"statuses_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/statuses/{sha}",
46+
"languages_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/languages",
47+
"stargazers_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/stargazers",
48+
"contributors_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/contributors",
49+
"subscribers_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/subscribers",
50+
"subscription_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/subscription",
51+
"commits_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/commits{/sha}",
52+
"git_commits_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/git/commits{/sha}",
53+
"comments_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/comments{/number}",
54+
"issue_comment_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/issues/comments{/number}",
55+
"contents_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/contents/{+path}",
56+
"compare_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/compare/{base}...{head}",
57+
"merges_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/merges",
58+
"archive_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/{archive_format}{/ref}",
59+
"downloads_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/downloads",
60+
"issues_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/issues{/number}",
61+
"pulls_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/pulls{/number}",
62+
"milestones_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/milestones{/number}",
63+
"notifications_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/notifications{?since,all,participating}",
64+
"labels_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/labels{/name}",
65+
"releases_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases{/id}",
66+
"deployments_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/deployments",
67+
"created_at": "2023-06-13T14:34:30Z",
68+
"updated_at": "2023-06-13T14:34:31Z",
69+
"pushed_at": "2023-06-13T14:34:31Z",
70+
"git_url": "git://github.com/hub4j-test-org/temp-testMakeLatestRelease.git",
71+
"ssh_url": "[email protected]:hub4j-test-org/temp-testMakeLatestRelease.git",
72+
"clone_url": "https://github.com/hub4j-test-org/temp-testMakeLatestRelease.git",
73+
"svn_url": "https://github.com/hub4j-test-org/temp-testMakeLatestRelease",
74+
"homepage": "http://github-api.kohsuke.org/",
75+
"size": 0,
76+
"stargazers_count": 0,
77+
"watchers_count": 0,
78+
"language": null,
79+
"has_issues": true,
80+
"has_projects": true,
81+
"has_downloads": true,
82+
"has_wiki": true,
83+
"has_pages": false,
84+
"has_discussions": false,
85+
"forks_count": 0,
86+
"mirror_url": null,
87+
"archived": false,
88+
"disabled": false,
89+
"open_issues_count": 0,
90+
"license": null,
91+
"allow_forking": true,
92+
"is_template": false,
93+
"web_commit_signoff_required": false,
94+
"topics": [],
95+
"visibility": "public",
96+
"forks": 0,
97+
"open_issues": 0,
98+
"watchers": 0,
99+
"default_branch": "main",
100+
"permissions": {
101+
"admin": true,
102+
"maintain": true,
103+
"push": true,
104+
"triage": true,
105+
"pull": true
106+
},
107+
"temp_clone_token": "",
108+
"allow_squash_merge": true,
109+
"allow_merge_commit": true,
110+
"allow_rebase_merge": true,
111+
"allow_auto_merge": false,
112+
"delete_branch_on_merge": false,
113+
"allow_update_branch": false,
114+
"use_squash_pr_title_as_default": false,
115+
"squash_merge_commit_message": "COMMIT_MESSAGES",
116+
"squash_merge_commit_title": "COMMIT_OR_PR_TITLE",
117+
"merge_commit_message": "PR_TITLE",
118+
"merge_commit_title": "MERGE_MESSAGE",
119+
"organization": {
120+
"login": "hub4j-test-org",
121+
"id": 7544739,
122+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
123+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
124+
"gravatar_id": "",
125+
"url": "https://api.github.com/users/hub4j-test-org",
126+
"html_url": "https://github.com/hub4j-test-org",
127+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
128+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
129+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
130+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
131+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
132+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
133+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
134+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
135+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
136+
"type": "Organization",
137+
"site_admin": false
138+
},
139+
"security_and_analysis": {
140+
"secret_scanning": {
141+
"status": "disabled"
142+
},
143+
"secret_scanning_push_protection": {
144+
"status": "disabled"
145+
}
146+
},
147+
"network_count": 0,
148+
"subscribers_count": 0
149+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387464",
3+
"assets_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387464/assets",
4+
"upload_url": "https://uploads.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387464/assets{?name,label}",
5+
"html_url": "https://github.com/hub4j-test-org/temp-testMakeLatestRelease/releases/tag/tag1",
6+
"id": 108387464,
7+
"author": {
8+
"login": "nikclayton",
9+
"id": 773100,
10+
"node_id": "MDQ6VXNlcjc3MzEwMA==",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/773100?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/nikclayton",
14+
"html_url": "https://github.com/nikclayton",
15+
"followers_url": "https://api.github.com/users/nikclayton/followers",
16+
"following_url": "https://api.github.com/users/nikclayton/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/nikclayton/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/nikclayton/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/nikclayton/subscriptions",
20+
"organizations_url": "https://api.github.com/users/nikclayton/orgs",
21+
"repos_url": "https://api.github.com/users/nikclayton/repos",
22+
"events_url": "https://api.github.com/users/nikclayton/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/nikclayton/received_events",
24+
"type": "User",
25+
"site_admin": false
26+
},
27+
"node_id": "RE_kwDOJu6fvc4GddyI",
28+
"tag_name": "tag1",
29+
"target_commitish": "main",
30+
"name": null,
31+
"draft": false,
32+
"prerelease": false,
33+
"created_at": "2023-06-13T14:34:31Z",
34+
"published_at": "2023-06-13T14:34:35Z",
35+
"assets": [],
36+
"tarball_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/tarball/tag1",
37+
"zipball_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/zipball/tag1",
38+
"body": null
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387467",
3+
"assets_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387467/assets",
4+
"upload_url": "https://uploads.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387467/assets{?name,label}",
5+
"html_url": "https://github.com/hub4j-test-org/temp-testMakeLatestRelease/releases/tag/tag2",
6+
"id": 108387467,
7+
"author": {
8+
"login": "nikclayton",
9+
"id": 773100,
10+
"node_id": "MDQ6VXNlcjc3MzEwMA==",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/773100?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/nikclayton",
14+
"html_url": "https://github.com/nikclayton",
15+
"followers_url": "https://api.github.com/users/nikclayton/followers",
16+
"following_url": "https://api.github.com/users/nikclayton/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/nikclayton/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/nikclayton/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/nikclayton/subscriptions",
20+
"organizations_url": "https://api.github.com/users/nikclayton/orgs",
21+
"repos_url": "https://api.github.com/users/nikclayton/repos",
22+
"events_url": "https://api.github.com/users/nikclayton/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/nikclayton/received_events",
24+
"type": "User",
25+
"site_admin": false
26+
},
27+
"node_id": "RE_kwDOJu6fvc4GddyL",
28+
"tag_name": "tag2",
29+
"target_commitish": "main",
30+
"name": null,
31+
"draft": false,
32+
"prerelease": false,
33+
"created_at": "2023-06-13T14:34:31Z",
34+
"published_at": "2023-06-13T14:34:36Z",
35+
"assets": [],
36+
"tarball_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/tarball/tag2",
37+
"zipball_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/zipball/tag2",
38+
"body": null
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387467",
3+
"assets_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387467/assets",
4+
"upload_url": "https://uploads.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387467/assets{?name,label}",
5+
"html_url": "https://github.com/hub4j-test-org/temp-testMakeLatestRelease/releases/tag/tag2",
6+
"id": 108387467,
7+
"author": {
8+
"login": "nikclayton",
9+
"id": 773100,
10+
"node_id": "MDQ6VXNlcjc3MzEwMA==",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/773100?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/nikclayton",
14+
"html_url": "https://github.com/nikclayton",
15+
"followers_url": "https://api.github.com/users/nikclayton/followers",
16+
"following_url": "https://api.github.com/users/nikclayton/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/nikclayton/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/nikclayton/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/nikclayton/subscriptions",
20+
"organizations_url": "https://api.github.com/users/nikclayton/orgs",
21+
"repos_url": "https://api.github.com/users/nikclayton/repos",
22+
"events_url": "https://api.github.com/users/nikclayton/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/nikclayton/received_events",
24+
"type": "User",
25+
"site_admin": false
26+
},
27+
"node_id": "RE_kwDOJu6fvc4GddyL",
28+
"tag_name": "tag2",
29+
"target_commitish": "main",
30+
"name": null,
31+
"draft": false,
32+
"prerelease": false,
33+
"created_at": "2023-06-13T14:34:31Z",
34+
"published_at": "2023-06-13T14:34:36Z",
35+
"assets": [],
36+
"tarball_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/tarball/tag2",
37+
"zipball_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/zipball/tag2",
38+
"body": null
39+
}

0 commit comments

Comments
 (0)