Skip to content

Add a Changes object to the PullRequestEvent object so we can see what changed in edited PR events #390

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions lib/src/common/model/changes.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';

part 'changes.g.dart';

@immutable
@JsonSerializable()
class Ref {
const Ref(this.from);
final String? from;

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

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

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

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

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

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

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

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

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

@immutable
@JsonSerializable()
class Changes {
const Changes(this.base, this.body, this.title);
final Base? base;
final Body? body;
final 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.

5 changes: 5 additions & 0 deletions lib/src/server/hooks.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:json_annotation/json_annotation.dart';

import '../common.dart';
import '../common/model/changes.dart';

part 'hooks.g.dart';

Expand Down Expand Up @@ -203,12 +206,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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy