Skip to content

Commit

Permalink
Support make_latest when creating/updating a release (#1676)
Browse files Browse the repository at this point in the history
* Support make_latest when creating/updating a release

* Add tests

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

---------

Co-authored-by: Liam Newman <bitwiseman@gmail.com>
  • Loading branch information
nikclayton and bitwiseman committed Jun 14, 2023
1 parent 8b80485 commit 8e73065
Show file tree
Hide file tree
Showing 21 changed files with 1,025 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/main/java/org/kohsuke/github/GHReleaseBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.util.Locale;

// TODO: Auto-generated Javadoc
/**
Expand Down Expand Up @@ -103,6 +104,41 @@ public GHReleaseBuilder categoryName(String categoryName) {
return this;
}

/**
* Values for whether this release should be the latest.
*/
public static enum MakeLatest {

/** Make this the latest release */
TRUE,
/** Do not make this the latest release */
FALSE,
/** Latest release is determined by date and higher semantic version */
LEGACY;

/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
return name().toLowerCase(Locale.ROOT);
}
}

/**
* Optional.
*
* @param latest
* Whether to make this the latest release. Default is {@code TRUE}
* @return the gh release builder
*/
public GHReleaseBuilder makeLatest(MakeLatest latest) {
builder.with("make_latest", latest);
return this;
}

/**
* Create gh release.
*
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/kohsuke/github/GHReleaseUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ public GHReleaseUpdater categoryName(String categoryName) {
return this;
}

/**
* Optional.
*
* @param latest
* Whether to make this the latest release. Default is {@code TRUE}
* @return the gh release builder
*/
public GHReleaseUpdater makeLatest(GHReleaseBuilder.MakeLatest latest) {
builder.with("make_latest", latest);
return this;
}

