Skip to content

Commit b285bd2

Browse files
authored
Merge pull request #231 from bsutton/master
Added the required status code StatusCodes.CREATED for the createRele…
2 parents 3c88457 + 6caf3ed commit b285bd2

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

lib/src/common/model/repos.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ class RepositorySlug {
274274
/// Repository Name
275275
String name;
276276

277-
RepositorySlug(this.owner, this.name);
277+
RepositorySlug(this.owner, this.name) {
278+
ArgumentError.checkNotNull(owner, 'owner');
279+
ArgumentError.checkNotNull(name, 'name');
280+
}
278281

279282
/// Creates a Repository Slug from a full name.
280283
factory RepositorySlug.full(String f) {

lib/src/common/model/repos_releases.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Release {
9696
String getUploadUrlFor(String name, [String label]) =>
9797
"${uploadUrl.substring(0, uploadUrl.indexOf('{'))}?name=$name${label != null ? ",$label" : ""}";
9898

99-
bool get hasErrors => errors?.isNotEmpty;
99+
bool get hasErrors => errors == null ? false : errors.isNotEmpty;
100100
}
101101

102102
/// Model class for a release asset.

lib/src/common/repos_service.dart

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -968,10 +968,23 @@ class RepositoriesService extends Service {
968968

969969
/// Fetches a single release by the release tag name.
970970
///
971+
/// Throws a [ReleaseNotFound] exception if the release
972+
/// doesn't exist.
973+
///
971974
/// API docs: https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name
972-
Future<Release> getReleaseByTagName(RepositorySlug slug, String tagName) =>
973-
github.getJSON('/repos/${slug.fullName}/releases/tags/$tagName',
974-
convert: (i) => Release.fromJson(i));
975+
Future<Release> getReleaseByTagName(
976+
RepositorySlug slug, String tagName) async {
977+
return github.getJSON(
978+
'/repos/${slug.fullName}/releases/tags/$tagName',
979+
convert: (i) => Release.fromJson(i),
980+
statusCode: StatusCodes.OK,
981+
fail: (http.Response response) {
982+
if (response.statusCode == 404) {
983+
throw ReleaseNotFound.fromTagName(github, tagName);
984+
}
985+
},
986+
);
987+
}
975988

976989
/// Creates a Release based on the specified [createRelease].
977990
///
@@ -986,10 +999,10 @@ class RepositoriesService extends Service {
986999
ArgumentError.checkNotNull(slug);
9871000
ArgumentError.checkNotNull(createRelease);
9881001
final release = await github.postJSON<Map<String, dynamic>, Release>(
989-
'/repos/${slug.fullName}/releases',
990-
convert: (i) => Release.fromJson(i),
991-
body: GitHubJson.encode(createRelease.toJson()),
992-
);
1002+
'/repos/${slug.fullName}/releases',
1003+
convert: (i) => Release.fromJson(i),
1004+
body: GitHubJson.encode(createRelease.toJson()),
1005+
statusCode: StatusCodes.CREATED);
9931006
if (release.hasErrors) {
9941007
final alreadyExistsErrorCode = release.errors.firstWhere(
9951008
(error) => error['code'] == 'already_exists',

lib/src/common/util/errors.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ class RepositoryNotFound extends NotFound {
4141
: super(github, 'Repository Not Found: $repo');
4242
}
4343

44+
/// Release not found
45+
class ReleaseNotFound extends NotFound {
46+
const ReleaseNotFound.fromTagName(GitHub github, String tagName)
47+
: super(github, 'Release for tagName $tagName Not Found.');
48+
}
49+
4450
/// GitHub User was not found
4551
class UserNotFound extends NotFound {
4652
const UserNotFound(GitHub github, String user)

0 commit comments

Comments
 (0)