-
Notifications
You must be signed in to change notification settings - Fork 141
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
Added the required status code StatusCodes.CREATED for the createRele… #231
Conversation
…rtion in createRelease. Now correctly returns false if no errors were returned.
Fixes: #230 createRelease was not working at all as it didn't register the expected return code of 201. getReleaseByTagName failed if a 404 occurred. Now returns null. Added asserts to RepositorySlug to ensure passed arguments were non-null. |
@robbecker-wf any chance of seeing this PR merged an an updated package pushed to pub.dev. I'm currently block on releasing another package that depends on it. |
ping @robbecker-wf |
Thanks for putting up this PR. I'll give it a review and some testing here soon. |
Thanks
…On Fri, 4 Sep 2020, 8:05 am Rob Becker, ***@***.***> wrote:
Thanks for putting up this PR. I'll give it a review and some testing here
soon.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#231 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG32OETAVXMTNAPGWE74DDSEAHI5ANCNFSM4P6NSIIA>
.
|
'/repos/${slug.fullName}/releases', | ||
convert: (i) => Release.fromJson(i), | ||
body: GitHubJson.encode(createRelease.toJson()), | ||
statusCode: StatusCodes.CREATED); |
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.
This part looks ok to me.
RepositorySlug(this.owner, this.name) { | ||
ArgumentError.checkNotNull(owner, 'owner'); | ||
ArgumentError.checkNotNull(name, 'name'); | ||
} |
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.
👍
@@ -96,7 +96,7 @@ class Release { | |||
String getUploadUrlFor(String name, [String label]) => | |||
"${uploadUrl.substring(0, uploadUrl.indexOf('{'))}?name=$name${label != null ? ",$label" : ""}"; | |||
|
|||
bool get hasErrors => errors?.isNotEmpty; | |||
bool get hasErrors => errors == null ? false : errors.isNotEmpty; |
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.
👍
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 have a feeling that returning null from hasErrors was causing a problem which is why I changed it to return false. I can't quite remember the circumstances.
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've just checked and the method createRelease has the following line:
if (release.hasErrors) {
As such hasErrors should never be null.
My experience with dart is that passing a bool with a null value always ends with someone crying.
lib/src/common/repos_service.dart
Outdated
}, | ||
); | ||
} on ReleaseNotFound catch (e) { | ||
release = null; |
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.
If I'm reading this correctly, this would mean that if a release isn't found callers might just get a null and not really know why. The exception is handled internally and silenced.
If that's correct it would mean it behaves inconsistently with other methods. For example the getReleaseById method would throw an exception if the release doesn't exist whereas this method returns null.
Would you be open to simply allowing the ReleaseNotFound exception to come out of this function and handling the exception at the caller level in your consuming code?
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.
Consistency is probably the right answer.
Personally I don't think an exception should be thrown unless something 'exceptional' happens.
I would consider not finding a release a part of normal processing rather than an exceptional set of circumstances.
The resulting code is also easier to work with
if ((release = getReleaseByTagname(xxx)) != null)
{
release.delete();
}
as apposed to
try
{
var release = getReleaseByTagName(xxxx);
release.delete();
}
on ReleaseNotFound catch(e)
{
/// no op
}
I will be guided by you as to which way you want it done.
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 I'd prefer the consistency with other methods and not return null. If someone did want to handle the case when a release is not found .. they wouldn't be able to. Here's what I was thinking it should look like:
Future<Release> getReleaseByTagName(
RepositorySlug slug, String tagName) async {
return github.getJSON(
'/repos/${slug.fullName}/releases/tags/$tagName',
convert: (i) => Release.fromJson(i),
statusCode: StatusCodes.OK,
fail: (http.Response response) {
if (response.statusCode == 404) {
throw ReleaseNotFound.fromTagName(github, tagName);
}
},
);
}
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.
OK, I have modified the code as requested. I will run a couple of tests and push the code.
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 with my review pass, back to you @bsutton
lib/src/common/repos_service.dart
Outdated
convert: (i) => Release.fromJson(i)); | ||
Future<Release> getReleaseByTagName( | ||
RepositorySlug slug, String tagName) async { | ||
// github.getJSON('/repos/${slug.fullName}/releases/tags/$tagName', convert: (i) => Release.fromJson(i)); |
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.
// github.getJSON('/repos/${slug.fullName}/releases/tags/$tagName', convert: (i) => Release.fromJson(i)); |
@robbecker-wf New PR with changes as requested. I still hate that it throws an exception ;) |
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.
LGTM. Are you ready for it to be merged?
Yes please
…On Wed, 16 Sep 2020, 5:24 am Rob Becker, ***@***.***> wrote:
***@***.**** approved this pull request.
LGTM. Are you ready for it to be merged?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#231 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG32OFVD2FA2MOJG5ESYITSF65OJANCNFSM4P6NSIIA>
.
|
thanks! |
Calls to createRelease were failing as the github api returns a 201 on a successful creation.
Added the required statusCode to the request and createRelease now completes as expected.