-
Couldn't load subscription status.
- Fork 7.3k
Using go's reflection library for dynamic PR lookup #1081
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
Conversation
| return fmt.Sprintf("%s:%s", pr.HeadRepositoryOwner.Login, pr.HeadRefName) | ||
| } | ||
| return pr.HeadRefName | ||
| } |
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.
It seems a little odd having this function (and ReviewStatus, CheckStatus) on the struct now?. Maybe it would be better as a helper function?
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.
What would be the issue with it being on the struct? It seems intuitive to me but I could be missing something
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.
It's just that there are three pull request structs in this PullRequestComplex, PullRequestMinimal, PullRequestComplexWithMergable and only one has the method on it.
But maybe that's fine?
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 really like this direction and would like to see it applied throughout the code 👍
Does the interface of prFromArgs make sense?
It does to me.
I've made the assumption that any helper functions that take a PR use the "complex" PR struct. This seems to work because the places where we use the "minimal" PR struct don't use the helper functions. Does that make sense?
It makes sense but sounds like something we're ultimately going to want an interface for, right?
I didn't use reflection on the api.PullRequests method because it is only used by the status command and we know what type we want.
Makes sense for now; I could see us wanting to generalize that in the future but until we need to then 🤷
| return fmt.Sprintf("%s:%s", pr.HeadRepositoryOwner.Login, pr.HeadRefName) | ||
| } | ||
| return pr.HeadRefName | ||
| } |
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.
What would be the issue with it being on the struct? It seems intuitive to me but I could be missing something
| column { | ||
| name | ||
| type PullRequestComplex struct { | ||
| PullRequestMinimal |
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 like how these compose 👍
@vilmibm that's what my original plan was, but I always forget go interfaces only work with methods not fields. But hopefully I'm wrong about this because using an interface would solve lots of problems. |
|
ah, duh :( my brain keeps reaching for union types but i guess we don't really have that in go in any useful way. specific structs being required makes sense then. |
|
This was a good hackday project, but we all agreed the PR has too much surface area. To get these ideas in I think we should divide this into three parts.
|
Based on the work in #1020
This was what I worked on for hack day and I'd love feedback on it. I think it's worth doing, but my head had been in it for 3 days and I'm not sure anymore.
This PR does two things:
This let's us choose how much PR data we want by changing the type of the pr we send in. For example, if we want to include the mergability data we can do this:
api.PullRequeststruct to the pull request structs mentioned above. The next step would be to convert everything away fromapi.PullRequestand delete it, but this felt out of scope for this PR.Things I'll love feedback on
prFromArgsmake sense?api.PullRequestsmethod because it is only used by the status command and we know what type we want._I tried to keep the pull request readable, but there were a lot of changes 🙇 _