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

Add global node_id to GHObject + GHTeam extends GHObject #791

Merged
merged 7 commits into from
Apr 22, 2020

Conversation

ingwarsw
Copy link
Contributor

@ingwarsw ingwarsw commented Apr 18, 2020

Description

That PR is adding Global Node ID according to https://developer.github.com/v4/guides/using-global-node-ids/
Im trying to mix v3 and v4 (graphQL) of GH API together and without Global Node IDs its really hard.

Extending GHObject in GHTeam changed signature of ID, so its back incompatible change (Im not sure why GHTeam was not extending GHObject, in my opinion there is no reason for not doing it).

Please let me know whats best idea to test if it will work on all objects that extends GHObject..

Before submitting a PR:

  • Push your changes to a branch other than master. Create your PR from that branch.
  • Add JavaDocs and other comments
  • Write tests that run and pass in CI. See CONTRIBUTING.md for details on how to capture snapshot data.
  • Run mvn clean compile locally. This may reformat your code, commit those changes.
  • Run mvn -D enable-ci clean install site locally. If this command doesn't succeed, your change will not pass CI.

@bitwiseman
Copy link
Member

This project is not ready to make backward incompatible API changes. When we do it, it will be a much larger change with a bunch of other clean ups. Please propose how you'd make this change without breaking api compatibility.

@bitwiseman bitwiseman closed this Apr 18, 2020
@bitwiseman bitwiseman reopened this Apr 18, 2020
*
* @return the id
*/
public int getId() {
Copy link
Member

Choose a reason for hiding this comment

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

We have a BridgeMethods to handle cases like these. Preserving backward compatibility while changing method return types.

https://github.com/github-api/github-api/blob/7d842175f7984e33b3d97346cba3b20a1f905031/src/main/java/org/kohsuke/github/GHObject.java#L75

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like it works only at runtime..
IDE still shows errors when trying to use it to return int..

But i assume its ok..

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is okay. If I had:

int a = team.getId();

Does it compile still with this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

incompatible types: possible lossy conversion from long to int

@ingwarsw
Copy link
Contributor Author

@bitwiseman There is also class that have implemented node_id on its own..
I have changed it to extend GHObject but Im not sure if it should go here (or to extra PR)
here is changed code (I did not checked tests or anything so far for it)
ingwarsw@f36f160

Copy link
Member

@bitwiseman bitwiseman left a comment

Choose a reason for hiding this comment

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

Can you do the getNodeId() addition without doing the getId() change?

They seem like distinct changes anyway.

*
* @return the id
*/
public int getId() {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is okay. If I had:

int a = team.getId();

Does it compile still with this change?

@@ -291,7 +291,7 @@ public void testShouldFetchTeam() throws Exception {
GHOrganization organization = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHTeam teamByName = organization.getTeams().get("Core Developers");

GHTeam teamById = gitHub.getTeam(teamByName.getId());
GHTeam teamById = gitHub.getTeam((int) teamByName.getId());
Copy link
Member

Choose a reason for hiding this comment

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

Right... so this means there will be build breaks for clients and we can't have that.

Copy link
Contributor Author

@ingwarsw ingwarsw Apr 21, 2020

Choose a reason for hiding this comment

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

That would mean we would have not to extend GHObject in GHTeam but write own implementation of node_id.. (And I actually need GHTeam)
And thats actually not good idea (it should extend it from the start)..

Im not sure how bridge methods should work (but in java you cannot have 2 methods with same signature just different return type), but probably it just work at runtime..
At compile time it for sure gives error..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you want me to remove extension and implement node id in GHTeam without issues..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bitwiseman From code perspective I see that such "breaking" changes was already being mage few times (that changes are binary compatible because of that bridge methods)

See here
b6e48cc
edd9a2d

And GHObject was also moved from int to long not far away...
#388

So I think its safe enought to do it..

@bitwiseman
Copy link
Member

Added tests and did some reformatting.

@bitwiseman bitwiseman merged commit cc2d14a into hub4j:master Apr 22, 2020
@ingwarsw
Copy link
Contributor Author

@bitwiseman Thanks..

@bitwiseman
Copy link
Member

Will release the next version in the next week or so. If you have any ideas on supporting GitHub API v4, I'd be interested to hear them.

@ingwarsw
Copy link
Contributor Author

@bitwiseman To connect to GH v4 API Im using "Allegro" framework (https://github.com/apollographql/apollo-android)

Calls itself are rather simple..
Only part that Is common to Github and I hat to write small wrapper over framework was paging and rate limits..

For now Im just using GraphQL to:

  • Setup branch protections (v4 allows setting branch protection with rules not branch per branch so In my case for some repos I was able ro replace 500 rules for 5)
  • Get list of all users with SAML emails.. to check with our AD and remove ones that are not there anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants