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

Best way to add "for current user" routes that don't take a User ID? #44

Closed
Mr-Wallet opened this issue Mar 16, 2018 · 19 comments
Closed
Milestone

Comments

@Mr-Wallet
Copy link
Contributor

My team is trying to move from the original node-gitlab repo to this one, primarily for v4 support. A few routes we need are still not implemented here, so we're interested in opening some pull requests.

One that is not totally straightforward is routes that sometimes take an ID and sometimes don't. For example, in UserKeys, all requires a userID so it can make a GET to /users/${id}/keys. But there's also a route /user/keys (docs) to make a request for the currently-authenticated user based on their token (without having to first ask the API what the user's ID is).

I was just wondering how best we could fit things of this pattern into this project. Since it's listed in the Users documentation, on our fork of node-gitlab we put the implementation into UserKeys and called it the somewhat-verbose allForCurrentUser. Does this work for you or is there something you think would fit better?

@jdalrymple
Copy link
Owner

Hey! I've recently tackled this problem and will have a beta release ready by the end of this weekend. for this case it will be somehting like

UserKeys.all({userId})

Where the userId is optional, if its passed it with be for that user, else it will be for the currently authenticated user.

Does this work for you?

@Mr-Wallet
Copy link
Contributor Author

Mr-Wallet commented Mar 16, 2018

Honestly that makes even more sense than GitLab's own URI design. As long as it also has add and remove, that will actually be almost everything we need. While I have your attention, do you think you could sneak "get forks" into that release?

@jdalrymple
Copy link
Owner

Yup!

@jdalrymple
Copy link
Owner

Check the most recent beta release, tell me if it works for you!

@Mr-Wallet
Copy link
Contributor Author

I was skimming the diff and I noticed the push to Node 9. Did you sneak any Node 9 features in? We have a big cruise ship of an app and only fairly recently managed to get it on Node 8, so that would be a no-go for us. If it's safe to do so, perhaps on our own fork of this we could downgrade that assertion back to 8, for the sake of our CI/linter.

@jdalrymple
Copy link
Owner

Yea a few, I can put it back to what it was before which compiled down to 8.9.0 ? Just trying to keep the the library up to date :(

@Mr-Wallet
Copy link
Contributor Author

Besides the immediate inconvenience to us personally, I'm most concerned about us using something versioned against 9 because odd-numbered Node releases do not go into LTS when development finishes on them. For our part, I suspect we're probably going to stay on 8 until we can make the jump to 10.

Unfortunately you seem to have the only good node module for gitlab API v4 at the moment... 😅 We'd love to rely on this excellent package, but in our particular case we need to distinguish between "up to date" and "bleeding edge". If you don't expect to use anything exclusive to Node 9, it may be better for adoption to stick with 8. If that's unpalatable then we can fork this and build it against 8 ourselves - but if we can, we'd like to avoid having to worry about pulling in ongoing updates from this base repo.

@jdalrymple
Copy link
Owner

jdalrymple commented Mar 19, 2018

thats fair! Ill keep it compiling down to 8 lts!

@Mr-Wallet
Copy link
Contributor Author

By the way, I really love the defaulting = {} behavior for options, so you might consider doing that for e.g. UserKeys, so that people don't need to provide an empty object when omitting user ID.

@jdalrymple
Copy link
Owner

Oops! Must of missed it thanks!

@jdalrymple
Copy link
Owner

Just pushed another release with some more fixes. Going to let it settle for a few days to see if i missed anything serious and then ill officially release it

@Mr-Wallet
Copy link
Contributor Author

It's not clear what the intended way to use 3.0.0 is, aside from the addition of the new keyword. (We definitely want to stick with the "Basic Import" since we are going to use many namespaces.) I really like v2's way of not needing to use new, and getting an object where namespaces can be accessed as properties. I think the Examples section in rc2's README may be out of date; or if not, it should define what the api variable refers to.

@jdalrymple
Copy link
Owner

jdalrymple commented Mar 20, 2018

I agree with not using the new keyword, but in v2 it was inconsistent and without it would require alot of self initialization which was what i was trying to avoid. It is annoying though im aware :P.

Ill update the examples to show the import so the variable makes more sense. Its just a reference to the above basic import examples.

Minus the new key word, the availabilty of the namespaces as properties are still present!

import Gitlab from 'node-gitlab-api';

const api = new Gitlab({ my credentials here });

api.Projects.all()
api.Groups.all()
api.SystemHooks.show(2) 

//etc

Sorry for the confusion!! If i can make it any clearer please dont hesitate to say anything :D

Edit: Added more docs, tell me if that helps !!

@Mr-Wallet
Copy link
Contributor Author

Mr-Wallet commented Mar 20, 2018

That's definitely what I was expecting. The issue I was having is that when I create a new Gitlab, I end up with something that doesn't have those properties on it. Instead it's something with the Namespace prototype.

@jdalrymple
Copy link
Owner

jdalrymple commented Mar 20, 2018 via email

@Mr-Wallet
Copy link
Contributor Author

I had assumed you intentionally changed something 😆

@jdalrymple
Copy link
Owner

jdalrymple commented Mar 20, 2018 via email

@jdalrymple
Copy link
Owner

Yup, i had conflicting variable names. Fixing now!!

@jdalrymple
Copy link
Owner

Should be good to go now :) v3.0.0-rc.3

@jdalrymple jdalrymple added this to the 3.0.0 milestone Mar 24, 2018
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

No branches or pull requests

2 participants