/**
* Update gh release.
*
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/org/kohsuke/github/GHReleaseTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kohsuke.github;

import org.junit.Test;
import org.kohsuke.github.GHReleaseBuilder.MakeLatest;

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

}

/**
* Test making a release the latest
*
* @throws Exception
* the exception
*/
@Test
public void testMakeLatestRelease() throws Exception {
GHRepository repo = getTempRepository();

GHRelease release1 = repo.createRelease("tag1").create();
GHRelease release2 = null;

try {
// Newly created release should also be the latest.
GHRelease latestRelease = repo.getLatestRelease();
assertThat(release1.getNodeId(), is(latestRelease.getNodeId()));

// Create a second release, explicitly set it not to be latest, confirm it isn't
release2 = repo.createRelease("tag2").makeLatest(MakeLatest.FALSE).create();
latestRelease = repo.getLatestRelease();
assertThat(release1.getNodeId(), is(latestRelease.getNodeId()));

// Update the second release to be latest, confirm it is.
release2.update().makeLatest(MakeLatest.TRUE).update();
latestRelease = repo.getLatestRelease();
assertThat(release2.getNodeId(), is(latestRelease.getNodeId()));
} finally {
release1.delete();
if (release2 != null) {
release2.delete();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"id": 653172669,
"node_id": "R_kgDOJu6fvQ",
"name": "temp-testMakeLatestRelease",
"full_name": "hub4j-test-org/temp-testMakeLatestRelease",
"private": false,
"owner": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/hub4j-test-org/temp-testMakeLatestRelease",
"description": "A test repository for testing the github-api project: temp-testMakeLatestRelease",
"fork": false,
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease",
"forks_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/forks",
"keys_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/teams",
"hooks_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/hooks",
"issue_events_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/issues/events{/number}",
"events_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/events",
"assignees_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/assignees{/user}",
"branches_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/branches{/branch}",
"tags_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/tags",
"blobs_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/statuses/{sha}",
"languages_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/languages",
"stargazers_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/stargazers",
"contributors_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/contributors",
"subscribers_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/subscribers",
"subscription_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/subscription",
"commits_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/contents/{+path}",
"compare_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/merges",
"archive_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/downloads",
"issues_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/issues{/number}",
"pulls_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/pulls{/number}",
"milestones_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/milestones{/number}",
"notifications_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/deployments",
"created_at": "2023-06-13T14:34:30Z",
"updated_at": "2023-06-13T14:34:31Z",
"pushed_at": "2023-06-13T14:34:31Z",
"git_url": "git://github.com/hub4j-test-org/temp-testMakeLatestRelease.git",
"ssh_url": "git@github.com:hub4j-test-org/temp-testMakeLatestRelease.git",
"clone_url": "https://github.com/hub4j-test-org/temp-testMakeLatestRelease.git",
"svn_url": "https://github.com/hub4j-test-org/temp-testMakeLatestRelease",
"homepage": "http://github-api.kohsuke.org/",
"size": 0,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"has_discussions": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"allow_forking": true,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [],
"visibility": "public",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main",
"permissions": {
"admin": true,
"maintain": true,
"push": true,
"triage": true,
"pull": true
},
"temp_clone_token": "",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"allow_auto_merge": false,
"delete_branch_on_merge": false,
"allow_update_branch": false,
"use_squash_pr_title_as_default": false,
"squash_merge_commit_message": "COMMIT_MESSAGES",
"squash_merge_commit_title": "COMMIT_OR_PR_TITLE",
"merge_commit_message": "PR_TITLE",
"merge_commit_title": "MERGE_MESSAGE",
"organization": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
"type": "Organization",
"site_admin": false
},
"security_and_analysis": {
"secret_scanning": {
"status": "disabled"
},
"secret_scanning_push_protection": {
"status": "disabled"
}
},
"network_count": 0,
"subscribers_count": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387464",
"assets_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387464/assets",
"upload_url": "https://uploads.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387464/assets{?name,label}",
"html_url": "https://github.com/hub4j-test-org/temp-testMakeLatestRelease/releases/tag/tag1",
"id": 108387464,
"author": {
"login": "nikclayton",
"id": 773100,
"node_id": "MDQ6VXNlcjc3MzEwMA==",
"avatar_url": "https://avatars.githubusercontent.com/u/773100?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nikclayton",
"html_url": "https://github.com/nikclayton",
"followers_url": "https://api.github.com/users/nikclayton/followers",
"following_url": "https://api.github.com/users/nikclayton/following{/other_user}",
"gists_url": "https://api.github.com/users/nikclayton/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nikclayton/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nikclayton/subscriptions",
"organizations_url": "https://api.github.com/users/nikclayton/orgs",
"repos_url": "https://api.github.com/users/nikclayton/repos",
"events_url": "https://api.github.com/users/nikclayton/events{/privacy}",
"received_events_url": "https://api.github.com/users/nikclayton/received_events",
"type": "User",
"site_admin": false
},
"node_id": "RE_kwDOJu6fvc4GddyI",
"tag_name": "tag1",
"target_commitish": "main",
"name": null,
"draft": false,
"prerelease": false,
"created_at": "2023-06-13T14:34:31Z",
"published_at": "2023-06-13T14:34:35Z",
"assets": [],
"tarball_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/tarball/tag1",
"zipball_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/zipball/tag1",
"body": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387467",
"assets_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387467/assets",
"upload_url": "https://uploads.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387467/assets{?name,label}",
"html_url": "https://github.com/hub4j-test-org/temp-testMakeLatestRelease/releases/tag/tag2",
"id": 108387467,
"author": {
"login": "nikclayton",
"id": 773100,
"node_id": "MDQ6VXNlcjc3MzEwMA==",
"avatar_url": "https://avatars.githubusercontent.com/u/773100?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nikclayton",
"html_url": "https://github.com/nikclayton",
"followers_url": "https://api.github.com/users/nikclayton/followers",
"following_url": "https://api.github.com/users/nikclayton/following{/other_user}",
"gists_url": "https://api.github.com/users/nikclayton/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nikclayton/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nikclayton/subscriptions",
"organizations_url": "https://api.github.com/users/nikclayton/orgs",
"repos_url": "https://api.github.com/users/nikclayton/repos",
"events_url": "https://api.github.com/users/nikclayton/events{/privacy}",
"received_events_url": "https://api.github.com/users/nikclayton/received_events",
"type": "User",
"site_admin": false
},
"node_id": "RE_kwDOJu6fvc4GddyL",
"tag_name": "tag2",
"target_commitish": "main",
"name": null,
"draft": false,
"prerelease": false,
"created_at": "2023-06-13T14:34:31Z",
"published_at": "2023-06-13T14:34:36Z",
"assets": [],
"tarball_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/tarball/tag2",
"zipball_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/zipball/tag2",
"body": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387467",
"assets_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387467/assets",
"upload_url": "https://uploads.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/releases/108387467/assets{?name,label}",
"html_url": "https://github.com/hub4j-test-org/temp-testMakeLatestRelease/releases/tag/tag2",
"id": 108387467,
"author": {
"login": "nikclayton",
"id": 773100,
"node_id": "MDQ6VXNlcjc3MzEwMA==",
"avatar_url": "https://avatars.githubusercontent.com/u/773100?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nikclayton",
"html_url": "https://github.com/nikclayton",
"followers_url": "https://api.github.com/users/nikclayton/followers",
"following_url": "https://api.github.com/users/nikclayton/following{/other_user}",
"gists_url": "https://api.github.com/users/nikclayton/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nikclayton/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nikclayton/subscriptions",
"organizations_url": "https://api.github.com/users/nikclayton/orgs",
"repos_url": "https://api.github.com/users/nikclayton/repos",
"events_url": "https://api.github.com/users/nikclayton/events{/privacy}",
"received_events_url": "https://api.github.com/users/nikclayton/received_events",
"type": "User",
"site_admin": false
},
"node_id": "RE_kwDOJu6fvc4GddyL",
"tag_name": "tag2",
"target_commitish": "main",
"name": null,
"draft": false,
"prerelease": false,
"created_at": "2023-06-13T14:34:31Z",
"published_at": "2023-06-13T14:34:36Z",
"assets": [],
"tarball_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/tarball/tag2",
"zipball_url": "https://api.github.com/repos/hub4j-test-org/temp-testMakeLatestRelease/zipball/tag2",
"body": null
}
Loading

0 comments on commit 8e73065

Please sign in to comment.