diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index cdec753ffd..e854e618ec 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -41,6 +41,7 @@ import java.net.URL; import java.util.AbstractSet; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -3618,6 +3619,36 @@ public void unstar() throws IOException { root().createRequest().method("DELETE").withUrlPath(String.format("/user/starred/%s", full_name)).send(); } + /** + * Get the top 10 popular contents over the last 14 days as described on + * https://docs.github.com/en/rest/metrics/traffic?apiVersion=2022-11-28#get-top-referral-paths + * + * @return list of top referral paths + * @throws IOException + * the io exception + */ + public List getTopReferralPaths() throws IOException { + return Arrays.asList(root().createRequest() + .method("GET") + .withUrlPath(getApiTailUrl("/traffic/popular/paths")) + .fetch(GHRepositoryTrafficTopReferralPath[].class)); + } + + /** + * Get the top 10 referrers over the last 14 days as described on + * https://docs.github.com/en/rest/metrics/traffic?apiVersion=2022-11-28#get-top-referral-sources + * + * @return list of top referrers + * @throws IOException + * the io exception + */ + public List getTopReferralSources() throws IOException { + return Arrays.asList(root().createRequest() + .method("GET") + .withUrlPath(getApiTailUrl("/traffic/popular/referrers")) + .fetch(GHRepositoryTrafficTopReferralSources[].class)); + } + /** * A {@link GHRepositoryBuilder} that allows multiple properties to be updated per request. * diff --git a/src/main/java/org/kohsuke/github/GHRepositoryTrafficReferralBase.java b/src/main/java/org/kohsuke/github/GHRepositoryTrafficReferralBase.java new file mode 100644 index 0000000000..25361fd76e --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHRepositoryTrafficReferralBase.java @@ -0,0 +1,46 @@ +package org.kohsuke.github; + +/** + * Base class for traffic referral objects. + */ +public class GHRepositoryTrafficReferralBase { + private int count; + private int uniques; + + /** + * Instantiates a new Gh repository traffic referral base. + */ + GHRepositoryTrafficReferralBase() { + } + + /** + * Instantiates a new Gh repository traffic referral base. + * + * @param count + * the count + * @param uniques + * the uniques + */ + GHRepositoryTrafficReferralBase(int count, int uniques) { + this.count = count; + this.uniques = uniques; + } + + /** + * Gets count. + * + * @return the count + */ + public int getCount() { + return this.count; + } + + /** + * Gets uniques. + * + * @return the uniques + */ + public int getUniques() { + return this.uniques; + } +} diff --git a/src/main/java/org/kohsuke/github/GHRepositoryTrafficTopReferralPath.java b/src/main/java/org/kohsuke/github/GHRepositoryTrafficTopReferralPath.java new file mode 100644 index 0000000000..647a56ebde --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHRepositoryTrafficTopReferralPath.java @@ -0,0 +1,51 @@ +package org.kohsuke.github; + +/** + * Top referral path object. + */ +public class GHRepositoryTrafficTopReferralPath extends GHRepositoryTrafficReferralBase { + private String path; + private String title; + + /** + * Instantiates a new Gh repository traffic top referral path. + */ + GHRepositoryTrafficTopReferralPath() { + } + + /** + * Instantiates a new Gh repository traffic top referral path. + * + * @param count + * the count + * @param uniques + * the uniques + * @param path + * the path + * @param title + * the title + */ + GHRepositoryTrafficTopReferralPath(int count, int uniques, String path, String title) { + super(count, uniques); + this.path = path; + this.title = title; + } + + /** + * Gets path. + * + * @return the path + */ + public String getPath() { + return this.path; + } + + /** + * Gets title. + * + * @return the title + */ + public String getTitle() { + return this.title; + } +} diff --git a/src/main/java/org/kohsuke/github/GHRepositoryTrafficTopReferralSources.java b/src/main/java/org/kohsuke/github/GHRepositoryTrafficTopReferralSources.java new file mode 100644 index 0000000000..dd784cd25d --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHRepositoryTrafficTopReferralSources.java @@ -0,0 +1,38 @@ +package org.kohsuke.github; + +/** + * Top referral source object. + */ +public class GHRepositoryTrafficTopReferralSources extends GHRepositoryTrafficReferralBase { + private String referrer; + + /** + * Instantiates a new Gh repository traffic top referral sources. + */ + GHRepositoryTrafficTopReferralSources() { + } + + /** + * Instantiates a new Gh repository traffic top referral sources. + * + * @param count + * the count + * @param uniques + * the uniques + * @param referrer + * the referrer + */ + GHRepositoryTrafficTopReferralSources(int count, int uniques, String referrer) { + super(count, uniques); + this.referrer = referrer; + } + + /** + * Gets referrer. + * + * @return the referrer + */ + public String getReferrer() { + return this.referrer; + } +} diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index 30b0960346..5e1626bec8 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -1823,6 +1823,32 @@ public void testSearchPullRequests() throws Exception { this.verifySingleResult(searchResult, mergedPR); } + /** + * Test getTopReferralPaths. + * + * @throws Exception + * the exception + */ + @Test + public void testGetTopReferralPaths() throws Exception { + GHRepository repository = gitHub.getRepository("ihrigb/node-doorbird"); + List referralPaths = repository.getTopReferralPaths(); + assertThat(referralPaths.size(), greaterThan(0)); + } + + /** + * Test getTopReferralSources. + * + * @throws Exception + * the exception + */ + @Test + public void testGetTopReferralSources() throws Exception { + GHRepository repository = gitHub.getRepository("ihrigb/node-doorbird"); + List referralSources = repository.getTopReferralSources(); + assertThat(referralSources.size(), greaterThan(0)); + } + private void verifyEmptyResult(PagedSearchIterable searchResult) { assertThat(searchResult.getTotalCount(), is(0)); } diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTrafficReferralBaseTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTrafficReferralBaseTest.java new file mode 100644 index 0000000000..78cd6d2520 --- /dev/null +++ b/src/test/java/org/kohsuke/github/GHRepositoryTrafficReferralBaseTest.java @@ -0,0 +1,23 @@ +package org.kohsuke.github; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; + +/** + * Unit test for {@link GHRepositoryTrafficReferralBase}. + */ +public class GHRepositoryTrafficReferralBaseTest { + + /** + * Test the constructor. + */ + @Test + public void test() { + GHRepositoryTrafficReferralBase testee = new GHRepositoryTrafficReferralBase(1, 2); + assertThat(testee.getCount(), is(equalTo(1))); + assertThat(testee.getUniques(), is(equalTo(2))); + } +} diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTrafficTopReferralPathTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTrafficTopReferralPathTest.java new file mode 100644 index 0000000000..b1de0dff72 --- /dev/null +++ b/src/test/java/org/kohsuke/github/GHRepositoryTrafficTopReferralPathTest.java @@ -0,0 +1,25 @@ +package org.kohsuke.github; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; + +/** + * Unit tests for {@link GHRepositoryTrafficTopReferralPath}. + */ +public class GHRepositoryTrafficTopReferralPathTest { + + /** + * Test the constructor. + */ + @Test + public void test() { + GHRepositoryTrafficTopReferralPath testee = new GHRepositoryTrafficTopReferralPath(1, 2, "path", "title"); + assertThat(testee.getCount(), is(equalTo(1))); + assertThat(testee.getUniques(), is(equalTo(2))); + assertThat(testee.getPath(), is(equalTo("path"))); + assertThat(testee.getTitle(), is(equalTo("title"))); + } +} diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTrafficTopReferralSourcesTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTrafficTopReferralSourcesTest.java new file mode 100644 index 0000000000..9125f29080 --- /dev/null +++ b/src/test/java/org/kohsuke/github/GHRepositoryTrafficTopReferralSourcesTest.java @@ -0,0 +1,24 @@ +package org.kohsuke.github; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; + +/** + * Unit test for {@link GHRepositoryTrafficTopReferralSources}. + */ +public class GHRepositoryTrafficTopReferralSourcesTest { + + /** + * Test the constructor. + */ + @Test + public void test() { + GHRepositoryTrafficTopReferralSources testee = new GHRepositoryTrafficTopReferralSources(1, 2, "referrer"); + assertThat(testee.getCount(), is(equalTo(1))); + assertThat(testee.getUniques(), is(equalTo(2))); + assertThat(testee.getReferrer(), is(equalTo("referrer"))); + } +} diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/__files/1-user.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/__files/1-user.json new file mode 100644 index 0000000000..3f1e83ed32 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/__files/1-user.json @@ -0,0 +1,34 @@ +{ + "login": "ihrigb", + "id": 3423161, + "node_id": "MDQ6VXNlcjM0MjMxNjE=", + "avatar_url": "https://avatars.githubusercontent.com/u/3423161?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/ihrigb", + "html_url": "https://github.com/ihrigb", + "followers_url": "https://api.github.com/users/ihrigb/followers", + "following_url": "https://api.github.com/users/ihrigb/following{/other_user}", + "gists_url": "https://api.github.com/users/ihrigb/gists{/gist_id}", + "starred_url": "https://api.github.com/users/ihrigb/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/ihrigb/subscriptions", + "organizations_url": "https://api.github.com/users/ihrigb/orgs", + "repos_url": "https://api.github.com/users/ihrigb/repos", + "events_url": "https://api.github.com/users/ihrigb/events{/privacy}", + "received_events_url": "https://api.github.com/users/ihrigb/received_events", + "type": "User", + "site_admin": false, + "name": "Benjamin Ihrig", + "company": "SAP SE", + "blog": "", + "location": "Germany", + "email": null, + "hireable": null, + "bio": "Working at @SAP.\r\nDoing software projects for a volunteer fire brigade in free time. Smart home enthusiast. Scuba diving instructor.", + "twitter_username": null, + "public_repos": 26, + "public_gists": 1, + "followers": 5, + "following": 20, + "created_at": "2013-01-30T02:20:16Z", + "updated_at": "2024-02-23T21:51:51Z" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/__files/2-r_i_node-doorbird.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/__files/2-r_i_node-doorbird.json new file mode 100644 index 0000000000..2bc400fb02 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/__files/2-r_i_node-doorbird.json @@ -0,0 +1,135 @@ +{ + "id": 404133501, + "node_id": "MDEwOlJlcG9zaXRvcnk0MDQxMzM1MDE=", + "name": "node-doorbird", + "full_name": "ihrigb/node-doorbird", + "private": false, + "owner": { + "login": "ihrigb", + "id": 3423161, + "node_id": "MDQ6VXNlcjM0MjMxNjE=", + "avatar_url": "https://avatars.githubusercontent.com/u/3423161?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/ihrigb", + "html_url": "https://github.com/ihrigb", + "followers_url": "https://api.github.com/users/ihrigb/followers", + "following_url": "https://api.github.com/users/ihrigb/following{/other_user}", + "gists_url": "https://api.github.com/users/ihrigb/gists{/gist_id}", + "starred_url": "https://api.github.com/users/ihrigb/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/ihrigb/subscriptions", + "organizations_url": "https://api.github.com/users/ihrigb/orgs", + "repos_url": "https://api.github.com/users/ihrigb/repos", + "events_url": "https://api.github.com/users/ihrigb/events{/privacy}", + "received_events_url": "https://api.github.com/users/ihrigb/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/ihrigb/node-doorbird", + "description": "Node client library for Doorbird's HTTP API.", + "fork": false, + "url": "https://api.github.com/repos/ihrigb/node-doorbird", + "forks_url": "https://api.github.com/repos/ihrigb/node-doorbird/forks", + "keys_url": "https://api.github.com/repos/ihrigb/node-doorbird/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/ihrigb/node-doorbird/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/ihrigb/node-doorbird/teams", + "hooks_url": "https://api.github.com/repos/ihrigb/node-doorbird/hooks", + "issue_events_url": "https://api.github.com/repos/ihrigb/node-doorbird/issues/events{/number}", + "events_url": "https://api.github.com/repos/ihrigb/node-doorbird/events", + "assignees_url": "https://api.github.com/repos/ihrigb/node-doorbird/assignees{/user}", + "branches_url": "https://api.github.com/repos/ihrigb/node-doorbird/branches{/branch}", + "tags_url": "https://api.github.com/repos/ihrigb/node-doorbird/tags", + "blobs_url": "https://api.github.com/repos/ihrigb/node-doorbird/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/ihrigb/node-doorbird/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/ihrigb/node-doorbird/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/ihrigb/node-doorbird/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/ihrigb/node-doorbird/statuses/{sha}", + "languages_url": "https://api.github.com/repos/ihrigb/node-doorbird/languages", + "stargazers_url": "https://api.github.com/repos/ihrigb/node-doorbird/stargazers", + "contributors_url": "https://api.github.com/repos/ihrigb/node-doorbird/contributors", + "subscribers_url": "https://api.github.com/repos/ihrigb/node-doorbird/subscribers", + "subscription_url": "https://api.github.com/repos/ihrigb/node-doorbird/subscription", + "commits_url": "https://api.github.com/repos/ihrigb/node-doorbird/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/ihrigb/node-doorbird/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/ihrigb/node-doorbird/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/ihrigb/node-doorbird/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/ihrigb/node-doorbird/contents/{+path}", + "compare_url": "https://api.github.com/repos/ihrigb/node-doorbird/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/ihrigb/node-doorbird/merges", + "archive_url": "https://api.github.com/repos/ihrigb/node-doorbird/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/ihrigb/node-doorbird/downloads", + "issues_url": "https://api.github.com/repos/ihrigb/node-doorbird/issues{/number}", + "pulls_url": "https://api.github.com/repos/ihrigb/node-doorbird/pulls{/number}", + "milestones_url": "https://api.github.com/repos/ihrigb/node-doorbird/milestones{/number}", + "notifications_url": "https://api.github.com/repos/ihrigb/node-doorbird/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/ihrigb/node-doorbird/labels{/name}", + "releases_url": "https://api.github.com/repos/ihrigb/node-doorbird/releases{/id}", + "deployments_url": "https://api.github.com/repos/ihrigb/node-doorbird/deployments", + "created_at": "2021-09-07T21:58:15Z", + "updated_at": "2024-06-20T20:02:34Z", + "pushed_at": "2024-06-24T22:22:00Z", + "git_url": "git://github.com/ihrigb/node-doorbird.git", + "ssh_url": "git@github.com:ihrigb/node-doorbird.git", + "clone_url": "https://github.com/ihrigb/node-doorbird.git", + "svn_url": "https://github.com/ihrigb/node-doorbird", + "homepage": "", + "size": 1279, + "stargazers_count": 4, + "watchers_count": 4, + "language": "TypeScript", + "has_issues": true, + "has_projects": false, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "has_discussions": false, + "forks_count": 2, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 3, + "license": { + "key": "apache-2.0", + "name": "Apache License 2.0", + "spdx_id": "Apache-2.0", + "url": "https://api.github.com/licenses/apache-2.0", + "node_id": "MDc6TGljZW5zZTI=" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + "client-library", + "doorbell", + "doorbird", + "library", + "smarthome" + ], + "visibility": "public", + "forks": 2, + "open_issues": 3, + "watchers": 4, + "default_branch": "main", + "permissions": { + "admin": true, + "maintain": true, + "push": true, + "triage": true, + "pull": true + }, + "security_and_analysis": { + "secret_scanning": { + "status": "disabled" + }, + "secret_scanning_push_protection": { + "status": "disabled" + }, + "dependabot_security_updates": { + "status": "disabled" + }, + "secret_scanning_validity_checks": { + "status": "disabled" + } + }, + "network_count": 2, + "subscribers_count": 6 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/mappings/1-user.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/mappings/1-user.json new file mode 100644 index 0000000000..0d8f0be37d --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/mappings/1-user.json @@ -0,0 +1,48 @@ +{ + "id": "2ae410dc-5442-442b-b7d6-145106cdd630", + "name": "user", + "request": { + "url": "/user", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-user.json", + "headers": { + "Server": "istio-envoy", + "Date": "Mon, 01 Jul 2024 08:23:10 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": "W/\"18e79cac306e2b256847587d121593af4c51df3d8d367e392289c99bfbeb77f0\"", + "Last-Modified": "Fri, 23 Feb 2024 21:51:51 GMT", + "github-authentication-token-expiration": "2024-07-31 10:13:04 +0200", + "X-GitHub-Media-Type": "github.v3; format=json", + "x-accepted-github-permissions": "allows_permissionless_access=true", + "x-github-api-version-selected": "2022-11-28", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4026", + "X-RateLimit-Reset": "1719823001", + "X-RateLimit-Used": "974", + "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": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "x-envoy-upstream-service-time": "65", + "X-GitHub-Request-Id": "3D98:27C18F:32B92B7:3352E53:6682676E" + } + }, + "uuid": "2ae410dc-5442-442b-b7d6-145106cdd630", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/mappings/2-r_i_node-doorbird.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/mappings/2-r_i_node-doorbird.json new file mode 100644 index 0000000000..1c766aece9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/mappings/2-r_i_node-doorbird.json @@ -0,0 +1,49 @@ +{ + "id": "4022161d-3ae8-4b11-a389-9c14ab9f2d23", + "name": "repos_ihrigb_node-doorbird", + "request": { + "url": "/repos/ihrigb/node-doorbird", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-r_i_node-doorbird.json", + "headers": { + "Server": "istio-envoy", + "Date": "Mon, 01 Jul 2024 08:23:11 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": "W/\"55d3ba68210c42d7349064b62572ac3f5649ea91cda0e535dafffd6cdc8d366d\"", + "Last-Modified": "Thu, 20 Jun 2024 20:02:34 GMT", + "github-authentication-token-expiration": "2024-07-31 10:13:04 +0200", + "X-GitHub-Media-Type": "github.v3; format=json", + "x-accepted-github-permissions": "metadata=read", + "x-github-api-version-selected": "2022-11-28", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4024", + "X-RateLimit-Reset": "1719823001", + "X-RateLimit-Used": "976", + "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": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "x-envoy-upstream-service-time": "152", + "x-envoy-decorator-operation": "unicorn-api.github-production.svc.cluster.local:80/*", + "X-GitHub-Request-Id": "4EF8:23E496:33C7BC8:3461A9E:6682676E" + } + }, + "uuid": "4022161d-3ae8-4b11-a389-9c14ab9f2d23", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/mappings/3-r_i_n_traffic_popular_paths.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/mappings/3-r_i_n_traffic_popular_paths.json new file mode 100644 index 0000000000..cb9e009c0b --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralPaths/mappings/3-r_i_n_traffic_popular_paths.json @@ -0,0 +1,47 @@ +{ + "id": "e9539f90-d4be-4c80-a4bd-6a8364eb1c91", + "name": "repos_ihrigb_node-doorbird_traffic_popular_paths", + "request": { + "url": "/repos/ihrigb/node-doorbird/traffic/popular/paths", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "body": "[{\"path\":\"/ihrigb/node-doorbird\",\"title\":\"ihrigb/node-doorbird: Node client library for Doorbird's HTTP API.\",\"count\":7,\"uniques\":7}]", + "headers": { + "Server": "istio-envoy", + "Date": "Mon, 01 Jul 2024 08:23:11 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": "W/\"006eb2ae8e15394459f8f30538923500d1c69cae53950a43dac01801004e1cb6\"", + "github-authentication-token-expiration": "2024-07-31 10:13:04 +0200", + "X-GitHub-Media-Type": "github.v3; format=json", + "x-accepted-github-permissions": "administration=read", + "x-github-api-version-selected": "2022-11-28", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4023", + "X-RateLimit-Reset": "1719823001", + "X-RateLimit-Used": "977", + "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": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "x-envoy-upstream-service-time": "109", + "X-GitHub-Request-Id": "9D4E:1DD08D:3271725:3309DBF:6682676F" + } + }, + "uuid": "e9539f90-d4be-4c80-a4bd-6a8364eb1c91", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/__files/1-user.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/__files/1-user.json new file mode 100644 index 0000000000..3f1e83ed32 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/__files/1-user.json @@ -0,0 +1,34 @@ +{ + "login": "ihrigb", + "id": 3423161, + "node_id": "MDQ6VXNlcjM0MjMxNjE=", + "avatar_url": "https://avatars.githubusercontent.com/u/3423161?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/ihrigb", + "html_url": "https://github.com/ihrigb", + "followers_url": "https://api.github.com/users/ihrigb/followers", + "following_url": "https://api.github.com/users/ihrigb/following{/other_user}", + "gists_url": "https://api.github.com/users/ihrigb/gists{/gist_id}", + "starred_url": "https://api.github.com/users/ihrigb/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/ihrigb/subscriptions", + "organizations_url": "https://api.github.com/users/ihrigb/orgs", + "repos_url": "https://api.github.com/users/ihrigb/repos", + "events_url": "https://api.github.com/users/ihrigb/events{/privacy}", + "received_events_url": "https://api.github.com/users/ihrigb/received_events", + "type": "User", + "site_admin": false, + "name": "Benjamin Ihrig", + "company": "SAP SE", + "blog": "", + "location": "Germany", + "email": null, + "hireable": null, + "bio": "Working at @SAP.\r\nDoing software projects for a volunteer fire brigade in free time. Smart home enthusiast. Scuba diving instructor.", + "twitter_username": null, + "public_repos": 26, + "public_gists": 1, + "followers": 5, + "following": 20, + "created_at": "2013-01-30T02:20:16Z", + "updated_at": "2024-02-23T21:51:51Z" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/__files/2-r_i_node-doorbird.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/__files/2-r_i_node-doorbird.json new file mode 100644 index 0000000000..2bc400fb02 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/__files/2-r_i_node-doorbird.json @@ -0,0 +1,135 @@ +{ + "id": 404133501, + "node_id": "MDEwOlJlcG9zaXRvcnk0MDQxMzM1MDE=", + "name": "node-doorbird", + "full_name": "ihrigb/node-doorbird", + "private": false, + "owner": { + "login": "ihrigb", + "id": 3423161, + "node_id": "MDQ6VXNlcjM0MjMxNjE=", + "avatar_url": "https://avatars.githubusercontent.com/u/3423161?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/ihrigb", + "html_url": "https://github.com/ihrigb", + "followers_url": "https://api.github.com/users/ihrigb/followers", + "following_url": "https://api.github.com/users/ihrigb/following{/other_user}", + "gists_url": "https://api.github.com/users/ihrigb/gists{/gist_id}", + "starred_url": "https://api.github.com/users/ihrigb/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/ihrigb/subscriptions", + "organizations_url": "https://api.github.com/users/ihrigb/orgs", + "repos_url": "https://api.github.com/users/ihrigb/repos", + "events_url": "https://api.github.com/users/ihrigb/events{/privacy}", + "received_events_url": "https://api.github.com/users/ihrigb/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/ihrigb/node-doorbird", + "description": "Node client library for Doorbird's HTTP API.", + "fork": false, + "url": "https://api.github.com/repos/ihrigb/node-doorbird", + "forks_url": "https://api.github.com/repos/ihrigb/node-doorbird/forks", + "keys_url": "https://api.github.com/repos/ihrigb/node-doorbird/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/ihrigb/node-doorbird/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/ihrigb/node-doorbird/teams", + "hooks_url": "https://api.github.com/repos/ihrigb/node-doorbird/hooks", + "issue_events_url": "https://api.github.com/repos/ihrigb/node-doorbird/issues/events{/number}", + "events_url": "https://api.github.com/repos/ihrigb/node-doorbird/events", + "assignees_url": "https://api.github.com/repos/ihrigb/node-doorbird/assignees{/user}", + "branches_url": "https://api.github.com/repos/ihrigb/node-doorbird/branches{/branch}", + "tags_url": "https://api.github.com/repos/ihrigb/node-doorbird/tags", + "blobs_url": "https://api.github.com/repos/ihrigb/node-doorbird/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/ihrigb/node-doorbird/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/ihrigb/node-doorbird/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/ihrigb/node-doorbird/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/ihrigb/node-doorbird/statuses/{sha}", + "languages_url": "https://api.github.com/repos/ihrigb/node-doorbird/languages", + "stargazers_url": "https://api.github.com/repos/ihrigb/node-doorbird/stargazers", + "contributors_url": "https://api.github.com/repos/ihrigb/node-doorbird/contributors", + "subscribers_url": "https://api.github.com/repos/ihrigb/node-doorbird/subscribers", + "subscription_url": "https://api.github.com/repos/ihrigb/node-doorbird/subscription", + "commits_url": "https://api.github.com/repos/ihrigb/node-doorbird/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/ihrigb/node-doorbird/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/ihrigb/node-doorbird/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/ihrigb/node-doorbird/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/ihrigb/node-doorbird/contents/{+path}", + "compare_url": "https://api.github.com/repos/ihrigb/node-doorbird/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/ihrigb/node-doorbird/merges", + "archive_url": "https://api.github.com/repos/ihrigb/node-doorbird/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/ihrigb/node-doorbird/downloads", + "issues_url": "https://api.github.com/repos/ihrigb/node-doorbird/issues{/number}", + "pulls_url": "https://api.github.com/repos/ihrigb/node-doorbird/pulls{/number}", + "milestones_url": "https://api.github.com/repos/ihrigb/node-doorbird/milestones{/number}", + "notifications_url": "https://api.github.com/repos/ihrigb/node-doorbird/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/ihrigb/node-doorbird/labels{/name}", + "releases_url": "https://api.github.com/repos/ihrigb/node-doorbird/releases{/id}", + "deployments_url": "https://api.github.com/repos/ihrigb/node-doorbird/deployments", + "created_at": "2021-09-07T21:58:15Z", + "updated_at": "2024-06-20T20:02:34Z", + "pushed_at": "2024-06-24T22:22:00Z", + "git_url": "git://github.com/ihrigb/node-doorbird.git", + "ssh_url": "git@github.com:ihrigb/node-doorbird.git", + "clone_url": "https://github.com/ihrigb/node-doorbird.git", + "svn_url": "https://github.com/ihrigb/node-doorbird", + "homepage": "", + "size": 1279, + "stargazers_count": 4, + "watchers_count": 4, + "language": "TypeScript", + "has_issues": true, + "has_projects": false, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "has_discussions": false, + "forks_count": 2, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 3, + "license": { + "key": "apache-2.0", + "name": "Apache License 2.0", + "spdx_id": "Apache-2.0", + "url": "https://api.github.com/licenses/apache-2.0", + "node_id": "MDc6TGljZW5zZTI=" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + "client-library", + "doorbell", + "doorbird", + "library", + "smarthome" + ], + "visibility": "public", + "forks": 2, + "open_issues": 3, + "watchers": 4, + "default_branch": "main", + "permissions": { + "admin": true, + "maintain": true, + "push": true, + "triage": true, + "pull": true + }, + "security_and_analysis": { + "secret_scanning": { + "status": "disabled" + }, + "secret_scanning_push_protection": { + "status": "disabled" + }, + "dependabot_security_updates": { + "status": "disabled" + }, + "secret_scanning_validity_checks": { + "status": "disabled" + } + }, + "network_count": 2, + "subscribers_count": 6 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/mappings/1-user.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/mappings/1-user.json new file mode 100644 index 0000000000..ed4d3e3ac2 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/mappings/1-user.json @@ -0,0 +1,48 @@ +{ + "id": "8108f0e0-5de3-4794-8f85-b9940ebbbce7", + "name": "user", + "request": { + "url": "/user", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-user.json", + "headers": { + "Server": "istio-envoy", + "Date": "Mon, 01 Jul 2024 08:22:45 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": "W/\"18e79cac306e2b256847587d121593af4c51df3d8d367e392289c99bfbeb77f0\"", + "Last-Modified": "Fri, 23 Feb 2024 21:51:51 GMT", + "github-authentication-token-expiration": "2024-07-31 10:13:04 +0200", + "X-GitHub-Media-Type": "github.v3; format=json", + "x-accepted-github-permissions": "allows_permissionless_access=true", + "x-github-api-version-selected": "2022-11-28", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4132", + "X-RateLimit-Reset": "1719823001", + "X-RateLimit-Used": "868", + "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": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "x-envoy-upstream-service-time": "71", + "X-GitHub-Request-Id": "4E8A:279108:27D16D3:2855622:66826755" + } + }, + "uuid": "8108f0e0-5de3-4794-8f85-b9940ebbbce7", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/mappings/2-r_i_node-doorbird.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/mappings/2-r_i_node-doorbird.json new file mode 100644 index 0000000000..6f15857291 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/mappings/2-r_i_node-doorbird.json @@ -0,0 +1,48 @@ +{ + "id": "0b16951e-7447-44a8-95d5-a86a6a37b600", + "name": "repos_ihrigb_node-doorbird", + "request": { + "url": "/repos/ihrigb/node-doorbird", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-r_i_node-doorbird.json", + "headers": { + "Server": "istio-envoy", + "Date": "Mon, 01 Jul 2024 08:22:45 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": "W/\"55d3ba68210c42d7349064b62572ac3f5649ea91cda0e535dafffd6cdc8d366d\"", + "Last-Modified": "Thu, 20 Jun 2024 20:02:34 GMT", + "github-authentication-token-expiration": "2024-07-31 10:13:04 +0200", + "X-GitHub-Media-Type": "github.v3; format=json", + "x-accepted-github-permissions": "metadata=read", + "x-github-api-version-selected": "2022-11-28", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4130", + "X-RateLimit-Reset": "1719823001", + "X-RateLimit-Used": "870", + "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": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "x-envoy-upstream-service-time": "125", + "X-GitHub-Request-Id": "BB97:1A6A5B:337D621:3417090:66826755" + } + }, + "uuid": "0b16951e-7447-44a8-95d5-a86a6a37b600", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/mappings/3-r_i_n_traffic_popular_referrers.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/mappings/3-r_i_n_traffic_popular_referrers.json new file mode 100644 index 0000000000..b6f44ffee9 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/testGetTopReferralSources/mappings/3-r_i_n_traffic_popular_referrers.json @@ -0,0 +1,47 @@ +{ + "id": "700d7c9d-6bfe-4f28-bcdc-2a3c0e8e00f7", + "name": "repos_ihrigb_node-doorbird_traffic_popular_referrers", + "request": { + "url": "/repos/ihrigb/node-doorbird/traffic/popular/referrers", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "body": "[{\"referrer\":\"Google\",\"count\":5,\"uniques\":5},{\"referrer\":\"github.com\",\"count\":1,\"uniques\":1}]", + "headers": { + "Server": "istio-envoy", + "Date": "Mon, 01 Jul 2024 08:22:46 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": "W/\"6095454e0e2facdf82dbc587d67b5647c571803ca74057741dceb0e7737791fe\"", + "github-authentication-token-expiration": "2024-07-31 10:13:04 +0200", + "X-GitHub-Media-Type": "github.v3; format=json", + "x-accepted-github-permissions": "administration=read", + "x-github-api-version-selected": "2022-11-28", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4129", + "X-RateLimit-Reset": "1719823001", + "X-RateLimit-Used": "871", + "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": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "x-envoy-upstream-service-time": "114", + "X-GitHub-Request-Id": "5F33:DCC42:2FC56E3:305E165:66826756" + } + }, + "uuid": "700d7c9d-6bfe-4f28-bcdc-2a3c0e8e00f7", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file