Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial feature add #1986

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ public GHRepository() {
private GHRepository source, parent;

private Boolean isTemplate;

private boolean compareUsePaginatedCommits;

private Set<GHRepositoryCustomProperty> custom_properties;
Copy link
Member

@bitwiseman bitwiseman Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts: I'm not sure that Set helps you here. You might want to represent this as

  • List - getting all of them
  • Map<String, String> - the docs seem to indicate that you can't have multiple properties with the same name value on a repository or organization. And the properties are just name/value pairs...
  • Map<String,CustomProperty> - This might be a good choice for future proofing, in case GitHub decides to make CustomProperty records more complex in future.

For either of the Map options you need to check whether key value uniqueness case-insensitive, case-sensitive but restricted to ASCII, or literary any Unicode/UTF-8 String.

I mean this as a discussion. I'm fully open to changing my mind.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got my custom properties returned to me using this code base referenced in a console app.

I was discussing map options with a friend of mine but haven't been able to get it to work yet. I am not familiar with how this repo handles object mapping and kept running into null errors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use Jackson.

Give an example of where you get null errors and we'll see if we can figure it out.


/**
* Read.
*
Expand Down Expand Up @@ -2893,6 +2896,24 @@ public GHRepositoryCloneTraffic getCloneTraffic() throws IOException {
.fetch(GHRepositoryCloneTraffic.class);
}

/**
* Gets all custom property values that are set for a repository. Users with read access to the repository can use
* this endpoint. <a href=
* "https://docs.github.com/en/rest/repos/custom-properties?apiVersion=2022-11-28#get-all-custom-property-values-for-a-repository">
* docs</a>
*
* @return the custom properties and values on the repository
* @throws IOException
* the io exception
*/
public Set<GHRepositoryCustomProperty> getCustomProperties() throws IOException {
return root().createRequest()
.method("GET")
.withUrlPath("/properties/values")
.toIterable(GHRepositoryCustomProperty[].class, null)
.toSet();
}

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

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

/**
* A custom property set on a repository in GitHub.
*
* @author gitPushPuppets
*/
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
justification = "JSON API")
public class GHRepositoryCustomProperty {

/**
* Create default GHRepositoryCustomProperty instance
*/
public GHRepositoryCustomProperty() {
}

private String property_name;
private String value;

/**
* Gets property_name
*
* @return the property_name
*/
public String getPropertyName() {
return property_name;
}

/**
* Gets property value
*
* @return the property value
*/
public String getValue() {
return value;
}

}
15 changes: 15 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,21 @@ public void testIsVulnerabilityAlertsEnabled() throws Exception {
assertThat(repository.isVulnerabilityAlertsEnabled(), is(true));
}

/**
* Test getCustomProperties. This test may or may not work, you will need to point to an org and repo that have
* custom properties setup
*
* @throws Exception
* the exception
*/
@Test
public void testGetCustomProperties() throws Exception {
GHRepository repository = getTempRepository();
Set<GHRepositoryCustomProperty> customProperties = repository.getCustomProperties();
GHRepositoryCustomProperty property = customProperties.iterator().next();
assertThat(customProperties, notNullValue());
}

private void verifyEmptyResult(PagedSearchIterable<GHPullRequest> searchResult) {
assertThat(searchResult.getTotalCount(), is(0));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"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": "[email protected]",
"hireable": null,
"bio": "https://twitter.com/bitwiseman",
"public_repos": 181,
"public_gists": 7,
"followers": 147,
"following": 9,
"created_at": "2012-07-11T20:38:33Z",
"updated_at": "2020-02-06T17:29:39Z",
"private_gists": 8,
"total_private_repos": 10,
"owned_private_repos": 0,
"disk_usage": 33697,
"collaborators": 0,
"two_factor_authentication": true,
"plan": {
"name": "free",
"space": 976562499,
"collaborators": 0,
"private_repos": 10000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"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": 11,
"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": 147,
"collaborators": 0,
"billing_email": "[email protected]",
"default_repository_permission": "none",
"members_can_create_repositories": false,
"two_factor_requirement_enabled": false,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 0,
"filled_seats": 12,
"seats": 0
}
}
Loading
Loading