-
Notifications
You must be signed in to change notification settings - Fork 75
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
Fix #746 - Expand FileComparison to Rename/Patch cases #747
Conversation
In the event that these are not exclusive cases, I'm happy to make the change to them being |
Seems they are exclusive according to: https://docs.github.com/en/rest/reference/commits#compare-two-commits
In the examples below it looks like the status cannot be both |
contents_url: String, | ||
patch: String | ||
) | ||
sealed trait FileComparison |
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.
Also, would it make sense to add the fields in the trait (as a def
s)? I think it could be helpful in handling the common fields
sealed trait FileComparison {
def sha: String
//...
}
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.
Done. Also added a couple helper methods for getPatch
and getPreviousFilename
for the cases where you don't necessarily want to do pattern matching.
The status cannot be both |
Thanks @rojsrojs for your inputs. I've changed the two cases as follows:
|
Just noticed and fixed an encoder/decoder ambiguity. Because the cases are separated now and can be parsed as each other, I've modified the encoder/decoder to take into account the expected |
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.
Left a minor comment, but it looks good to me.
* To guarantee that the `patch` field is available, match this `FileComparison` value as a | ||
* `FileComparison.FileComparisonNotRenamed` type which always has this field. | ||
*/ | ||
def getPatch: Option[String] |
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.
Would it make sense to remove the getPatch
and getPreviousFilename
fields from here? If the user wants these fields, they must match the concrete type. If they don't need those fields, they can use the supertype.
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 think it's a lot less verbose to use these rather than do a proper pattern match for some cases. If I'm using this library and I want "the previous filename if it exists" then that's a single method call. Or if I want the patch "if it exists" that's also a single call. Takes up a lot less vertical space. The main use case of doing the pattern match would be if you're passing the file comparison to some downstream function and want to validate that it's the right subtype first, but I don't think it should be required if we can help it.
Fixes #746
Took a slightly different approach than the one suggested. Because it seems like there are two distinct cases, I felt the user of the library should not have to know that these fields are mutually exclusive, and it should be instead clear from the models. If the
patch
field exists, it should be aString
and notOption[String]
since it sounds like that means there will also be noprevious_filename
field (and vice versa).I've added two additional cases for
FileComparison
asFileComparisonRename
andFileComparisonPatch
that contain these two exclusive cases as separate models. It involves a little copy/paste but nothing egregious and I think this is better for end-users than the alternative anyway.Either way, this is a breaking model change and should be noted when released.
EDIT: based on the below discussion, it seems the fields are not mutually exclusive but in the case of a rename there will always be
previous_filename
but not always apatch
. I've modified the cases to match, and I've added methods to get these from the common supertype if they exist asOption[String]
.