Skip to content

Commit

Permalink
Merge tag 'github-api-1.321' into release/v1.x
Browse files Browse the repository at this point in the history
github-api-1.321
  • Loading branch information
bitwiseman committed Mar 21, 2024
2 parents aeb676c + f6fd920 commit ecfc410
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 14 deletions.
@@ -1,4 +1,4 @@
name: Creat New Release Tag
name: Create New Release Tag and PR

on: workflow_dispatch

Expand All @@ -11,13 +11,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'

- name: Reset staging/main
id: staging
run: |
git checkout -B staging/main
git push --set-upstream -f origin staging/main
- name: Set Release Version
id: release
run: |
Expand All @@ -29,7 +38,7 @@ jobs:
commit_message: "Prepare release (${{ github.actor }}): github-api-${{ steps.release.outputs.version }}"
tagging_message: 'github-api-${{ steps.release.outputs.version }}'
branch: staging/main

- name: Increment Snapshot Version
run: |
mvn versions:set versions:commit -DnextSnapshot
Expand All @@ -38,7 +47,7 @@ jobs:
with:
commit_message: "Prepare for next development iteration"
branch: staging/main

- name: pull-request to main
uses: repo-sync/pull-request@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.320</version>
<version>1.321</version>
<name>GitHub API for Java</name>
<url>https://github-api.kohsuke.org/</url>
<description>GitHub API for Java</description>
Expand Down
60 changes: 54 additions & 6 deletions src/main/java/org/kohsuke/github/GHMemberChanges.java
@@ -1,5 +1,6 @@
package org.kohsuke.github;

import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.kohsuke.github.internal.EnumUtils;

