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 a Changes object to the PullRequestEvent object so we can see what changed in edited PR events #390

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions lib/src/common/model/changes.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:json_annotation/json_annotation.dart';

part 'changes.g.dart';

@JsonSerializable()
class Ref {
Ref(this.from);
ricardoamador marked this conversation as resolved.
Show resolved Hide resolved
String? from;

factory Ref.fromJson(Map<String, dynamic> input) => _$RefFromJson(input);
Map<String, dynamic> toJson() => _$RefToJson(this);
}

@JsonSerializable()
class Sha {
Sha(this.from);
String? from;

factory Sha.fromJson(Map<String, dynamic> input) => _$ShaFromJson(input);
Map<String, dynamic> toJson() => _$ShaToJson(this);
}

@JsonSerializable()
class Base {
Base(this.ref, this.sha);
Ref? ref;
Sha? sha;

factory Base.fromJson(Map<String, dynamic> input) => _$BaseFromJson(input);
Map<String, dynamic> toJson() => _$BaseToJson(this);
}

@JsonSerializable()
class Body {
Body(this.from);
String? from;

factory Body.fromJson(Map<String, dynamic> input) => _$BodyFromJson(input);
Map<String, dynamic> toJson() => _$BodyToJson(this);
}

@JsonSerializable()
class Title {
Title({this.from});
String? from;

factory Title.fromJson(Map<String, dynamic> input) => _$TitleFromJson(input);
Map<String, dynamic> toJson() => _$TitleToJson(this);
}

@JsonSerializable()
class Changes {
Changes(this.base, this.body, this.title);
Base? base;
Body? body;
Title? title;

factory Changes.fromJson(Map<String, dynamic> input) =>
_$ChangesFromJson(input);
Map<String, dynamic> toJson() => _$ChangesToJson(this);
}
71 changes: 71 additions & 0 deletions lib/src/common/model/changes.g.dart

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

3 changes: 3 additions & 0 deletions lib/src/server/hooks.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:github/src/common/model/changes.dart';
ricardoamador marked this conversation as resolved.
Show resolved Hide resolved
import 'package:json_annotation/json_annotation.dart';
import '../common.dart';

Expand Down Expand Up @@ -203,12 +204,14 @@ class PullRequestEvent extends HookEvent {
this.pullRequest,
this.sender,
this.repository,
this.changes,
});
String? action;
int? number;
PullRequest? pullRequest;
User? sender;
Repository? repository;
Changes? changes;

factory PullRequestEvent.fromJson(Map<String, dynamic> input) =>
_$PullRequestEventFromJson(input);
Expand Down
4 changes: 4 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.

25 changes: 25 additions & 0 deletions test/server/hooks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,29 @@ void main() {
expect(sender.htmlUrl, "https://github.com/Codertocat");
});
});

group('EditedPullRequest', () {
test('deserialize with body edit', () {
final pullRequestEditedEvent = PullRequestEvent.fromJson(
jsonDecode(prBodyEditedEvent) as Map<String, dynamic>);
final changes = pullRequestEditedEvent.changes;
expect(changes, isNotNull);
expect(changes!.body!.from, isNotNull);
assert(changes.body!.from ==
'**This should not land until https://github.com/flutter/buildroot/pull/790');
});

test('deserialize with base edit', () {
final pullRequestEditedEvent = PullRequestEvent.fromJson(
jsonDecode(prBaseEditedEvent) as Map<String, dynamic>);
final changes = pullRequestEditedEvent.changes;
expect(changes, isNotNull);
expect(changes!.body, isNull);
expect(changes.base, isNotNull);
expect(changes.base!.ref, isNotNull);
assert(changes.base!.ref!.from == 'main');
assert(changes.base!.sha!.from ==
'b3af5d64d3e6e2110b07d71909fc432537339659');
});
});
}
Loading