Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

refactor: simplify git helpers#134

Merged
tjkandala merged 5 commits into
masterfrom
refactor-git
Jan 20, 2021
Merged

refactor: simplify git helpers#134
tjkandala merged 5 commits into
masterfrom
refactor-git

Conversation

@tjkandala

Copy link
Copy Markdown
Contributor
  • gitRemoteBranch was called by both gitDefaultRemoteURL and gitBranch and the return value was used differently in each call site
  • Change precedent for multiple return values from array to object

@tjkandala tjkandala requested review from a team, felixfbecker and marekweb and removed request for a team January 6, 2021 21:37
Comment thread src/git.ts Outdated
if (remote !== '') {
return gitRemoteURL(repoDirectory, remote)
async function gitRemoteNameAndBranch(repoDirectory: string): Promise<RemoteName & Branch> {
let remoteName = ''

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we also change the pattern of using empty strings to using undefined? I.e. making a property optional if it can be optional, otherwise just relying on control flow analysis to make sure this is assigned.
Since a branch doesn't need to have an upstream I guess it would be optional? Or should the whole object be potentially undefined? I can't tell if this function name should read as "get the git remote name and get the branch name" or "get the git remote name and get the remote branch name"

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.

Right now we only use the branch if the remote is found, so we should return undefined instead of optional properties. This would also make our type simpler, since fileRelative is also dependent on the remote as well. We can revisit this function if it ever has more callers.

As for how to read the function name, I believe it's ideally the latter, but we fall back to 'HEAD' if we can't find the remote branch name.

Comment thread src/git.ts Outdated
Comment on lines 106 to 108
let remoteURL = ''
let branch = ''
let fileRelative = ''

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same comment here

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.

It looks like we do this to "salvage" variables already re-assigned by the time an error is thrown. The issue is that whether we use the other values is dependent on whether remoteURL is found. Is there ever a case where we'd catch an error but still end up with remoteURL? I can't think of any since it's the last value we look for.

@felixfbecker

Copy link
Copy Markdown
Contributor

Let's not leave PRs hanging in open state for long - @marekweb could you review too, and @tjkandala are you planning on either making more changes or merging?

@tjkandala

Copy link
Copy Markdown
Contributor Author

@felixfbecker I made the changes you suggested, ready to merge now

@tjkandala tjkandala merged commit cbbfac2 into master Jan 20, 2021
@tjkandala tjkandala deleted the refactor-git branch January 20, 2021 01:07
@github-actions

github-actions Bot commented Feb 1, 2021

Copy link
Copy Markdown

🎉 This PR is included in version 1.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants