Skip to content
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

Merged
merged 7 commits into from
Sep 15, 2020
Merged

Conversation

bsutton
Copy link
Contributor

@bsutton bsutton commented Aug 13, 2020

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.

@bsutton
Copy link
Contributor Author

bsutton commented Aug 24, 2020

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.

@bsutton
Copy link
Contributor Author

bsutton commented Aug 25, 2020

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

@bsutton
Copy link
Contributor Author

bsutton commented Sep 3, 2020

ping @robbecker-wf

@robrbecker
Copy link
Member

Thanks for putting up this PR. I'll give it a review and some testing here soon.

@bsutton
Copy link
Contributor Author

bsutton commented Sep 3, 2020 via email

'/repos/${slug.fullName}/releases',
convert: (i) => Release.fromJson(i),
body: GitHubJson.encode(createRelease.toJson()),
statusCode: StatusCodes.CREATED);
Copy link
Member

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');
}
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

},
);
} on ReleaseNotFound catch (e) {
release = null;
Copy link
Member

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?

Copy link
Contributor Author

@bsutton bsutton Sep 9, 2020

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.

Copy link
Member

@robrbecker robrbecker Sep 15, 2020

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);
        }
      },
    );
  }

Copy link
Contributor Author

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.

Copy link
Member

@robrbecker robrbecker left a 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

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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// github.getJSON('/repos/${slug.fullName}/releases/tags/$tagName', convert: (i) => Release.fromJson(i));

@bsutton
Copy link
Contributor Author

bsutton commented Sep 15, 2020

@robbecker-wf New PR with changes as requested.

I still hate that it throws an exception ;)

Copy link
Member

@robrbecker robrbecker left a 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?

@bsutton
Copy link
Contributor Author

bsutton commented Sep 15, 2020 via email

@robrbecker robrbecker merged commit b285bd2 into SpinlockLabs:master Sep 15, 2020
@bsutton
Copy link
Contributor Author

bsutton commented Sep 15, 2020

thanks!

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