Skip to content

Commit 53de5fa

Browse files
committed
Add release command
1 parent ca8b740 commit 53de5fa

File tree

3 files changed

+424
-3
lines changed

3 files changed

+424
-3
lines changed

.maintenance/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
WP_CLI::add_command( 'maintenance contrib-list', 'WP_CLI\Maintenance\Contrib_list_Command' );
1010
WP_CLI::add_command( 'maintenance milestones-after', 'WP_CLI\Maintenance\Milestones_After_Command' );
1111
WP_CLI::add_command( 'maintenance milestones-since', 'WP_CLI\Maintenance\Milestones_Since_Command' );
12+
WP_CLI::add_command( 'maintenance release', 'WP_CLI\Maintenance\Release_Command' );
1213
WP_CLI::add_command( 'maintenance release-date', 'WP_CLI\Maintenance\Release_Date_Command' );
1314
WP_CLI::add_command( 'maintenance release-notes', 'WP_CLI\Maintenance\Release_Notes_Command' );
1415
WP_CLI::add_command( 'maintenance replace-label', 'WP_CLI\Maintenance\Replace_Label_Command' );

.maintenance/src/GitHub.php

Lines changed: 144 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,70 @@ public static function get_project_milestones(
3030
return $body;
3131
}
3232

33+
/**
34+
* Gets the releases for a given project.
35+
*
36+
* @param string $project
37+
*
38+
* @return array
39+
*/
40+
public static function get_project_releases(
41+
$project,
42+
$args = array()
43+
) {
44+
$request_url = sprintf(
45+
self::API_ROOT . 'repos/%s/releases',
46+
$project
47+
);
48+
49+
$args['per_page'] = 100;
50+
51+
list( $body, $headers ) = self::request( $request_url, $args );
52+
53+
return $body;
54+
}
55+
56+
/**
57+
* Gets the releases for a given project.
58+
*
59+
* @param string $project
60+
*
61+
* @return array
62+
*/
63+
public static function create_release(
64+
$project,
65+
$tag_name,
66+
$target_commitish,
67+
$name,
68+
$body,
69+
$draft = false,
70+
$prerelease = false,
71+
$args = []
72+
) {
73+
$request_url = sprintf(
74+
self::API_ROOT . 'repos/%s/releases',
75+
$project
76+
);
77+
78+
$args = array_merge(
79+
$args,
80+
[
81+
'tag_name' => (string) $tag_name,
82+
'target_commitish' => (string) $target_commitish,
83+
'name' => (string) $name,
84+
'body' => (string) $body,
85+
'draft' => (bool) $draft,
86+
'prerelease' => (bool) $prerelease,
87+
]
88+
);
89+
90+
$headers['http_verb'] = 'POST';
91+
92+
list( $body, $headers ) = self::request( $request_url, $args, $headers );
93+
94+
return $body;
95+
}
96+
3397
/**
3498
* Gets a release for a given project by its tag name.
3599
*
@@ -115,6 +179,35 @@ public static function remove_label(
115179
return $body;
116180
}
117181

182+
/**
183+
* Close a milestone.
184+
*
185+
* @param string $project
186+
* @param string $milestone
187+
*
188+
* @return array|false
189+
*/
190+
public static function close_milestone(
191+
$project,
192+
$milestone
193+
) {
194+
$request_url = sprintf(
195+
self::API_ROOT . 'repos/%s/milestones/%s',
196+
$project,
197+
$milestone
198+
);
199+
200+
$headers['http_verb'] = 'PATCH';
201+
202+
$args = [
203+
'state' => 'closed',
204+
];
205+
206+
list( $body, $headers ) = self::request( $request_url, $args, $headers );
207+
208+
return $body;
209+
}
210+
118211
/**
119212
* Adds a label to an issue.
120213
*
@@ -168,8 +261,6 @@ public static function delete_label(
168261
$label
169262
);
170263

171-
$headers['http_verb'] = 'DELETE';
172-
173264
list( $body, $headers ) = self::request( $request_url, $args, $headers );
174265

175266
return $body;
@@ -244,6 +335,56 @@ public static function parse_contributors_from_pull_requests(
244335
return $contributors;
245336
}
246337

338+
/**
339+
* Get latest release.
340+
*
341+
* @param string $project
342+
*
343+
* @return string
344+
*/
345+
public static function get_latest_release( $project ) {
346+
$request_url = sprintf(
347+
self::API_ROOT . 'repos/%s/releases/latest',
348+
$project
349+
);
350+
351+
$args = array(
352+
'per_page' => 100,
353+
'state' => 'all',
354+
);
355+
356+
list( $body, $headers ) = self::request( $request_url, $args );
357+
358+
return $body;
359+
}
360+
361+
/**
362+
* Get issues/PRs.
363+
*
364+
* @param string $project
365+
* @param array $args
366+
*
367+
* @return string
368+
*/
369+
public static function get_issues( $project, $args = [] ) {
370+
$request_url = sprintf(
371+
self::API_ROOT . 'repos/%s/issues',
372+
$project
373+
);
374+
375+
$args = array_merge(
376+
[
377+
'per_page' => 100,
378+
'state' => 'all',
379+
],
380+
$args
381+
);
382+
383+
list( $body, $headers ) = self::request( $request_url, $args );
384+
385+
return $body;
386+
}
387+
247388
/**
248389
* Makes a request to the GitHub API.
249390
*
@@ -275,7 +416,7 @@ public static function request(
275416
unset( $headers['http_verb'] );
276417
}
277418

278-
if ( 'POST' === $verb ) {
419+
if ( 'POST' === $verb || 'PATCH' === $verb ) {
279420
$args = json_encode( $args );
280421
}
281422

0 commit comments

Comments
 (0)