Expand All @@ -11,6 +12,8 @@ public class GHMemberChanges {

private FromToPermission permission;

private FromRoleName roleName;

/**
* Get changes to permission.
*
Expand All @@ -20,6 +23,18 @@ public FromToPermission getPermission() {
return permission;
}

/**
* Get changes to the role name.
* <p>
* Apparently, it is recommended to use this rather than permission if defined. But it will only be defined when
* adding and not when editing.
*
* @return changes to role name
*/
public FromRoleName getRoleName() {
return roleName;
}

/**
* Changes to permission.
*/
Expand All @@ -34,19 +49,52 @@ public static class FromToPermission {
*
* @return the from
*/
public GHOrganization.Permission getFrom() {
return EnumUtils
.getNullableEnumOrDefault(GHOrganization.Permission.class, from, GHOrganization.Permission.UNKNOWN);
@WithBridgeMethods(value = GHOrganization.Permission.class, adapterMethod = "stringToOrgPermission")
public String getFrom() {
return from;
}

/**
* Gets the to.
*
* @return the to
*/
public GHOrganization.Permission getTo() {
return EnumUtils
.getNullableEnumOrDefault(GHOrganization.Permission.class, to, GHOrganization.Permission.UNKNOWN);
@WithBridgeMethods(value = GHOrganization.Permission.class, adapterMethod = "stringToOrgPermission")
public String getTo() {
return to;
}

@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getFrom and getTo")
private Object stringToOrgPermission(String permissionType, Class type) {
switch (permissionType) {
case "admin" :
return GHOrganization.Permission.ADMIN;
case "none" :
return GHOrganization.Permission.UNKNOWN;
case "read" :
return GHOrganization.Permission.PULL;
case "write" :
return GHOrganization.Permission.PUSH;
default :
return EnumUtils.getNullableEnumOrDefault(GHPermissionType.class, to, GHPermissionType.UNKNOWN);
}
}
}

/**
* Changes to role name.
*/
public static class FromRoleName {

private String to;

/**
* Gets the to.
*
* @return the to
*/
public String getTo() {
return to;
}
}
}
9 changes: 9 additions & 0 deletions src/test/java/org/kohsuke/github/BridgeMethodTest.java
Expand Up @@ -60,6 +60,15 @@ public void testBridgeMethods() throws IOException {

verifyBridgeMethods(GHTeam.class, "getId", int.class, long.class, String.class);

verifyBridgeMethods(GHMemberChanges.FromToPermission.class,
"getTo",
String.class,
GHOrganization.Permission.class);
verifyBridgeMethods(GHMemberChanges.FromToPermission.class,
"getFrom",
String.class,
GHOrganization.Permission.class);

// verifyBridgeMethods(GitHub.class, "getMyself", GHMyself.class, GHUser.class);

}
Expand Down
33 changes: 29 additions & 4 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Expand Up @@ -4,7 +4,6 @@
import org.junit.Test;
import org.kohsuke.github.GHCheckRun.Conclusion;
import org.kohsuke.github.GHCheckRun.Status;
import org.kohsuke.github.GHOrganization.Permission;
import org.kohsuke.github.GHProjectsV2Item.ContentType;
import org.kohsuke.github.GHProjectsV2ItemChanges.FieldType;
import org.kohsuke.github.GHTeam.Privacy;
Expand Down Expand Up @@ -1715,8 +1714,8 @@ public void member_edited() throws Exception {
assertThat(member.getLogin(), is("yrodiere"));

GHMemberChanges changes = memberPayload.getChanges();
assertThat(changes.getPermission().getFrom(), is(Permission.ADMIN));
assertThat(changes.getPermission().getTo(), is(Permission.TRIAGE));
assertThat(changes.getPermission().getFrom(), is("admin"));
assertThat(changes.getPermission().getTo(), is("triage"));
}

/**
Expand All @@ -1741,7 +1740,33 @@ public void member_added() throws Exception {

GHMemberChanges changes = memberPayload.getChanges();
assertThat(changes.getPermission().getFrom(), is(nullValue()));
assertThat(changes.getPermission().getTo(), is(Permission.ADMIN));
assertThat(changes.getPermission().getTo(), is("admin"));
}

/**
* Member added with role name defined.
*
* @throws Exception
* the exception
*/
@Test
public void member_added_role_name() throws Exception {
final GHEventPayload.Member memberPayload = GitHub.offline()
.parseEventPayload(payload.asReader(), GHEventPayload.Member.class);

assertThat(memberPayload.getAction(), is("added"));

assertThat(memberPayload.getOrganization().getLogin(), is("gsmet-bot-playground"));
assertThat(memberPayload.getRepository().getName(), is("github-automation-with-quarkus-demo-playground"));

GHUser member = memberPayload.getMember();
assertThat(member.getId(), is(412878L));
assertThat(member.getLogin(), is("yrodiere"));

GHMemberChanges changes = memberPayload.getChanges();
assertThat(changes.getPermission().getFrom(), is(nullValue()));
assertThat(changes.getPermission().getTo(), is("write"));
assertThat(changes.getRoleName().getTo(), is("maintain"));
}

/**
Expand Down
@@ -0,0 +1,169 @@
{
"action": "added",
"member": {
"login": "yrodiere",
"id": 412878,
"node_id": "MDQ6VXNlcjQxMjg3OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/412878?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/yrodiere",
"html_url": "https://github.com/yrodiere",
"followers_url": "https://api.github.com/users/yrodiere/followers",
"following_url": "https://api.github.com/users/yrodiere/following{/other_user}",
"gists_url": "https://api.github.com/users/yrodiere/gists{/gist_id}",
"starred_url": "https://api.github.com/users/yrodiere/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/yrodiere/subscriptions",
"organizations_url": "https://api.github.com/users/yrodiere/orgs",
"repos_url": "https://api.github.com/users/yrodiere/repos",
"events_url": "https://api.github.com/users/yrodiere/events{/privacy}",
"received_events_url": "https://api.github.com/users/yrodiere/received_events",
"type": "User",
"site_admin": false
},
"changes": { "permission": { "to": "write" }, "role_name": { "to": "maintain" } },
"repository": {
"id": 493568123,
"node_id": "R_kgDOHWtAew",
"name": "github-automation-with-quarkus-demo-playground",
"full_name": "gsmet-bot-playground/github-automation-with-quarkus-demo-playground",
"private": false,
"owner": {
"login": "gsmet-bot-playground",
"id": 81260024,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjgxMjYwMDI0",
"avatar_url": "https://avatars.githubusercontent.com/u/81260024?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gsmet-bot-playground",
"html_url": "https://github.com/gsmet-bot-playground",
"followers_url": "https://api.github.com/users/gsmet-bot-playground/followers",
"following_url": "https://api.github.com/users/gsmet-bot-playground/following{/other_user}",
"gists_url": "https://api.github.com/users/gsmet-bot-playground/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gsmet-bot-playground/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gsmet-bot-playground/subscriptions",
"organizations_url": "https://api.github.com/users/gsmet-bot-playground/orgs",
"repos_url": "https://api.github.com/users/gsmet-bot-playground/repos",
"events_url": "https://api.github.com/users/gsmet-bot-playground/events{/privacy}",
"received_events_url": "https://api.github.com/users/gsmet-bot-playground/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/gsmet-bot-playground/github-automation-with-quarkus-demo-playground",
"description": "Example repository with a demo GitHub app (github-automation-with-quarkus-demo-app) installed",
"fork": false,
"url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground",
"forks_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/forks",
"keys_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/teams",
"hooks_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/hooks",
"issue_events_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/issues/events{/number}",
"events_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/events",
"assignees_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/assignees{/user}",
"branches_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/branches{/branch}",
"tags_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/tags",
"blobs_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/statuses/{sha}",
"languages_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/languages",
"stargazers_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/stargazers",
"contributors_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/contributors",
"subscribers_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/subscribers",
"subscription_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/subscription",
"commits_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/contents/{+path}",
"compare_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/merges",
"archive_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/downloads",
"issues_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/issues{/number}",
"pulls_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/pulls{/number}",
"milestones_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/milestones{/number}",
"notifications_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/labels{/name}",
"releases_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/releases{/id}",
"deployments_url": "https://api.github.com/repos/gsmet-bot-playground/github-automation-with-quarkus-demo-playground/deployments",
"created_at": "2022-05-18T08:07:30Z",
"updated_at": "2022-05-19T10:46:46Z",
"pushed_at": "2023-07-07T08:22:15Z",
"git_url": "git://github.com/gsmet-bot-playground/github-automation-with-quarkus-demo-playground.git",
"ssh_url": "git@github.com:gsmet-bot-playground/github-automation-with-quarkus-demo-playground.git",
"clone_url": "https://github.com/gsmet-bot-playground/github-automation-with-quarkus-demo-playground.git",
"svn_url": "https://github.com/gsmet-bot-playground/github-automation-with-quarkus-demo-playground",
"homepage": null,
"size": 5,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"has_discussions": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": {
"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": [],
"visibility": "public",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main",
"custom_properties": {}
},
"organization": {
"login": "gsmet-bot-playground",
"id": 81260024,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjgxMjYwMDI0",
"url": "https://api.github.com/orgs/gsmet-bot-playground",
"repos_url": "https://api.github.com/orgs/gsmet-bot-playground/repos",
"events_url": "https://api.github.com/orgs/gsmet-bot-playground/events",
"hooks_url": "https://api.github.com/orgs/gsmet-bot-playground/hooks",
"issues_url": "https://api.github.com/orgs/gsmet-bot-playground/issues",
"members_url": "https://api.github.com/orgs/gsmet-bot-playground/members{/member}",
"public_members_url": "https://api.github.com/orgs/gsmet-bot-playground/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/81260024?v=4",
"description": null
},
"sender": {
"login": "gsmet",
"id": 1279749,
"node_id": "MDQ6VXNlcjEyNzk3NDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gsmet",
"html_url": "https://github.com/gsmet",
"followers_url": "https://api.github.com/users/gsmet/followers",
"following_url": "https://api.github.com/users/gsmet/following{/other_user}",
"gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gsmet/subscriptions",
"organizations_url": "https://api.github.com/users/gsmet/orgs",
"repos_url": "https://api.github.com/users/gsmet/repos",
"events_url": "https://api.github.com/users/gsmet/events{/privacy}",
"received_events_url": "https://api.github.com/users/gsmet/received_events",
"type": "User",
"site_admin": false
},
"installation": {
"id": 16779846,
"node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMTY3Nzk4NDY="
}
}

0 comments on commit ecfc410

Please sign in to comment.