Skip to content

Commit

Permalink
Merge pull request #1836 from eleanorgoh/main
Browse files Browse the repository at this point in the history
Support repository renamed and transferred in event payload
  • Loading branch information
bitwiseman authored Apr 27, 2024
2 parents 6b2a487 + c5ce1f6 commit 2e6dcc1
Show file tree
Hide file tree
Showing 6 changed files with 629 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/kohsuke/github/GHEventPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,16 @@ public void setRelease(GHRelease release) {
* @see <a href="https://docs.github.com/en/rest/reference/repos">Repositories</a>
*/
public static class Repository extends GHEventPayload {
private GHRepositoryChanges changes;

/**
* Get changes.
*
* @return GHRepositoryChanges
*/
public GHRepositoryChanges getChanges() {
return changes;
}

}

Expand Down
106 changes: 106 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepositoryChanges.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Changes made to a repository.
*/
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
public class GHRepositoryChanges {
private FromRepository repository;
private Owner owner;

/**
* Get outer owner object.
*
* @return Owner
*/
public Owner getOwner() {
return owner;
}

/**
* Outer object of owner from whom this repository was transferred.
*/
public static class Owner {
private FromOwner from;

/**
* Get in owner object.
*
* @return FromOwner
*/
public FromOwner getFrom() {
return from;
}
}

/**
* Owner from whom this repository was transferred.
*/
public static class FromOwner {
private GHUser user;
private GHOrganization organization;

/**
* Get user from which this repository was transferred.
*
* @return user
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public GHUser getUser() {
return user;
}

/**
* Get organization from which this repository was transferred.
*
* @return GHOrganization
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public GHOrganization getOrganization() {
return organization;
}
}

/**
* Get repository.
*
* @return FromRepository
*/
public FromRepository getRepository() {
return repository;
}

/**
* Repository object from which the name was changed.
*/
public static class FromRepository {
private FromName name;

/**
* Get top level object for the previous name of the repository.
*
* @return FromName
*/
public FromName getName() {
return name;
}
}

/**
* Repository name that was changed.
*/
public static class FromName {
private String from;

/**
* Get previous name of the repository before rename.
*
* @return String
*/
public String getFrom() {
return from;
}
}
}
51 changes: 51 additions & 0 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,57 @@ public void repository() throws Exception {
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
}

/**
* Repository renamed.
*
* @throws Exception
* the exception
*/
@Test
public void repository_renamed() throws Exception {
final GHEventPayload.Repository event = GitHub.offline()
.parseEventPayload(payload.asReader(), GHEventPayload.Repository.class);
assertThat(event.getAction(), is("renamed"));
assertThat(event.getChanges().getRepository().getName().getFrom(), is("react-workshop"));
assertThat(event.getRepository().getName(), is("react-workshop-renamed"));
assertThat(event.getRepository().getOwner().getLogin(), is("EJG-Organization"));
assertThat(event.getOrganization().getLogin(), is("EJG-Organization"));
assertThat(event.getSender().getLogin(), is("eleanorgoh"));
}

/**
* Repository ownership transferred to an organization.
*
* @throws Exception
* the exception
*/
@Test
public void repository_transferred_to_org() throws Exception {
final GHEventPayload.Repository event = GitHub.offline()
.parseEventPayload(payload.asReader(), GHEventPayload.Repository.class);
assertThat(event.getAction(), is("transferred"));
assertThat(event.getChanges().getOwner().getFrom().getUser().getLogin(), is("eleanorgoh"));
assertThat(event.getChanges().getOwner().getFrom().getUser().getId(), is(66235606L));
assertThat(event.getChanges().getOwner().getFrom().getUser().getType(), is("User"));
}

/**
* Repository ownership transferred to a user.
*
* @throws Exception
* the exception
*/
@Test
public void repository_transferred_to_user() throws Exception {
final GHEventPayload.Repository event = GitHub.offline()
.parseEventPayload(payload.asReader(), GHEventPayload.Repository.class);
assertThat(event.getAction(), is("transferred"));
assertThat(event.getChanges().getOwner().getFrom().getOrganization().getLogin(), is("EJG-Organization"));
assertThat(event.getChanges().getOwner().getFrom().getOrganization().getId(), is(168135412L));
assertThat(event.getRepository().getOwner().getLogin(), is("eleanorgoh"));
assertThat(event.getRepository().getOwner().getType(), is("User"));
}

/**
* Status.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"action": "renamed",
"changes": {
"repository": {
"name": {
"from": "react-workshop"
}
}
},
"repository": {
"id": 360319037,
"node_id": "MDEwOlJlcG9zaXRvcnkzNjAzMTkwMzc=",
"name": "react-workshop-renamed",
"full_name": "EJG-Organization/react-workshop-renamed",
"private": false,
"owner": {
"login": "EJG-Organization",
"id": 168135412,
"node_id": "O_kgDOCgWK9A",
"avatar_url": "https://avatars.githubusercontent.com/u/168135412?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/EJG-Organization",
"html_url": "https://github.com/EJG-Organization",
"followers_url": "https://api.github.com/users/EJG-Organization/followers",
"following_url": "https://api.github.com/users/EJG-Organization/following{/other_user}",
"gists_url": "https://api.github.com/users/EJG-Organization/gists{/gist_id}",
"starred_url": "https://api.github.com/users/EJG-Organization/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/EJG-Organization/subscriptions",
"organizations_url": "https://api.github.com/users/EJG-Organization/orgs",
"repos_url": "https://api.github.com/users/EJG-Organization/repos",
"events_url": "https://api.github.com/users/EJG-Organization/events{/privacy}",
"received_events_url": "https://api.github.com/users/EJG-Organization/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/EJG-Organization/react-workshop-renamed",
"description": null,
"fork": true,
"url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed",
"forks_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/forks",
"keys_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/teams",
"hooks_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/hooks",
"issue_events_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/issues/events{/number}",
"events_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/events",
"assignees_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/assignees{/user}",
"branches_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/branches{/branch}",
"tags_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/tags",
"blobs_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/statuses/{sha}",
"languages_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/languages",
"stargazers_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/stargazers",
"contributors_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/contributors",
"subscribers_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/subscribers",
"subscription_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/subscription",
"commits_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/contents/{+path}",
"compare_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/merges",
"archive_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/downloads",
"issues_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/issues{/number}",
"pulls_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/pulls{/number}",
"milestones_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/milestones{/number}",
"notifications_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/labels{/name}",
"releases_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/releases{/id}",
"deployments_url": "https://api.github.com/repos/EJG-Organization/react-workshop-renamed/deployments",
"created_at": "2021-04-21T22:09:16Z",
"updated_at": "2024-04-25T20:31:00Z",
"pushed_at": "2021-04-21T03:47:44Z",
"git_url": "git://github.com/EJG-Organization/react-workshop-renamed.git",
"ssh_url": "[email protected]:EJG-Organization/react-workshop-renamed.git",
"clone_url": "https://github.com/EJG-Organization/react-workshop-renamed.git",
"svn_url": "https://github.com/EJG-Organization/react-workshop-renamed",
"homepage": null,
"size": 196,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": false,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"has_discussions": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"allow_forking": true,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [

],
"visibility": "public",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main",
"custom_properties": {

}
},
"organization": {
"login": "EJG-Organization",
"id": 168135412,
"node_id": "O_kgDOCgWK9A",
"url": "https://api.github.com/orgs/EJG-Organization",
"repos_url": "https://api.github.com/orgs/EJG-Organization/repos",
"events_url": "https://api.github.com/orgs/EJG-Organization/events",
"hooks_url": "https://api.github.com/orgs/EJG-Organization/hooks",
"issues_url": "https://api.github.com/orgs/EJG-Organization/issues",
"members_url": "https://api.github.com/orgs/EJG-Organization/members{/member}",
"public_members_url": "https://api.github.com/orgs/EJG-Organization/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/168135412?v=4",
"description": null
},
"sender": {
"login": "eleanorgoh",
"id": 66235606,
"node_id": "MDQ6VXNlcjY2MjM1NjA2",
"avatar_url": "https://avatars.githubusercontent.com/u/66235606?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/eleanorgoh",
"html_url": "https://github.com/eleanorgoh",
"followers_url": "https://api.github.com/users/eleanorgoh/followers",
"following_url": "https://api.github.com/users/eleanorgoh/following{/other_user}",
"gists_url": "https://api.github.com/users/eleanorgoh/gists{/gist_id}",
"starred_url": "https://api.github.com/users/eleanorgoh/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/eleanorgoh/subscriptions",
"organizations_url": "https://api.github.com/users/eleanorgoh/orgs",
"repos_url": "https://api.github.com/users/eleanorgoh/repos",
"events_url": "https://api.github.com/users/eleanorgoh/events{/privacy}",
"received_events_url": "https://api.github.com/users/eleanorgoh/received_events",
"type": "User",
"site_admin": false
}
}
Loading

0 comments on commit 2e6dcc1

Please sign in to comment.