Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@probablycorey
Copy link
Contributor

@probablycorey probablycorey commented Jun 2, 2020

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:

  1. Let's us specify which PR we want to look up using this interface
pr := PullRequestMinimal{}
err: = prFromArgs(ctx, apiClient, repo, args, &pr)

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:

pr := PullRequestComplexWithMergable{}
err: =prFromArgs(ctx, apiClient, repo, args, &pr)
  1. It moves us partially away from the api.PullRequest struct to the pull request structs mentioned above. The next step would be to convert everything away from api.PullRequest and delete it, but this felt out of scope for this PR.

Things I'll love feedback on

  1. Does the interface of prFromArgs make sense?
  2. 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?
  3. 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.

_I tried to keep the pull request readable, but there were a lot of changes 🙇 _

@probablycorey probablycorey self-assigned this Jun 2, 2020
@probablycorey probablycorey marked this pull request as ready for review June 2, 2020 18:08
return fmt.Sprintf("%s:%s", pr.HeadRepositoryOwner.Login, pr.HeadRefName)
}
return pr.HeadRefName
}
Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

@vilmibm vilmibm left a 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
}
Copy link
Contributor

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

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 👍

@probablycorey
Copy link
Contributor Author

It makes sense but sounds like something we're ultimately going to want an interface for, right?

@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.

@vilmibm
Copy link
Contributor

vilmibm commented Jun 5, 2020

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.

@probablycorey
Copy link
Contributor Author

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.

  1. Convert the API calls to use the githubv4 lib
  2. Duplicate the functions in pr_lookup to take custom PR structs, also create a helper function that converts these new structs to the legacy api.PullRequest struct so we don't have to duplicate all the funcs that take an api.PullRequest
  3. Factor out api.PullRequest completely and use custom PR structs everywhere.

@mislav mislav mentioned this pull request Sep 2, 2020
@mislav mislav deleted the relective-pr-lookup branch March 23, 2021 11:48
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.

2 participants