Skip to content

Start on context package#7

Closed
vilmibm wants to merge 4 commits intoprototypefrom
context
Closed

Start on context package#7
vilmibm wants to merge 4 commits intoprototypefrom
context

Conversation

@vilmibm
Copy link
Contributor

@vilmibm vilmibm commented Oct 8, 2019

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
Copy link
Contributor

@mislav mislav left a comment

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.

return "", err
}

return strings.Replace(currentBranch, "refs/heads/", "", 1), nil
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

👍

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

func CurrentRepository() (GitRepository, error) {
Copy link
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?

Copy link
Contributor Author

@vilmibm vilmibm Oct 9, 2019

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
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ć <mislav@github.com>
Co-Authored-By: Mislav Marohnić <mislav@github.com>
@probablycorey
Copy link
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
Copy link
Contributor Author

vilmibm commented Oct 10, 2019

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

@vilmibm vilmibm closed this Oct 14, 2019
@mislav mislav deleted the context branch October 31, 2019 10:14
vilmibm pushed a commit that referenced this pull request Jun 29, 2021
Added flags: --settings, --projects, and --wiki
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