-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Replace getRepoURL
and getRepoPath
with getRepositoryInfo
#47
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @yakov116 for any comments
I'll replace the usage of the deprecated functions both here and in RG before merging
index.ts
Outdated
} | ||
|
||
if (!isRepo(url)) { | ||
return {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to return {}
instead of undefined
to make it easier to check without having to use ?.
// Before:
if (getRepoPath() === undefined)
// Now:
if (getRepositoryInfo().path === undefined)
// If it returned `undefined`:
if (getRepositoryInfo()?.path === undefined)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed my mind. Returning Partial<RepositoryInfo>
is actually wrong because the type is actually RepositoryInfo | {}
.
The difference is that with the first one, even if you typecheck if !repository.name, return
, .path
will still be string | undefined
, even if we know for sure it's a string.
Unfortunately RepositoryInfo | {}
is awkward to use because repository.name
will cause a type error: name doesn't exist on {}
.
In short, since we have ?.
in the language, let's make use of it for ease of use, even if it generates slightly longer code.
I debated this when I did the lint. One thing that held me back was that we sometimes need the repo url in lower case. So I backed off changing it all and just kept |
Good point. I added a couple of notes to my first post as well. |
Pre-published as |
Do we? I think this was solved by our use of The only annoyance is that |
If I am not mistaken it was added because of that line. Will look for the PR to confirm. |
Yeah, I mean we just need to make sure that all the comparisons are made on the same normalized content. In some cases we could still use |
Last 2 points:
|
Initially added in Refined GitHub, I think we can bring this over, unify it and deprecate any other function.
The 2 functions aren't mapped exactly to
getRepositoryInfo
. Here are the differences:getRepoURL
did not actually checkisRepo
, so it would return'settings'
if you were onhttps://github.com/settings
getRepoPath
did not use the canonical URL, however this probably isn't much of an issue generallyI need to ensure that this doesn't impact the current usage in RGH