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

Add the 'PushEvent' webhook and associated PushCommit object #386

Merged
merged 4 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 14 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 9.18.0

* Adds the initial `PushEvent` object in https://github.com/SpinlockLabs/github.dart/pull/386
* Update the `Repository` values `created_at` and `pushed_at` to handle integer times

## 9.17.0

* Add bearerToken constructor to Authentication class by @kevmoo in https://github.com/SpinlockLabs/github.dart/pull/381
Expand Down Expand Up @@ -307,7 +312,7 @@ Map<String, GistFile>? files;
- Clean up lints https://github.com/SpinlockLabs/github.dart/pull/202

## 6.0.5
- Fix null errors issue https://github.com/SpinlockLabs/github.dart/issues/199
- Fix null errors issue https://github.com/SpinlockLabs/github.dart/issues/199

## 6.0.4
- This fixes #196 (https://github.com/SpinlockLabs/github.dart/issues/196)
Expand Down Expand Up @@ -357,10 +362,10 @@ Map<String, GistFile>? files;

Deprecations:

- The `draft` and `prerelease` properties in the CreateRelease and Release
- The `draft` and `prerelease` properties in the CreateRelease and Release
- classes have been renamed to `isDraft` and `isPrerelease` for clarity.
- Release.targetCommitsh has been renamed to Release.targetCommitish.
- The `release` parameter in RepositoriesService.createRelease
- Release.targetCommitsh has been renamed to Release.targetCommitish.
- The `release` parameter in RepositoriesService.createRelease
has been renamed to `createRelease`.
- `RepositoriesService.getRelease` has been renamed to `RepositoriesService.getReleaseById`

Expand All @@ -369,7 +374,7 @@ has been renamed to `createRelease`.
- Add access to labels on Pull Requests https://github.com/SpinlockLabs/github.dart/pull/163
- Adding draft property to PR model https://github.com/SpinlockLabs/github.dart/pull/162
- updateFile request must be a PUT https://github.com/SpinlockLabs/github.dart/pull/160

## v5.1.0

- `Repository`: added `updatedAt` and `license` fields.
Expand All @@ -386,7 +391,7 @@ has been renamed to `createRelease`.

## v5.0.0

- **BREAKING** `RepositoriesService.listCollaborators` now returns
- **BREAKING** `RepositoriesService.listCollaborators` now returns
`Stream<Collaborator>` instead of `Stream<User>`.
- `Collaborator` is a new type that includes collaborator-specific
information.
Expand All @@ -403,7 +408,7 @@ has been renamed to `createRelease`.
- Removed unsupported `limit` parameter.
- Removed flaky retry logic. Instead, `NotReady` is thrown, which can be used
to decide to retry at the call site.
- Made associated classes `ContributorStatistics` and
- Made associated classes `ContributorStatistics` and
`ContributorWeekStatistics` immutable. Since these classes are only meant as
return values, we're not treating this as a breaking change.
- Added `Stream<CodeSearchResults> github.search.code(...)` search API
Expand Down Expand Up @@ -433,7 +438,7 @@ has been renamed to `createRelease`.

## v2.3.2

- Automatically attempt to find GitHub user information in the process environment when running on the standalone VM.
- Automatically attempt to find GitHub user information in the process environment when running on the standalone VM.
- Add `ref` parameter to `getReadme` method for the repository service.

## v2.3.1
Expand All @@ -447,7 +452,7 @@ has been renamed to `createRelease`.
- Moved `CHANGELOG` content back to repo.
- Added `rateLimitLimit`, `rateLimitRemaining` and `rateLimitReset` to `GitHub`.
- Added `id` to `Issue`
- Added `direction`, `sort` and `since` optional arguments to
- Added `direction`, `sort` and `since` optional arguments to
`IssueService.listByRepo`.

## v2.1.0
Expand Down
22 changes: 22 additions & 0 deletions lib/src/common/model/git.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ class CreateGitCommit {
Map<String, dynamic> toJson() => _$CreateGitCommitToJson(this);
}

/// Model class for a pushed commit.
@JsonSerializable()
class PushGitCommit {
PushGitCommit(this.id, this.message, this.timestamp, this.url);

/// The commit hash.
String? id;

/// The commit message.
String? message;

/// The timestamp of the commit.
DateTime? timestamp;

/// The direct url to the commit.
String? url;

factory PushGitCommit.fromJson(Map<String, dynamic> input) =>
_$PushGitCommitFromJson(input);
Map<String, dynamic> toJson() => _$PushGitCommitToJson(this);
}

/// Model class for an author or committer of a commit. The [GitCommitUser] may
/// not correspond to a GitHub [User].
@JsonSerializable(includeIfNull: false)
Expand Down
18 changes: 18 additions & 0 deletions lib/src/common/model/git.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions lib/src/common/model/repos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,11 @@ class Repository {
int networkCount;

/// The time the repository was created at
@JsonKey(fromJson: Repository.dynamicToDateTime)
DateTime? createdAt;

/// The last time the repository was pushed at
@JsonKey(fromJson: Repository.dynamicToDateTime)
DateTime? pushedAt;

DateTime? updatedAt;
Expand Down Expand Up @@ -459,6 +461,18 @@ class Repository {

@override
String toString() => 'Repository: $owner/$name';

/// In some cases, github webhooks send time values as an integer. This method
/// is added to handle those cases, but otherwise parse like normal.
static DateTime? dynamicToDateTime(dynamic time) {
if (time == null) {
return null;
}
if (time.runtimeType == int) {
drewroengoogle marked this conversation as resolved.
Show resolved Hide resolved
return DateTime.fromMillisecondsSinceEpoch(time * 1000);
}
return DateTime.parse(time as String);
}
}

/// Model class for repository permissions.
Expand Down
8 changes: 2 additions & 6 deletions lib/src/common/model/repos.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions lib/src/server/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,40 @@ class CreateEvent extends HookEvent {

Map<String, dynamic> toJson() => _$CreateEventToJson(this);
}

@JsonSerializable(fieldRename: FieldRename.snake)
class PushEvent extends HookEvent {
PushEvent({
this.ref,
this.before,
this.after,
this.repository,
this.headCommit,
this.commits,
this.sender,
});

factory PushEvent.fromJson(Map<String, dynamic> input) =>
_$PushEventFromJson(input);
String? ref;
String? before;
String? after;
@JsonKey(toJson: handleIntegerTimes)
Repository? repository;
PushGitCommit? headCommit;
List<PushGitCommit>? commits;
User? sender;

Map<String, dynamic> toJson() => _$PushEventToJson(this);

static Map<String, dynamic>? handleIntegerTimes(Repository? repository) {
var repositoryMap = repository?.toJson();
for (final parameter in ['created_at', 'pushed_at']) {
if (repositoryMap?[parameter] != null) {
final createdAt = DateTime.parse(repositoryMap?[parameter]);
repositoryMap?[parameter] = createdAt.millisecondsSinceEpoch ~/ 1000;
}
}
return repositoryMap;
}
}
28 changes: 28 additions & 0 deletions lib/src/server/hooks.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.