node-gh / gh

(DEPRECATED) GitHub CLI made with NodeJS. Use the official https://cli.github.com/ instead.
http://nodegh.io
Other
1.71k stars 217 forks source link

[WIP] Add search feature to repo command #588

Closed svallory closed 4 years ago

svallory commented 5 years ago

Hey there, I constantly search for repos on GH because the org I work for has literally hundreds of them with odd names :/

So I found out about nodegh today (which is awesome btw!) but grepping the result of list was too slow, so I decided to add the search option.

The feature is incomplete, needs docs, but I decided to share sooner so you guys can check and tell me if I'm going in the right direction ;)

Btw, options.user is always set. So for now I had to use a workaround to detect if the user passed it or not here

This will close #451 when it's done

protoEvangelion commented 5 years ago

@svallory You are headed in the right direction. I will review more in depth soon 😄

It looks like you have already found it but just in case here is the relevant api doc: https://octokit.github.io/rest.js/#api-Search-repos

This is probably the best example of trying to distinguish user from an organization if that's what you are trying to do: https://github.com/node-gh/gh/blob/master/lib/cmds/repo.js#L423

svallory commented 5 years ago

@protoEvangelion I saw that code. The problem I found is that options.user is always set to the logged user. So I can't tell if that option was passed to the command by looking at that variable. At least in the context of the search command, if the user option isn't specified, it should be null, so the search won't be restricted. This looks like a bug, but I didn't have time to debug it.

protoEvangelion commented 5 years ago

Ya I definitely see the problem in conflating argv with ~/.gh.json options.

It looks like we set it early on in the program here: https://github.com/node-gh/gh/blob/master/lib/cmd.js#L152

I think your workaround is fine for now, and we can do a better job in the future of delineating between argv and real options.

protoEvangelion commented 5 years ago

@svallory I noticed you still had this marked as WIP. Is there anything else you wanted to do for this?

svallory commented 5 years ago

Hi @protoEvangelion, sorry for the huuuge delay. There are no tests written and the question about the workaround. But I did use the search function in a script and it worked

protoEvangelion commented 4 years ago

Will reopen because git will not let me push to your branch even if using -f.

protoEvangelion commented 4 years ago

https://github.com/node-gh/gh/pull/685