Skip to content

Start on context package - #7

Closed
vilmibm wants to merge 4 commits into
prototypefrom
context
Closed

vilmibm wants to merge 4 commits into
prototypefrom
context

Conversation

@vilmibm

@vilmibm vilmibm commented Oct 8, 2019

Copy link
Copy Markdown
Contributor

This WIP PR starts a context package that is intended to be called from commands to get information about the current state of a user, their config, their current repo, and their github account.

@vilmibm
vilmibm changed the base branch from master to prototype October 8, 2019 21:11

@mislav mislav left a comment

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.

Nice start!

Something I would like us to consider is potentially designing Context as an interface, and having other methods accept that interface when querying the context? That way, we could supply a fake context with mocked values during tests.

Still not clear on how exactly it would look like, but it might get clearer once we start writing more unit tests and experience the pain of isolating them from fs lookups.

Comment thread command/pr.go Resolved
Comment thread command/pr.go Resolved
Comment thread context/context.go
return "", err
}

return strings.Replace(currentBranch, "refs/heads/", "", 1), nil

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.

I wonder if there would be some value in passing around the branch as a Branch object instead of a string? The String() method of the Branch object could then return the name of that branch without the refs/heads/ prefix.

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.

👍

Comment thread context/context.go Outdated
return strings.Replace(currentBranch, "refs/heads/", "", 1), nil
}

func CurrentRepository() (GitRepository, error) {

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.

Perhaps this method name could be less ambiguous re: whether it refers to the "repository" as local git repository or "repository" as a GitHub Repository object?

@vilmibm vilmibm Oct 9, 2019 •

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.

yeah -- i'm still stuck on what a good implementation for keeping git and github repositories separate would be.

Honestly, I think I'm starting from too general a place here and should step back and work on something else...

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.

That makes sense! Maybe a better place to start would be top-down; i.e. start with a real command that needs to query current git branch, fetch some git config, and potentially fetch info about the current GitHub repo. How would we invoke this command in tests and stub out the current branch info? Also, if information like current branch or the list of git remotes is accessed more than one time per invocation of a command, do we perform any duplicate lookups? How to cache the results of those lookups instead.

Alternatively to stubbing in memory: the test could also prepare a real, isolated git repo just for the test, setup the current branch and some GitHub remotes in it, and cd into that repo for the duration of the test. However, I found out that this slows down tests significantly.

Nate Smith and others added 2 commits October 9, 2019 11:09
Co-Authored-By: Mislav Marohnić <[email protected]>
Co-Authored-By: Mislav Marohnić <[email protected]>
@probablycorey

Copy link
Copy Markdown
Contributor

Should this target master instead of prototype?

@tierninho
tierninho requested review from tierninho and removed request for tierninho October 9, 2019 22:58
@vilmibm

vilmibm commented Oct 10, 2019

Copy link
Copy Markdown
Contributor Author

I'm re-doing this work against master and will either make a new PR or just force push when that's ready.

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.

3 participants