Conversation
This reverts commit 7427716.
probablycorey
left a comment
There was a problem hiding this comment.
I want to use this! I had a few questions about naming and errors.
api/queries.go
Outdated
| repo := project.Name | ||
| currentBranch := currentBranch() | ||
| ghRepo, rerr := context.CurrentGitHubRepository() | ||
| if rerr != nil { |
There was a problem hiding this comment.
I'm guessing that using rerr over err has some benefit here, but I can't tell what it is.
There was a problem hiding this comment.
something that is plaguing me in golang is this scenario:
foo, err := someFunction()
if err != nil { return err }
bar, err := otherFunction() // fails because err is already defined and i'm trying to use := operatori've been slapping letters onto my err variable names to make them distinct and allow group assignment / initialization. i assume there is a better way to do this and i'm all ears.
There was a problem hiding this comment.
Then I have good news for you! You can reuse the err variable with short variable declarations, as long as you declares multiple variables with :=. This code compiles fine!
foo, err := os.Open("file.moo")
if err != nil {
panic(err)
}
bar, err := os.Open("file.go")
fmt.Printf("%v %v %v", foo, bar, err)
Unlike regular variable declarations, a short variable declaration may redeclare variables provided they were originally declared earlier in the same block (or the parameter lists if the block is the function body) with the same type, and at least one of the non-blank variables is new. As a consequence, redeclaration can only appear in a multi-variable short declaration. Redeclaration does not introduce a new variable; it just assigns a new value to the original.
There was a problem hiding this comment.
OH
i didn't even try because i knew := failed for singular assignment
welp, thank you for telling me! i think this PR no longer has the subtly renamed errs but i'll keep it in mind for the future
| currentUsername, err := context.CurrentUsername() | ||
| if err != nil { | ||
| return PullRequestsPayload{}, err | ||
| } |
There was a problem hiding this comment.
To get the branch, repo and username there is a lot of error checking. Would it be simpler to call context.GetContext() that returns a struct with the data and an err?
This would also make it easier to test as well because we could mock what is returned by GetContext()
context/remote.go
Outdated
| } | ||
|
|
||
| // GuessRemote attempts to select and return the remote a user likely wants to target when dealing with GitHub repositories. | ||
| func GuessRemote() (Remote, error) { |
There was a problem hiding this comment.
We pretty much to guess which remote to use, but naming the function that makes it feel more random than it is? Would DefaultRemote work?
There was a problem hiding this comment.
GuessRemote felt honest; DefaultRemote makes it sound like we have some hardcoded default independent of the repo we're in. While not truly random, we are picking a remote without any actual information from the user that it's what they want.
There was a problem hiding this comment.
Yeah, I guess I'm trying to pretend we aren't guessing, which doesn't really communicate what it does. So GuessRemote works, GuessDefaultRemote might be more descriptive, but I'm totally fine with GuessRemote now too.
There was a problem hiding this comment.
My hope is a name like GuessRemote will motivate us to have a better system for remote determination ^_^
|
💫 Now ready for review! ✨ // Context represents the interface for querying information about the current environment
type Context interface {
AuthToken() (string, error)
AuthLogin() (string, error)
Branch() (string, error)
SetBranch(string)
Remotes() (Remotes, error)
BaseRepo() (*GitHubRepository, error)
SetBaseRepo(string)
}
// example usage:
branch, err := context.Current().Branch()Design goals:
@vilmibm To reach the above goals, I had to restructure and rename a lot of the existing context comands. Your code served as a great outline for me, but in the end I mostly rewrote the whole branch. I hope you don't mind! Please let me know what you think 🙇 Breaking:
|
|
Update:
|
probablycorey
left a comment
There was a problem hiding this comment.
This is wonderful, it's going to make the code so much easier to write and maintain! I have a few questions:
-
Is there an advantage to using
context.Current()over automatically creating currentContext in the package'sInitfunction? I think we could still mock the context in tests by callingcontext.InitBlankContextand we could callcontext.Whaterver()instead ofcontext.Current.Whaterver() -
The
context.BaseRepowas a little confusing to me. It made me think it was contained info about the git repo, and then I was wondering if there are other non-base repos. But if it was called something likeGitHubRepoit would have clicked more quickly. -
AuthLoginmakes me thing this method with log me in rather than return the username. MaybeUsernameorAuthUsername?
That's a great question. Right now it doesn't seem like there is a clear advantage, but when designing this, I was trying to be a bit defensive about putting all context methods as being "global" in the But as things are wired up right now, there's not a clear benefit from calling
This is good feedback around naming. I'll try to rename them according to your suggestions so that their intent is more immediately apparent. |
fix addArgs and combine by addding branchName parameter
Remove Terminal, no longer needed by ghcs
Add common badges for python projects Co-authored-by: Mackenzie Zastrow <zastrowm@users.noreply.github.com>
This was an attempt at moving some stuff out of
githuband into a new package,context. It also houses some code that @probablycorey added in his graphql PR.It's entirely possible that this isn't the direction we want to go in and I'm open to that. I wanted to open this PR anyway since afaik it doesn't break anything and includes a fair bit of code trimming.
Punted things:
github. it was too tightly coupled withgithub.client, which is still in use in establishing auth context. since @mislav is redoing our auth flow i ultimately just decided to leave this alone after many attempts to cleanly disentanglelocalrepobut i didn't get to thatgithub.client