From c40f6b991d7387c35168079974c69f6355860dde Mon Sep 17 00:00:00 2001 From: Valentin Delaye Date: Wed, 17 Jul 2024 07:52:00 +0200 Subject: [PATCH 1/5] Add fork branch sync --- .../java/org/kohsuke/github/GHRepository.java | 21 ++ .../org/kohsuke/github/GHRepositoryTest.java | 12 + .../wiremock/sync/__files/1-user.json | 33 ++ .../sync/__files/2-orgs_hub4j-test-org.json | 42 +++ .../sync/__files/3-r_h_github-api.json | 330 ++++++++++++++++++ .../sync/__files/4-r_h_github-api.json | 17 + .../wiremock/sync/mappings/1-user.json | 48 +++ .../sync/mappings/2-orgs_hub4j-test-org.json | 48 +++ .../sync/mappings/3-r_h_github-api.json | 51 +++ .../sync/mappings/4-r_h_github-api.json | 54 +++ 10 files changed, 656 insertions(+) create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/1-user.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/2-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/3-r_h_github-api.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/4-r_h_github-api.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/1-user.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/2-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/3-r_h_github-api.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/4-r_h_github-api.json diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index e854e618ec..ced59a6f5a 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -1614,6 +1614,27 @@ public GHRepository fork() throws IOException { throw new IOException(this + " was forked but can't find the new repository"); } + /** + * Sync this repository fork branch + * + * @param branch + * the branch to sync + * @return The current repository + * @throws IOException + * the io exception + */ + public GHRepository sync(String branch) throws IOException { + if (isFork()) { + root().createRequest() + .method("POST") + .with("branch", branch) + .withUrlPath(getApiTailUrl("merge-upstream")) + .send(); + + } + return this; + } + /** * Forks this repository into an organization. * diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index 5e1626bec8..b01bf2f262 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -47,6 +47,18 @@ private GHRepository getRepository(GitHub gitHub) throws IOException { return gitHub.getOrganization("hub4j-test-org").getRepository("github-api"); } + /** + * Test sync of fork + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test + public void sync() throws IOException { + GHRepository r = getRepository(); + r.sync("main"); + } + /** * Test zipball. * diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/1-user.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/1-user.json new file mode 100644 index 0000000000..eab16ea068 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/1-user.json @@ -0,0 +1,33 @@ +{ + "login": "bitwiseman", + "id": 1958953, + "node_id": "MDQ6VXNlcjE5NTg5NTM=", + "avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bitwiseman", + "html_url": "https://github.com/bitwiseman", + "followers_url": "https://api.github.com/users/bitwiseman/followers", + "following_url": "https://api.github.com/users/bitwiseman/following{/other_user}", + "gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions", + "organizations_url": "https://api.github.com/users/bitwiseman/orgs", + "repos_url": "https://api.github.com/users/bitwiseman/repos", + "events_url": "https://api.github.com/users/bitwiseman/events{/privacy}", + "received_events_url": "https://api.github.com/users/bitwiseman/received_events", + "type": "User", + "site_admin": false, + "name": "Liam Newman", + "company": "Cloudbees, Inc.", + "blog": "", + "location": "Seattle, WA, USA", + "email": "bitwiseman@gmail.com", + "hireable": null, + "bio": "https://twitter.com/bitwiseman", + "public_repos": 166, + "public_gists": 4, + "followers": 135, + "following": 9, + "created_at": "2012-07-11T20:38:33Z", + "updated_at": "2019-09-24T19:32:29Z" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/2-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/2-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..f176fc4ff5 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/2-orgs_hub4j-test-org.json @@ -0,0 +1,42 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 9, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 132, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "members_allowed_repository_creation_type": "none", + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 3, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/3-r_h_github-api.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/3-r_h_github-api.json new file mode 100644 index 0000000000..d2a3a7aa94 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/3-r_h_github-api.json @@ -0,0 +1,330 @@ +{ + "id": 206888201, + "node_id": "MDEwOlJlcG9zaXRvcnkyMDY4ODgyMDE=", + "name": "github-api", + "full_name": "hub4j-test-org/github-api", + "private": false, + "owner": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.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/github-api", + "description": "Tricky", + "fork": true, + "url": "https://api.github.com/repos/hub4j-test-org/github-api", + "forks_url": "https://api.github.com/repos/hub4j-test-org/github-api/forks", + "keys_url": "https://api.github.com/repos/hub4j-test-org/github-api/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/hub4j-test-org/github-api/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/hub4j-test-org/github-api/teams", + "hooks_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks", + "issue_events_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues/events{/number}", + "events_url": "https://api.github.com/repos/hub4j-test-org/github-api/events", + "assignees_url": "https://api.github.com/repos/hub4j-test-org/github-api/assignees{/user}", + "branches_url": "https://api.github.com/repos/hub4j-test-org/github-api/branches{/branch}", + "tags_url": "https://api.github.com/repos/hub4j-test-org/github-api/tags", + "blobs_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api/statuses/{sha}", + "languages_url": "https://api.github.com/repos/hub4j-test-org/github-api/languages", + "stargazers_url": "https://api.github.com/repos/hub4j-test-org/github-api/stargazers", + "contributors_url": "https://api.github.com/repos/hub4j-test-org/github-api/contributors", + "subscribers_url": "https://api.github.com/repos/hub4j-test-org/github-api/subscribers", + "subscription_url": "https://api.github.com/repos/hub4j-test-org/github-api/subscription", + "commits_url": "https://api.github.com/repos/hub4j-test-org/github-api/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/hub4j-test-org/github-api/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/hub4j-test-org/github-api/contents/{+path}", + "compare_url": "https://api.github.com/repos/hub4j-test-org/github-api/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/hub4j-test-org/github-api/merges", + "archive_url": "https://api.github.com/repos/hub4j-test-org/github-api/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/hub4j-test-org/github-api/downloads", + "issues_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues{/number}", + "pulls_url": "https://api.github.com/repos/hub4j-test-org/github-api/pulls{/number}", + "milestones_url": "https://api.github.com/repos/hub4j-test-org/github-api/milestones{/number}", + "notifications_url": "https://api.github.com/repos/hub4j-test-org/github-api/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/hub4j-test-org/github-api/labels{/name}", + "releases_url": "https://api.github.com/repos/hub4j-test-org/github-api/releases{/id}", + "deployments_url": "https://api.github.com/repos/hub4j-test-org/github-api/deployments", + "created_at": "2019-09-06T23:26:04Z", + "updated_at": "2019-09-25T23:32:35Z", + "pushed_at": "2019-09-21T14:29:14Z", + "git_url": "git://github.com/hub4j-test-org/github-api.git", + "ssh_url": "git@github.com:hub4j-test-org/github-api.git", + "clone_url": "https://github.com/hub4j-test-org/github-api.git", + "svn_url": "https://github.com/hub4j-test-org/github-api", + "homepage": "http://github-api.kohsuke.org/", + "size": 11387, + "stargazers_count": 0, + "watchers_count": 0, + "language": "Java", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "main", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "allow_squash_merge": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "organization": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.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 + }, + "parent": { + "id": 617210, + "node_id": "MDEwOlJlcG9zaXRvcnk2MTcyMTA=", + "name": "github-api", + "full_name": "hub4j/github-api", + "private": false, + "owner": { + "login": "hub4j", + "id": 54909825, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1", + "avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/hub4j", + "html_url": "https://github.com/hub4j", + "followers_url": "https://api.github.com/users/hub4j/followers", + "following_url": "https://api.github.com/users/hub4j/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j/orgs", + "repos_url": "https://api.github.com/users/hub4j/repos", + "events_url": "https://api.github.com/users/hub4j/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/hub4j/github-api", + "description": "Java API for GitHub", + "fork": true, + "url": "https://api.github.com/repos/hub4j/github-api", + "forks_url": "https://api.github.com/repos/hub4j/github-api/forks", + "keys_url": "https://api.github.com/repos/hub4j/github-api/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/hub4j/github-api/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/hub4j/github-api/teams", + "hooks_url": "https://api.github.com/repos/hub4j/github-api/hooks", + "issue_events_url": "https://api.github.com/repos/hub4j/github-api/issues/events{/number}", + "events_url": "https://api.github.com/repos/hub4j/github-api/events", + "assignees_url": "https://api.github.com/repos/hub4j/github-api/assignees{/user}", + "branches_url": "https://api.github.com/repos/hub4j/github-api/branches{/branch}", + "tags_url": "https://api.github.com/repos/hub4j/github-api/tags", + "blobs_url": "https://api.github.com/repos/hub4j/github-api/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/hub4j/github-api/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/hub4j/github-api/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/hub4j/github-api/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/hub4j/github-api/statuses/{sha}", + "languages_url": "https://api.github.com/repos/hub4j/github-api/languages", + "stargazers_url": "https://api.github.com/repos/hub4j/github-api/stargazers", + "contributors_url": "https://api.github.com/repos/hub4j/github-api/contributors", + "subscribers_url": "https://api.github.com/repos/hub4j/github-api/subscribers", + "subscription_url": "https://api.github.com/repos/hub4j/github-api/subscription", + "commits_url": "https://api.github.com/repos/hub4j/github-api/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/hub4j/github-api/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/hub4j/github-api/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/hub4j/github-api/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/hub4j/github-api/contents/{+path}", + "compare_url": "https://api.github.com/repos/hub4j/github-api/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/hub4j/github-api/merges", + "archive_url": "https://api.github.com/repos/hub4j/github-api/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/hub4j/github-api/downloads", + "issues_url": "https://api.github.com/repos/hub4j/github-api/issues{/number}", + "pulls_url": "https://api.github.com/repos/hub4j/github-api/pulls{/number}", + "milestones_url": "https://api.github.com/repos/hub4j/github-api/milestones{/number}", + "notifications_url": "https://api.github.com/repos/hub4j/github-api/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/hub4j/github-api/labels{/name}", + "releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}", + "deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments", + "created_at": "2010-04-19T04:13:03Z", + "updated_at": "2019-09-25T22:47:32Z", + "pushed_at": "2019-09-25T22:56:18Z", + "git_url": "git://github.com/hub4j/github-api.git", + "ssh_url": "git@github.com:hub4j/github-api.git", + "clone_url": "https://github.com/hub4j/github-api.git", + "svn_url": "https://github.com/hub4j/github-api", + "homepage": "http://github-api.kohsuke.org/", + "size": 11678, + "stargazers_count": 553, + "watchers_count": 553, + "language": "Java", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 427, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 96, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 427, + "open_issues": 96, + "watchers": 553, + "default_branch": "main" + }, + "source": { + "id": 617210, + "node_id": "MDEwOlJlcG9zaXRvcnk2MTcyMTA=", + "name": "github-api", + "full_name": "hub4j/github-api", + "private": false, + "owner": { + "login": "hub4j", + "id": 54909825, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1", + "avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/hub4j", + "html_url": "https://github.com/hub4j", + "followers_url": "https://api.github.com/users/hub4j/followers", + "following_url": "https://api.github.com/users/hub4j/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j/orgs", + "repos_url": "https://api.github.com/users/hub4j/repos", + "events_url": "https://api.github.com/users/hub4j/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/hub4j/github-api", + "description": "Java API for GitHub", + "fork": false, + "url": "https://api.github.com/repos/hub4j/github-api", + "forks_url": "https://api.github.com/repos/hub4j/github-api/forks", + "keys_url": "https://api.github.com/repos/hub4j/github-api/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/hub4j/github-api/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/hub4j/github-api/teams", + "hooks_url": "https://api.github.com/repos/hub4j/github-api/hooks", + "issue_events_url": "https://api.github.com/repos/hub4j/github-api/issues/events{/number}", + "events_url": "https://api.github.com/repos/hub4j/github-api/events", + "assignees_url": "https://api.github.com/repos/hub4j/github-api/assignees{/user}", + "branches_url": "https://api.github.com/repos/hub4j/github-api/branches{/branch}", + "tags_url": "https://api.github.com/repos/hub4j/github-api/tags", + "blobs_url": "https://api.github.com/repos/hub4j/github-api/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/hub4j/github-api/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/hub4j/github-api/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/hub4j/github-api/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/hub4j/github-api/statuses/{sha}", + "languages_url": "https://api.github.com/repos/hub4j/github-api/languages", + "stargazers_url": "https://api.github.com/repos/hub4j/github-api/stargazers", + "contributors_url": "https://api.github.com/repos/hub4j/github-api/contributors", + "subscribers_url": "https://api.github.com/repos/hub4j/github-api/subscribers", + "subscription_url": "https://api.github.com/repos/hub4j/github-api/subscription", + "commits_url": "https://api.github.com/repos/hub4j/github-api/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/hub4j/github-api/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/hub4j/github-api/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/hub4j/github-api/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/hub4j/github-api/contents/{+path}", + "compare_url": "https://api.github.com/repos/hub4j/github-api/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/hub4j/github-api/merges", + "archive_url": "https://api.github.com/repos/hub4j/github-api/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/hub4j/github-api/downloads", + "issues_url": "https://api.github.com/repos/hub4j/github-api/issues{/number}", + "pulls_url": "https://api.github.com/repos/hub4j/github-api/pulls{/number}", + "milestones_url": "https://api.github.com/repos/hub4j/github-api/milestones{/number}", + "notifications_url": "https://api.github.com/repos/hub4j/github-api/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/hub4j/github-api/labels{/name}", + "releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}", + "deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments", + "created_at": "2010-04-19T04:13:03Z", + "updated_at": "2019-09-25T22:47:32Z", + "pushed_at": "2019-09-25T22:56:18Z", + "git_url": "git://github.com/hub4j/github-api.git", + "ssh_url": "git@github.com:hub4j/github-api.git", + "clone_url": "https://github.com/hub4j/github-api.git", + "svn_url": "https://github.com/hub4j/github-api", + "homepage": "http://github-api.kohsuke.org/", + "size": 11678, + "stargazers_count": 553, + "watchers_count": 553, + "language": "Java", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 427, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 96, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 427, + "open_issues": 96, + "watchers": 553, + "default_branch": "main" + }, + "network_count": 427, + "subscribers_count": 0 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/4-r_h_github-api.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/4-r_h_github-api.json new file mode 100644 index 0000000000..fd74e56e5d --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/4-r_h_github-api.json @@ -0,0 +1,17 @@ +[ + { + "name": "main", + "commit": { + "sha": "c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc", + "url": "https://api.github.com/repos/hub4j-test-org/github-api/commits/c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc" + }, + "protected": true, + "protection": { + "required_status_checks": { + "enforcement_level": "non_admins", + "contexts": [], + } + }, + "protection_url": "https://api.github.com/repos/hub4j-test-org/github-api/branches/main/protection" + } +] \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/1-user.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/1-user.json new file mode 100644 index 0000000000..a7e5c0c21c --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/1-user.json @@ -0,0 +1,48 @@ +{ + "id": "7f6e9a01-5bfa-4f72-9947-07df902f56c3", + "name": "user", + "request": { + "url": "/user", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-user.json", + "headers": { + "Date": "Wed, 25 Sep 2019 23:35:33 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4992", + "X-RateLimit-Reset": "1569457884", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"14ffd29009ddc2209c450bb29a5a8330\"", + "Last-Modified": "Tue, 24 Sep 2019 19:32:29 GMT", + "X-OAuth-Scopes": "gist, notifications, read:org, read:public_key, read:repo_hook, repo", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F845:5D1D:FFA88A:12FE539:5D8BF9C5" + } + }, + "uuid": "7f6e9a01-5bfa-4f72-9947-07df902f56c3", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/2-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/2-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..64182cc8c5 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/2-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "cb173af2-c793-444a-acdf-c3850e7afdbe", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-orgs_hub4j-test-org.json", + "headers": { + "Date": "Wed, 25 Sep 2019 23:35:58 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4989", + "X-RateLimit-Reset": "1569457884", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"b7989d48e6539c9c76038995b902421b\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "gist, notifications, read:org, read:public_key, read:repo_hook, repo", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F855:59E1:1397ED7:171400E:5D8BF9DE" + } + }, + "uuid": "cb173af2-c793-444a-acdf-c3850e7afdbe", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/3-r_h_github-api.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/3-r_h_github-api.json new file mode 100644 index 0000000000..265e1fd4bb --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/3-r_h_github-api.json @@ -0,0 +1,51 @@ +{ + "id": "0a4d7a1a-f99c-47ca-840a-3e920c18bd1f", + "name": "repos_hub4j-test-org_github-api", + "request": { + "url": "/repos/hub4j-test-org/github-api", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "3-r_h_github-api.json", + "headers": { + "Date": "Wed, 25 Sep 2019 23:35:58 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4988", + "X-RateLimit-Reset": "1569457884", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"0678d1c39ea574f68cc0fb330b067cb7\"", + "Last-Modified": "Wed, 25 Sep 2019 23:32:35 GMT", + "X-OAuth-Scopes": "gist, notifications, read:org, read:public_key, read:repo_hook, repo", + "X-Accepted-OAuth-Scopes": "repo", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F855:59E1:1397EEB:1714029:5D8BF9DE" + } + }, + "uuid": "0a4d7a1a-f99c-47ca-840a-3e920c18bd1f", + "persistent": true, + "scenarioName": "scenario-1-repos-hub4j-test-org-github-api", + "requiredScenarioState": "Started", + "newScenarioState": "scenario-1-repos-hub4j-test-org-github-api-2", + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/4-r_h_github-api.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/4-r_h_github-api.json new file mode 100644 index 0000000000..d3f36a5627 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/mappings/4-r_h_github-api.json @@ -0,0 +1,54 @@ +{ + "id": "2c69d5c8-dd81-4204-bad9-ee37f5b0ebfd", + "name": "repos_hub4j-test-org_github-api", + "request": { + "url": "/repos/hub4j-test-org/github-api/merge-upstream", + "method": "POST", + "bodyPatterns": [ + { + "equalToJson": "{\"branch\":\"main\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": false + } + ], + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "4-r_h_github-api.json", + "headers": { + "Date": "Wed, 25 Sep 2019 23:35:59 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4987", + "X-RateLimit-Reset": "1569457884", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"e40487cafd3670c0de171f4250dbefb8\"", + "X-OAuth-Scopes": "gist, notifications, read:org, read:public_key, read:repo_hook, repo", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F855:59E1:1397F0E:1714041:5D8BF9DE" + } + }, + "uuid": "2c69d5c8-dd81-4204-bad9-ee37f5b0ebfd", + "persistent": true, + "insertionIndex": 4 +} \ No newline at end of file From 5083df701414897ed171202aba5ea262a589d5e3 Mon Sep 17 00:00:00 2001 From: Valentin Delaye Date: Mon, 22 Jul 2024 06:28:00 +0200 Subject: [PATCH 2/5] Remove check for fork sync and let the API rethrow exception --- src/main/java/org/kohsuke/github/GHRepository.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index ced59a6f5a..cb32a4add7 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -1624,14 +1624,11 @@ public GHRepository fork() throws IOException { * the io exception */ public GHRepository sync(String branch) throws IOException { - if (isFork()) { - root().createRequest() - .method("POST") - .with("branch", branch) - .withUrlPath(getApiTailUrl("merge-upstream")) - .send(); - - } + root().createRequest() + .method("POST") + .with("branch", branch) + .withUrlPath(getApiTailUrl("merge-upstream")) + .send(); return this; } From 189125c19db19cc8e6e10e04b000ca5a026e126d Mon Sep 17 00:00:00 2001 From: Valentin Delaye Date: Wed, 24 Jul 2024 12:14:53 +0200 Subject: [PATCH 3/5] Add GHBranchSync model --- .../java/org/kohsuke/github/GHBranchSync.java | 58 +++ .../java/org/kohsuke/github/GHRepository.java | 8 +- .../org/kohsuke/github/GHRepositoryTest.java | 20 +- .../sync/__files/4-r_h_github-api.json | 22 +- .../wiremock/syncNoFork/__files/1-user.json | 33 ++ .../__files/2-orgs_hub4j-test-org.json | 42 +++ .../syncNoFork/__files/3-r_h_github-api.json | 330 ++++++++++++++++++ .../syncNoFork/__files/4-r_h_github-api.json | 5 + .../wiremock/syncNoFork/mappings/1-user.json | 48 +++ .../mappings/2-orgs_hub4j-test-org.json | 48 +++ .../syncNoFork/mappings/3-r_h_github-api.json | 51 +++ .../syncNoFork/mappings/4-r_h_github-api.json | 54 +++ 12 files changed, 697 insertions(+), 22 deletions(-) create mode 100644 src/main/java/org/kohsuke/github/GHBranchSync.java create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/1-user.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/2-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/3-r_h_github-api.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/4-r_h_github-api.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/1-user.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/2-orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/3-r_h_github-api.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/4-r_h_github-api.json diff --git a/src/main/java/org/kohsuke/github/GHBranchSync.java b/src/main/java/org/kohsuke/github/GHBranchSync.java new file mode 100644 index 0000000000..2acd48a0ca --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHBranchSync.java @@ -0,0 +1,58 @@ +package org.kohsuke.github; + +import com.fasterxml.jackson.annotation.JsonProperty; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +public class GHBranchSync extends GitHubInteractiveObject { + + private GHRepository owner; + + private String message; + + @JsonProperty("merge_type") + private String mergeType; + + @JsonProperty("base_branch") + private String baseBranch; + + /** + * Gets owner. + * + * @return the repository that this branch is in. + */ + @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") + public GHRepository getOwner() { + return owner; + } + + public String getMessage() { + return message; + } + + public String getMergeType() { + return mergeType; + } + + public String getBaseBranch() { + return baseBranch; + } + + @Override + public String toString() { + return "GHBranchSync{" + "message='" + message + '\'' + ", mergeType='" + mergeType + '\'' + ", baseBranch='" + + baseBranch + '\'' + '}'; + } + + /** + * Wrap. + * + * @param repo + * the repo + * @return the GH branch sync + */ + GHBranchSync wrap(GHRepository repo) { + this.owner = repo; + return this; + } + +} diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index cb32a4add7..bab9cafb10 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -1623,13 +1623,13 @@ public GHRepository fork() throws IOException { * @throws IOException * the io exception */ - public GHRepository sync(String branch) throws IOException { - root().createRequest() + public GHBranchSync sync(String branch) throws IOException { + return root().createRequest() .method("POST") .with("branch", branch) .withUrlPath(getApiTailUrl("merge-upstream")) - .send(); - return this; + .fetch(GHBranchSync.class) + .wrap(this); } /** diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index b01bf2f262..daf55d226d 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -56,7 +56,25 @@ private GHRepository getRepository(GitHub gitHub) throws IOException { @Test public void sync() throws IOException { GHRepository r = getRepository(); - r.sync("main"); + GHBranchSync sync = r.sync("main"); + assertThat(sync.getOwner().getFullName(), equalTo("hub4j-test-org/github-api")); + assertThat(sync.getMessage(), equalTo("Successfully fetched and fast-forwarded from upstream github-api:main")); + assertThat(sync.getMergeType(), equalTo("fast-forward")); + assertThat(sync.getBaseBranch(), equalTo("github-api:main")); + } + + /** + * Test sync of repository not a fork + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + @Test(expected = HttpException.class) + public void syncNoFork() throws IOException { + GHRepository r = getRepository(); + GHBranchSync sync = r.sync("main"); + fail("Should have thrown an exception"); + } /** diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/4-r_h_github-api.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/4-r_h_github-api.json index fd74e56e5d..59ae8286f3 100644 --- a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/4-r_h_github-api.json +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/sync/__files/4-r_h_github-api.json @@ -1,17 +1,5 @@ -[ - { - "name": "main", - "commit": { - "sha": "c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc", - "url": "https://api.github.com/repos/hub4j-test-org/github-api/commits/c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc" - }, - "protected": true, - "protection": { - "required_status_checks": { - "enforcement_level": "non_admins", - "contexts": [], - } - }, - "protection_url": "https://api.github.com/repos/hub4j-test-org/github-api/branches/main/protection" - } -] \ No newline at end of file +{ + "message": "Successfully fetched and fast-forwarded from upstream github-api:main", + "merge_type": "fast-forward", + "base_branch": "github-api:main" +} diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/1-user.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/1-user.json new file mode 100644 index 0000000000..eab16ea068 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/1-user.json @@ -0,0 +1,33 @@ +{ + "login": "bitwiseman", + "id": 1958953, + "node_id": "MDQ6VXNlcjE5NTg5NTM=", + "avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bitwiseman", + "html_url": "https://github.com/bitwiseman", + "followers_url": "https://api.github.com/users/bitwiseman/followers", + "following_url": "https://api.github.com/users/bitwiseman/following{/other_user}", + "gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions", + "organizations_url": "https://api.github.com/users/bitwiseman/orgs", + "repos_url": "https://api.github.com/users/bitwiseman/repos", + "events_url": "https://api.github.com/users/bitwiseman/events{/privacy}", + "received_events_url": "https://api.github.com/users/bitwiseman/received_events", + "type": "User", + "site_admin": false, + "name": "Liam Newman", + "company": "Cloudbees, Inc.", + "blog": "", + "location": "Seattle, WA, USA", + "email": "bitwiseman@gmail.com", + "hireable": null, + "bio": "https://twitter.com/bitwiseman", + "public_repos": 166, + "public_gists": 4, + "followers": 135, + "following": 9, + "created_at": "2012-07-11T20:38:33Z", + "updated_at": "2019-09-24T19:32:29Z" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/2-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/2-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..f176fc4ff5 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/2-orgs_hub4j-test-org.json @@ -0,0 +1,42 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 9, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 132, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "members_allowed_repository_creation_type": "none", + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 3, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/3-r_h_github-api.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/3-r_h_github-api.json new file mode 100644 index 0000000000..2680467bcb --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/3-r_h_github-api.json @@ -0,0 +1,330 @@ +{ + "id": 206888201, + "node_id": "MDEwOlJlcG9zaXRvcnkyMDY4ODgyMDE=", + "name": "github-api", + "full_name": "hub4j-test-org/github-api", + "private": false, + "owner": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.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/github-api", + "description": "Tricky", + "fork": false, + "url": "https://api.github.com/repos/hub4j-test-org/github-api", + "forks_url": "https://api.github.com/repos/hub4j-test-org/github-api/forks", + "keys_url": "https://api.github.com/repos/hub4j-test-org/github-api/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/hub4j-test-org/github-api/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/hub4j-test-org/github-api/teams", + "hooks_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks", + "issue_events_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues/events{/number}", + "events_url": "https://api.github.com/repos/hub4j-test-org/github-api/events", + "assignees_url": "https://api.github.com/repos/hub4j-test-org/github-api/assignees{/user}", + "branches_url": "https://api.github.com/repos/hub4j-test-org/github-api/branches{/branch}", + "tags_url": "https://api.github.com/repos/hub4j-test-org/github-api/tags", + "blobs_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api/statuses/{sha}", + "languages_url": "https://api.github.com/repos/hub4j-test-org/github-api/languages", + "stargazers_url": "https://api.github.com/repos/hub4j-test-org/github-api/stargazers", + "contributors_url": "https://api.github.com/repos/hub4j-test-org/github-api/contributors", + "subscribers_url": "https://api.github.com/repos/hub4j-test-org/github-api/subscribers", + "subscription_url": "https://api.github.com/repos/hub4j-test-org/github-api/subscription", + "commits_url": "https://api.github.com/repos/hub4j-test-org/github-api/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/hub4j-test-org/github-api/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/hub4j-test-org/github-api/contents/{+path}", + "compare_url": "https://api.github.com/repos/hub4j-test-org/github-api/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/hub4j-test-org/github-api/merges", + "archive_url": "https://api.github.com/repos/hub4j-test-org/github-api/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/hub4j-test-org/github-api/downloads", + "issues_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues{/number}", + "pulls_url": "https://api.github.com/repos/hub4j-test-org/github-api/pulls{/number}", + "milestones_url": "https://api.github.com/repos/hub4j-test-org/github-api/milestones{/number}", + "notifications_url": "https://api.github.com/repos/hub4j-test-org/github-api/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/hub4j-test-org/github-api/labels{/name}", + "releases_url": "https://api.github.com/repos/hub4j-test-org/github-api/releases{/id}", + "deployments_url": "https://api.github.com/repos/hub4j-test-org/github-api/deployments", + "created_at": "2019-09-06T23:26:04Z", + "updated_at": "2019-09-25T23:32:35Z", + "pushed_at": "2019-09-21T14:29:14Z", + "git_url": "git://github.com/hub4j-test-org/github-api.git", + "ssh_url": "git@github.com:hub4j-test-org/github-api.git", + "clone_url": "https://github.com/hub4j-test-org/github-api.git", + "svn_url": "https://github.com/hub4j-test-org/github-api", + "homepage": "http://github-api.kohsuke.org/", + "size": 11387, + "stargazers_count": 0, + "watchers_count": 0, + "language": "Java", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "main", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "allow_squash_merge": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "organization": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.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 + }, + "parent": { + "id": 617210, + "node_id": "MDEwOlJlcG9zaXRvcnk2MTcyMTA=", + "name": "github-api", + "full_name": "hub4j/github-api", + "private": false, + "owner": { + "login": "hub4j", + "id": 54909825, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1", + "avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/hub4j", + "html_url": "https://github.com/hub4j", + "followers_url": "https://api.github.com/users/hub4j/followers", + "following_url": "https://api.github.com/users/hub4j/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j/orgs", + "repos_url": "https://api.github.com/users/hub4j/repos", + "events_url": "https://api.github.com/users/hub4j/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/hub4j/github-api", + "description": "Java API for GitHub", + "fork": true, + "url": "https://api.github.com/repos/hub4j/github-api", + "forks_url": "https://api.github.com/repos/hub4j/github-api/forks", + "keys_url": "https://api.github.com/repos/hub4j/github-api/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/hub4j/github-api/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/hub4j/github-api/teams", + "hooks_url": "https://api.github.com/repos/hub4j/github-api/hooks", + "issue_events_url": "https://api.github.com/repos/hub4j/github-api/issues/events{/number}", + "events_url": "https://api.github.com/repos/hub4j/github-api/events", + "assignees_url": "https://api.github.com/repos/hub4j/github-api/assignees{/user}", + "branches_url": "https://api.github.com/repos/hub4j/github-api/branches{/branch}", + "tags_url": "https://api.github.com/repos/hub4j/github-api/tags", + "blobs_url": "https://api.github.com/repos/hub4j/github-api/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/hub4j/github-api/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/hub4j/github-api/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/hub4j/github-api/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/hub4j/github-api/statuses/{sha}", + "languages_url": "https://api.github.com/repos/hub4j/github-api/languages", + "stargazers_url": "https://api.github.com/repos/hub4j/github-api/stargazers", + "contributors_url": "https://api.github.com/repos/hub4j/github-api/contributors", + "subscribers_url": "https://api.github.com/repos/hub4j/github-api/subscribers", + "subscription_url": "https://api.github.com/repos/hub4j/github-api/subscription", + "commits_url": "https://api.github.com/repos/hub4j/github-api/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/hub4j/github-api/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/hub4j/github-api/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/hub4j/github-api/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/hub4j/github-api/contents/{+path}", + "compare_url": "https://api.github.com/repos/hub4j/github-api/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/hub4j/github-api/merges", + "archive_url": "https://api.github.com/repos/hub4j/github-api/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/hub4j/github-api/downloads", + "issues_url": "https://api.github.com/repos/hub4j/github-api/issues{/number}", + "pulls_url": "https://api.github.com/repos/hub4j/github-api/pulls{/number}", + "milestones_url": "https://api.github.com/repos/hub4j/github-api/milestones{/number}", + "notifications_url": "https://api.github.com/repos/hub4j/github-api/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/hub4j/github-api/labels{/name}", + "releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}", + "deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments", + "created_at": "2010-04-19T04:13:03Z", + "updated_at": "2019-09-25T22:47:32Z", + "pushed_at": "2019-09-25T22:56:18Z", + "git_url": "git://github.com/hub4j/github-api.git", + "ssh_url": "git@github.com:hub4j/github-api.git", + "clone_url": "https://github.com/hub4j/github-api.git", + "svn_url": "https://github.com/hub4j/github-api", + "homepage": "http://github-api.kohsuke.org/", + "size": 11678, + "stargazers_count": 553, + "watchers_count": 553, + "language": "Java", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 427, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 96, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 427, + "open_issues": 96, + "watchers": 553, + "default_branch": "main" + }, + "source": { + "id": 617210, + "node_id": "MDEwOlJlcG9zaXRvcnk2MTcyMTA=", + "name": "github-api", + "full_name": "hub4j/github-api", + "private": false, + "owner": { + "login": "hub4j", + "id": 54909825, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1", + "avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/hub4j", + "html_url": "https://github.com/hub4j", + "followers_url": "https://api.github.com/users/hub4j/followers", + "following_url": "https://api.github.com/users/hub4j/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j/orgs", + "repos_url": "https://api.github.com/users/hub4j/repos", + "events_url": "https://api.github.com/users/hub4j/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/hub4j/github-api", + "description": "Java API for GitHub", + "fork": false, + "url": "https://api.github.com/repos/hub4j/github-api", + "forks_url": "https://api.github.com/repos/hub4j/github-api/forks", + "keys_url": "https://api.github.com/repos/hub4j/github-api/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/hub4j/github-api/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/hub4j/github-api/teams", + "hooks_url": "https://api.github.com/repos/hub4j/github-api/hooks", + "issue_events_url": "https://api.github.com/repos/hub4j/github-api/issues/events{/number}", + "events_url": "https://api.github.com/repos/hub4j/github-api/events", + "assignees_url": "https://api.github.com/repos/hub4j/github-api/assignees{/user}", + "branches_url": "https://api.github.com/repos/hub4j/github-api/branches{/branch}", + "tags_url": "https://api.github.com/repos/hub4j/github-api/tags", + "blobs_url": "https://api.github.com/repos/hub4j/github-api/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/hub4j/github-api/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/hub4j/github-api/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/hub4j/github-api/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/hub4j/github-api/statuses/{sha}", + "languages_url": "https://api.github.com/repos/hub4j/github-api/languages", + "stargazers_url": "https://api.github.com/repos/hub4j/github-api/stargazers", + "contributors_url": "https://api.github.com/repos/hub4j/github-api/contributors", + "subscribers_url": "https://api.github.com/repos/hub4j/github-api/subscribers", + "subscription_url": "https://api.github.com/repos/hub4j/github-api/subscription", + "commits_url": "https://api.github.com/repos/hub4j/github-api/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/hub4j/github-api/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/hub4j/github-api/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/hub4j/github-api/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/hub4j/github-api/contents/{+path}", + "compare_url": "https://api.github.com/repos/hub4j/github-api/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/hub4j/github-api/merges", + "archive_url": "https://api.github.com/repos/hub4j/github-api/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/hub4j/github-api/downloads", + "issues_url": "https://api.github.com/repos/hub4j/github-api/issues{/number}", + "pulls_url": "https://api.github.com/repos/hub4j/github-api/pulls{/number}", + "milestones_url": "https://api.github.com/repos/hub4j/github-api/milestones{/number}", + "notifications_url": "https://api.github.com/repos/hub4j/github-api/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/hub4j/github-api/labels{/name}", + "releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}", + "deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments", + "created_at": "2010-04-19T04:13:03Z", + "updated_at": "2019-09-25T22:47:32Z", + "pushed_at": "2019-09-25T22:56:18Z", + "git_url": "git://github.com/hub4j/github-api.git", + "ssh_url": "git@github.com:hub4j/github-api.git", + "clone_url": "https://github.com/hub4j/github-api.git", + "svn_url": "https://github.com/hub4j/github-api", + "homepage": "http://github-api.kohsuke.org/", + "size": 11678, + "stargazers_count": 553, + "watchers_count": 553, + "language": "Java", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 427, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 96, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 427, + "open_issues": 96, + "watchers": 553, + "default_branch": "main" + }, + "network_count": 427, + "subscribers_count": 0 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/4-r_h_github-api.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/4-r_h_github-api.json new file mode 100644 index 0000000000..6d03114863 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/__files/4-r_h_github-api.json @@ -0,0 +1,5 @@ +{ + "message": "Validation Failed", + "documentation_url": "https://docs.github.com/rest/branches/branches#sync-a-fork-branch-with-the-upstream-repository", + "status": "422" +} diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/1-user.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/1-user.json new file mode 100644 index 0000000000..a7e5c0c21c --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/1-user.json @@ -0,0 +1,48 @@ +{ + "id": "7f6e9a01-5bfa-4f72-9947-07df902f56c3", + "name": "user", + "request": { + "url": "/user", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "1-user.json", + "headers": { + "Date": "Wed, 25 Sep 2019 23:35:33 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4992", + "X-RateLimit-Reset": "1569457884", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"14ffd29009ddc2209c450bb29a5a8330\"", + "Last-Modified": "Tue, 24 Sep 2019 19:32:29 GMT", + "X-OAuth-Scopes": "gist, notifications, read:org, read:public_key, read:repo_hook, repo", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F845:5D1D:FFA88A:12FE539:5D8BF9C5" + } + }, + "uuid": "7f6e9a01-5bfa-4f72-9947-07df902f56c3", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/2-orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/2-orgs_hub4j-test-org.json new file mode 100644 index 0000000000..64182cc8c5 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/2-orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "cb173af2-c793-444a-acdf-c3850e7afdbe", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "2-orgs_hub4j-test-org.json", + "headers": { + "Date": "Wed, 25 Sep 2019 23:35:58 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4989", + "X-RateLimit-Reset": "1569457884", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"b7989d48e6539c9c76038995b902421b\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "gist, notifications, read:org, read:public_key, read:repo_hook, repo", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F855:59E1:1397ED7:171400E:5D8BF9DE" + } + }, + "uuid": "cb173af2-c793-444a-acdf-c3850e7afdbe", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/3-r_h_github-api.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/3-r_h_github-api.json new file mode 100644 index 0000000000..265e1fd4bb --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/3-r_h_github-api.json @@ -0,0 +1,51 @@ +{ + "id": "0a4d7a1a-f99c-47ca-840a-3e920c18bd1f", + "name": "repos_hub4j-test-org_github-api", + "request": { + "url": "/repos/hub4j-test-org/github-api", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "3-r_h_github-api.json", + "headers": { + "Date": "Wed, 25 Sep 2019 23:35:58 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4988", + "X-RateLimit-Reset": "1569457884", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"0678d1c39ea574f68cc0fb330b067cb7\"", + "Last-Modified": "Wed, 25 Sep 2019 23:32:35 GMT", + "X-OAuth-Scopes": "gist, notifications, read:org, read:public_key, read:repo_hook, repo", + "X-Accepted-OAuth-Scopes": "repo", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F855:59E1:1397EEB:1714029:5D8BF9DE" + } + }, + "uuid": "0a4d7a1a-f99c-47ca-840a-3e920c18bd1f", + "persistent": true, + "scenarioName": "scenario-1-repos-hub4j-test-org-github-api", + "requiredScenarioState": "Started", + "newScenarioState": "scenario-1-repos-hub4j-test-org-github-api-2", + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/4-r_h_github-api.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/4-r_h_github-api.json new file mode 100644 index 0000000000..ec44fcf0d3 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/syncNoFork/mappings/4-r_h_github-api.json @@ -0,0 +1,54 @@ +{ + "id": "2c69d5c8-dd81-4204-bad9-ee37f5b0ebfd", + "name": "repos_hub4j-test-org_github-api", + "request": { + "url": "/repos/hub4j-test-org/github-api/merge-upstream", + "method": "POST", + "bodyPatterns": [ + { + "equalToJson": "{\"branch\":\"main\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": false + } + ], + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + } + } + }, + "response": { + "status": 422, + "bodyFileName": "4-r_h_github-api.json", + "headers": { + "Date": "Wed, 25 Sep 2019 23:35:59 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "422 Unprocessable Entity", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4987", + "X-RateLimit-Reset": "1569457884", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"e40487cafd3670c0de171f4250dbefb8\"", + "X-OAuth-Scopes": "gist, notifications, read:org, read:public_key, read:repo_hook, repo", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F855:59E1:1397F0E:1714041:5D8BF9DE" + } + }, + "uuid": "2c69d5c8-dd81-4204-bad9-ee37f5b0ebfd", + "persistent": true, + "insertionIndex": 4 +} \ No newline at end of file From 72f4b76a20c5a2526dcf5ead28ec8673429ae056 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Sat, 27 Jul 2024 22:15:14 -0700 Subject: [PATCH 4/5] Update src/main/java/org/kohsuke/github/GHBranchSync.java --- src/main/java/org/kohsuke/github/GHBranchSync.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHBranchSync.java b/src/main/java/org/kohsuke/github/GHBranchSync.java index 2acd48a0ca..eb11971966 100644 --- a/src/main/java/org/kohsuke/github/GHBranchSync.java +++ b/src/main/java/org/kohsuke/github/GHBranchSync.java @@ -1,6 +1,5 @@ package org.kohsuke.github; -import com.fasterxml.jackson.annotation.JsonProperty; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; public class GHBranchSync extends GitHubInteractiveObject { @@ -9,10 +8,8 @@ public class GHBranchSync extends GitHubInteractiveObject { private String message; - @JsonProperty("merge_type") private String mergeType; - @JsonProperty("base_branch") private String baseBranch; /** From f98355f1ee5bec08e46e8f7697900ce235114779 Mon Sep 17 00:00:00 2001 From: Valentin Delaye Date: Sun, 28 Jul 2024 11:17:01 +0200 Subject: [PATCH 5/5] Add missing javadoc --- .../java/org/kohsuke/github/GHBranchSync.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHBranchSync.java b/src/main/java/org/kohsuke/github/GHBranchSync.java index eb11971966..d03f4a79b4 100644 --- a/src/main/java/org/kohsuke/github/GHBranchSync.java +++ b/src/main/java/org/kohsuke/github/GHBranchSync.java @@ -2,14 +2,29 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +/** + * The type Gh branch sync. + */ public class GHBranchSync extends GitHubInteractiveObject { + /** + * The Repository that this branch is in. + */ private GHRepository owner; + /** + * The message. + */ private String message; + /** + * The merge type. + */ private String mergeType; + /** + * The base branch. + */ private String baseBranch; /** @@ -22,18 +37,38 @@ public GHRepository getOwner() { return owner; } + /** + * Gets message. + * + * @return the message + */ public String getMessage() { return message; } + /** + * Gets merge type. + * + * @return the merge type + */ public String getMergeType() { return mergeType; } + /** + * Gets base branch. + * + * @return the base branch + */ public String getBaseBranch() { return baseBranch; } + /** + * To string. + * + * @return the string + */ @Override public String toString() { return "GHBranchSync{" + "message='" + message + '\'' + ", mergeType='" + mergeType + '\'' + ", baseBranch='"