Skip to content

Commit af73df4

Browse files
Add support for creating draft PRs
1 parent 29cb49a commit af73df4

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

lib/src/common/model/pulls.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:github/src/common.dart';
22
import 'package:github/src/common/model/users.dart';
33
import 'package:json_annotation/json_annotation.dart';
4+
import 'package:meta/meta.dart';
45

56
part 'pulls.g.dart';
67

@@ -159,11 +160,20 @@ class PullRequestHead {
159160
/// Model class for a pull request to be created.
160161
@JsonSerializable(fieldRename: FieldRename.snake)
161162
class CreatePullRequest {
162-
CreatePullRequest(this.title, this.head, this.base, {this.body});
163+
CreatePullRequest(this.title, this.head, this.base,
164+
{this.draft = false, this.body});
163165

164166
final String title;
165167
final String head;
166168
final String base;
169+
170+
/// Whether a draft PR should be created.
171+
///
172+
/// This is currently experimental functionality since the way draft PRs are
173+
/// created through Github's REST API is in developer preview only - and could change at any time.
174+
@experimental
175+
final bool draft;
176+
167177
String body;
168178

169179
factory CreatePullRequest.fromJson(Map<String, dynamic> input) =>

lib/src/common/model/pulls.g.dart

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/common/pulls_service.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,14 @@ class PullRequestsService extends Service {
4949
///
5050
/// API docs: https://developer.github.com/v3/pulls/#create-a-pull-request
5151
Future<PullRequest> create(RepositorySlug slug, CreatePullRequest request) {
52-
return github.postJSON('/repos/${slug.fullName}/pulls',
53-
convert: (i) => PullRequest.fromJson(i), body: jsonEncode(request));
52+
return github.postJSON(
53+
'/repos/${slug.fullName}/pulls',
54+
convert: (i) => PullRequest.fromJson(i),
55+
body: jsonEncode(request),
56+
preview: request.draft
57+
? 'application/vnd.github.shadow-cat-preview+json'
58+
: null,
59+
);
5460
}
5561

5662
/// Edit a pull request.

0 commit comments

Comments
 (0)
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