Skip to content

Commit

Permalink
change method names
Browse files Browse the repository at this point in the history
  • Loading branch information
Alaurant committed Dec 3, 2024
1 parent 6574ae2 commit 2ad3c5b
Show file tree
Hide file tree
Showing 39 changed files with 401 additions and 335 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHAutolink.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @author Alaurant
* @see GHAutolinkBuilder
* @see GHRepository#getAutolinks() GHRepository#getAutolinks()
* @see GHRepository#listAutolinks() GHRepository#listAutolinks()
* @see <a href="https://docs.github.com/en/rest/repos/autolinks">Repository autolinks API</a>
*/
public class GHAutolink {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -3386,22 +3386,22 @@ public GHAutolinkBuilder createAutolink() {
}

/**
* Gets all autolinks of a repo (admin only).
* List all autolinks of a repo (admin only).
* (https://docs.github.com/en/rest/repos/autolinks?apiVersion=2022-11-28#get-all-autolinks-of-a-repository)
*
* @return the autolinks
* @throws IOException
* the io exception
*/
public PagedIterable<GHAutolink> getAutolinks() throws IOException {
public PagedIterable<GHAutolink> listAutolinks() throws IOException {
return root().createRequest()
.withHeader("Accept", "application/vnd.github+json")
.withUrlPath(String.format("/repos/%s/%s/autolinks", getOwnerName(), getName()))
.toIterable(GHAutolink[].class, item -> item.wrap(this));
}

/**
* Gets an autolink by ID.
* Read an autolink by ID.
* (https://docs.github.com/en/rest/repos/autolinks?apiVersion=2022-11-28#get-an-autolink-reference-of-a-repository)
*
* @param autolinkId
Expand All @@ -3410,7 +3410,7 @@ public PagedIterable<GHAutolink> getAutolinks() throws IOException {
* @throws IOException
* the io exception
*/
public GHAutolink getAutolink(Integer autolinkId) throws IOException {
public GHAutolink readAutolink(Integer autolinkId) throws IOException {
return root().createRequest()
.withHeader("Accept", "application/vnd.github+json")
.withUrlPath(String.format("/repos/%s/%s/autolinks/%d", getOwnerName(), getName(), autolinkId))
Expand Down
110 changes: 63 additions & 47 deletions src/test/java/org/kohsuke/github/GHAutolinkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.junit.Before;
import org.junit.Test;

import java.util.List;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -31,6 +33,9 @@ public GHAutolinkTest() {
@Before
public void setUp() throws Exception {
repo = gitHub.getRepository("Alaurant/github-api-test");
if (repo == null) {
throw new IllegalStateException("Failed to initialize repository");
}
}

/**
Expand All @@ -57,6 +62,8 @@ public void testCreateAutolink() throws Exception {
assertThat(autolink.isAlphanumeric(), equalTo(isAlphanumeric));
assertThat(autolink.getOwner(), equalTo(repo));

autolink.delete();

}

/**
Expand All @@ -66,21 +73,23 @@ public void testCreateAutolink() throws Exception {
* the exception
*/
@Test
public void testGetAutolink() throws Exception {
public void testReadAutolink() throws Exception {
GHAutolink autolink = repo.createAutolink()
.withKeyPrefix("JIRA-")
.withUrlTemplate("https://example.com/test/<num>")
.withIsAlphanumeric(false)
.create();

GHAutolink fetched = repo.getAutolink(autolink.getId());
GHAutolink fetched = repo.readAutolink(autolink.getId());

assertThat(fetched.getId(), equalTo(autolink.getId()));
assertThat(fetched.getKeyPrefix(), equalTo(autolink.getKeyPrefix()));
assertThat(fetched.getUrlTemplate(), equalTo(autolink.getUrlTemplate()));
assertThat(fetched.isAlphanumeric(), equalTo(autolink.isAlphanumeric()));
assertThat(fetched.getOwner(), equalTo(repo));

autolink.delete();

}

/**
Expand All @@ -90,44 +99,48 @@ public void testGetAutolink() throws Exception {
* the exception
*/
@Test
public void testGetAllAutolinks() throws Exception {
GHAutolink autolink1 = repo.createAutolink()
.withKeyPrefix("LIST-")
.withUrlTemplate("https://example.com/list1/<num>")
.withIsAlphanumeric(true)
.create();

GHAutolink autolink2 = repo.createAutolink()
.withKeyPrefix("LISTED-")
.withUrlTemplate("https://example.com/list2/<num>")
.withIsAlphanumeric(false)
.create();
Thread.sleep(1000);
public void testListAllAutolinks() throws Exception {
assertThat("Initial autolinks should be empty", repo.listAutolinks().toList(), is(empty()));

boolean found1 = false;
boolean found2 = false;

PagedIterable<GHAutolink> autolinks = repo.getAutolinks();

for (GHAutolink autolink : autolinks) {

if (autolink.getId().equals(autolink1.getId())) {
found1 = true;
assertThat(autolink.getKeyPrefix(), equalTo(autolink1.getKeyPrefix()));
assertThat(autolink.getUrlTemplate(), equalTo(autolink1.getUrlTemplate()));
assertThat(autolink.isAlphanumeric(), equalTo(autolink1.isAlphanumeric()));
}
if (autolink.getId().equals(autolink2.getId())) {
found2 = true;
assertThat(autolink.getKeyPrefix(), equalTo(autolink2.getKeyPrefix()));
assertThat(autolink.getUrlTemplate(), equalTo(autolink2.getUrlTemplate()));
assertThat(autolink.isAlphanumeric(), equalTo(autolink2.isAlphanumeric()));
}
try {
GHAutolink autolink1 = repo.createAutolink()
.withKeyPrefix("LIST-")
.withUrlTemplate("https://example.com/list1/<num>")
.withIsAlphanumeric(true)
.create();

GHAutolink autolink2 = repo.createAutolink()
.withKeyPrefix("LISTED-")
.withUrlTemplate("https://example.com/list2/<num>")
.withIsAlphanumeric(false)
.create();

List<GHAutolink> autolinks = repo.listAutolinks().toList();
assertThat("Should have exactly 2 autolinks", ((List<?>) autolinks).size(), is(2));

GHAutolink foundAutolink1 = autolinks.stream()
.filter(a -> a.getId().equals(autolink1.getId()))
.findFirst()
.orElseThrow(() -> new AssertionError("Autolink 1 not found"));

GHAutolink foundAutolink2 = autolinks.stream()
.filter(a -> a.getId().equals(autolink2.getId()))
.findFirst()
.orElseThrow(() -> new AssertionError("Autolink 2 not found"));

assertAutolinksEqual(autolink1, foundAutolink1);
assertAutolinksEqual(autolink2, foundAutolink2);

} catch (Exception e) {
System.err.println("Failed to list autolinks: " + e.getMessage());
}
}

assertThat("First autolink", found1, is(true));
assertThat("Second autolink", found2, is(true));

private void assertAutolinksEqual(GHAutolink expected, GHAutolink actual) {
assertThat(actual.getKeyPrefix(), equalTo(expected.getKeyPrefix()));
assertThat(actual.getUrlTemplate(), equalTo(expected.getUrlTemplate()));
assertThat(actual.isAlphanumeric(), equalTo(expected.isAlphanumeric()));
assertThat(actual.getOwner(), equalTo(expected.getOwner()));
}

/**
Expand All @@ -148,7 +161,7 @@ public void testDeleteAutolink() throws Exception {
autolink.delete();

try {
repo.getAutolink(autolink.getId());
repo.readAutolink(autolink.getId());
fail("Expected GHFileNotFoundException");
} catch (GHFileNotFoundException e) {
// Expected
Expand All @@ -164,7 +177,7 @@ public void testDeleteAutolink() throws Exception {
repo.deleteAutolink(autolink.getId());

try {
repo.getAutolink(autolink.getId());
repo.readAutolink(autolink.getId());
fail("Expected GHFileNotFoundException");
} catch (GHFileNotFoundException e) {
// Expected
Expand All @@ -179,16 +192,19 @@ public void testDeleteAutolink() throws Exception {
*/
@After
public void cleanup() throws Exception {
try {
for (GHAutolink autolink : repo.getAutolinks()) {
try {
autolink.delete();
} catch (GHFileNotFoundException e) {
// Ignore 404 errors during cleanup
if (repo != null) {
try {
PagedIterable<GHAutolink> autolinks = repo.listAutolinks();
for (GHAutolink autolink : autolinks) {
try {
autolink.delete();
} catch (Exception e) {
System.err.println("Failed to delete autolink: " + e.getMessage());
}
}
} catch (Exception e) {
System.err.println("Cleanup failed: " + e.getMessage());
}
} catch (GHFileNotFoundException e) {
// Ignore if no autolinks exist
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"triage": true,
"pull": true
},
"temp_clone_token": "AJ7BLWFPFMVFENAYEGMMQNTHJGX7M",
"temp_clone_token": "AJ7BLWGMBCV4RX4BQQXEBOTHJ2WGQ",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "235d9d84-9cd7-4be8-931c-15eada0775ef",
"id": "a4f46a34-8c81-44e9-bec4-043ba7bdcb10",
"name": "user",
"request": {
"url": "/user",
Expand All @@ -14,7 +14,7 @@
"status": 200,
"bodyFileName": "1-user.json",
"headers": {
"Date": "Fri, 29 Nov 2024 12:08:41 GMT",
"Date": "Tue, 03 Dec 2024 06:54:51 GMT",
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With",
Expand All @@ -26,9 +26,9 @@
"X-GitHub-Media-Type": "github.v3; format=json",
"x-github-api-version-selected": "2022-11-28",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4873",
"X-RateLimit-Reset": "1732885041",
"X-RateLimit-Used": "127",
"X-RateLimit-Remaining": "4953",
"X-RateLimit-Reset": "1733209471",
"X-RateLimit-Used": "47",
"X-RateLimit-Resource": "core",
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
"Access-Control-Allow-Origin": "*",
Expand All @@ -39,10 +39,10 @@
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"Server": "github.com",
"X-GitHub-Request-Id": "AA94:CE235:B789E:DC5E1:6749AEC9"
"X-GitHub-Request-Id": "AB78:259AD1:61CD9C:72C698:674EAB3B"
}
},
"uuid": "235d9d84-9cd7-4be8-931c-15eada0775ef",
"uuid": "a4f46a34-8c81-44e9-bec4-043ba7bdcb10",
"persistent": true,
"insertionIndex": 1
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "a07f11cb-b8ae-4a6a-a486-3b0fae66f3e9",
"id": "ee74a0a7-35fd-4683-a471-587c81678ae3",
"name": "repos_alaurant_github-api-test",
"request": {
"url": "/repos/Alaurant/github-api-test",
Expand All @@ -14,7 +14,7 @@
"status": 200,
"bodyFileName": "2-r_a_github-api-test.json",
"headers": {
"Date": "Fri, 29 Nov 2024 12:08:42 GMT",
"Date": "Tue, 03 Dec 2024 06:54:52 GMT",
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With",
Expand All @@ -26,9 +26,9 @@
"X-GitHub-Media-Type": "github.v3; format=json",
"x-github-api-version-selected": "2022-11-28",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4871",
"X-RateLimit-Reset": "1732885041",
"X-RateLimit-Used": "129",
"X-RateLimit-Remaining": "4951",
"X-RateLimit-Reset": "1733209471",
"X-RateLimit-Used": "49",
"X-RateLimit-Resource": "core",
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
"Access-Control-Allow-Origin": "*",
Expand All @@ -39,10 +39,10 @@
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"Server": "github.com",
"X-GitHub-Request-Id": "AA95:BC38C:189764:1D15CD:6749AECA"
"X-GitHub-Request-Id": "ABD3:275BE1:5986ED:681867:674EAB3C"
}
},
"uuid": "a07f11cb-b8ae-4a6a-a486-3b0fae66f3e9",
"uuid": "ee74a0a7-35fd-4683-a471-587c81678ae3",
"persistent": true,
"insertionIndex": 2
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "4bf2d1c6-e598-4e44-b5b5-fd2def41755d",
"id": "e03166d6-8ef7-42ef-9fd9-3c37415b29d8",
"name": "repos_alaurant_github-api-test_autolinks",
"request": {
"url": "/repos/Alaurant/github-api-test/autolinks",
Expand All @@ -19,22 +19,22 @@
},
"response": {
"status": 201,
"body": "{\"id\":6152588,\"key_prefix\":\"EXAMPLE-\",\"url_template\":\"https://example.com/TICKET?q=<num>\",\"is_alphanumeric\":true}",
"body": "{\"id\":6208102,\"key_prefix\":\"EXAMPLE-\",\"url_template\":\"https://example.com/TICKET?q=<num>\",\"is_alphanumeric\":true}",
"headers": {
"Date": "Fri, 29 Nov 2024 12:08:42 GMT",
"Date": "Tue, 03 Dec 2024 06:54:53 GMT",
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With",
"ETag": "\"ec4fdc72dbf3168e39facb1e3952c440b2d78ed7b3e58f12404d3dd5b33ebf42\"",
"ETag": "\"a43aceb24d084ac36cc51df4652c6770f8d169d875ecf46247ac99b589e441fe\"",
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, admin:ssh_signing_key, audit_log, codespace, delete:packages, delete_repo, gist, project, read:packages, repo, user, workflow, write:discussion",
"X-Accepted-OAuth-Scopes": "repo",
"github-authentication-token-expiration": "2025-02-25 04:28:56 UTC",
"X-GitHub-Media-Type": "github.v3; format=json",
"x-github-api-version-selected": "2022-11-28",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4870",
"X-RateLimit-Reset": "1732885041",
"X-RateLimit-Used": "130",
"X-RateLimit-Remaining": "4950",
"X-RateLimit-Reset": "1733209471",
"X-RateLimit-Used": "50",
"X-RateLimit-Resource": "core",
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
"Access-Control-Allow-Origin": "*",
Expand All @@ -45,10 +45,10 @@
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"Server": "github.com",
"X-GitHub-Request-Id": "AA99:B1D42:2AFA65:31D40E:6749AECA"
"X-GitHub-Request-Id": "ABD4:25E009:63825C:747B1A:674EAB3D"
}
},
"uuid": "4bf2d1c6-e598-4e44-b5b5-fd2def41755d",
"uuid": "e03166d6-8ef7-42ef-9fd9-3c37415b29d8",
"persistent": true,
"insertionIndex": 3
}
Loading

0 comments on commit 2ad3c5b

Please sign in to comment.