Skip to content

Add global node_id to GHObject + GHTeam extends GHObject#791

Merged
bitwiseman merged 7 commits into
hub4j:masterfrom
ingwarsw:global_node_id
Apr 22, 2020
Merged

Add global node_id to GHObject + GHTeam extends GHObject#791
bitwiseman merged 7 commits into
hub4j:masterfrom
ingwarsw:global_node_id

Conversation

@ingwarsw
Copy link
Copy Markdown
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
Copy Markdown
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
Comment thread src/main/java/org/kohsuke/github/GHOrganization.java
*
* @return the id
*/
public int getId() {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/main/java/org/kohsuke/github/GHOrganization.java Outdated
Comment thread src/main/java/org/kohsuke/github/GHOrganization.java Outdated
*
* @return the id
*/
public int getId() {
Copy link
Copy Markdown
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?

GHTeam teamByName = organization.getTeams().get("Core Developers");

GHTeam teamById = gitHub.getTeam(teamByName.getId());
GHTeam teamById = gitHub.getTeam((int) teamByName.getId());
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Added tests and did some reformatting.

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

@bitwiseman Thanks..

@bitwiseman
Copy link
Copy Markdown
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
Copy Markdown
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