@@ -17,77 +17,42 @@ const builder = yargs => {
17
17
const baseOptions = flow ( [
18
18
commonYargs . withToken ,
19
19
commonYargs . withJson ,
20
- commonYargs . withBase ,
21
- commonYargs . withOwner ,
22
- commonYargs . withRepo ,
23
- commonYargs . withNumber ,
24
- ] )
20
+ commonYargs . withPullRequest ,
21
+ ] ) ;
22
+
25
23
return baseOptions ( yargs )
26
- . option ( "commit_title" , {
27
- alias : "t" ,
28
- describe : "Pull request commit title" ,
29
- type : "string"
30
- } )
31
- . option ( "commit_message" , {
32
- alias : "m" ,
33
- describe : "Pull request commit message" ,
34
- type : "string"
35
- } )
36
- . option ( "sha" , {
37
- describe : "SHA that the pull request head must match to allow merge" ,
38
- type : "string"
39
- } )
40
- . option ( "merge_method" , {
41
- describe : "Merge method to use. Possible values are merge, squash or rebase. Default is merge." ,
42
- type : "string"
43
- } )
24
+ . option ( "method" , {
25
+ describe : "Merge method to use." ,
26
+ choices : [ "merge" , "squash" , "rebase" ] ,
27
+ default : "merge"
28
+ } ) ;
44
29
}
45
30
46
31
/**
47
32
* Return the contents of a pull request body and create a pull request.
48
33
*
49
34
* @param {object } argv - argv parsed and filtered by yargs
50
- * @param {string } argv.token
51
- * @param {string } argv.json
52
- * @param {string } argv.owner
53
- * @param {string } argv.repo
54
- * @param {string } argv.number
55
- * @param {string } [argv.commit_title]
56
- * @param {string } [argv.commit_message]
57
- * @param {string } [argv.sha]
58
- * @param {string } [argv.merge_method]
59
35
* @throws {Error } - Throws an error if any required properties are invalid
60
36
*/
61
- const handler = async ( { token, json, owner, repo, number, commit_title, commit_message, sha, merge_method } ) => {
37
+ const handler = async ( argv ) => {
38
+ try {
39
+ const octokit = await authenticatedOctokit ( { personalAccessToken : argv . token } ) ;
62
40
63
- // Ensure that all required properties have values
64
- const requiredProperties = {
65
- owner,
66
- repo,
67
- number,
68
- }
69
- if ( Object . values ( requiredProperties ) . some ( property => ! property ) ) {
70
- throw new Error ( `Please provide all required properties: ${ Object . keys ( requiredProperties ) . join ( ", " ) } ` )
71
- }
41
+ const result = await octokit . pulls . merge ( {
42
+ owner : argv . pullRequest . owner ,
43
+ repo : argv . pullRequest . repo ,
44
+ pull_number : argv . pullRequest . number ,
45
+ merge_method : argv . method ,
46
+ } ) ;
72
47
73
- const inputs = Object . assign ( { } , requiredProperties , {
74
- commit_title,
75
- commit_message,
76
- sha,
77
- merge_method,
78
- } )
79
- try {
80
- const octokit = await authenticatedOctokit ( { personalAccessToken : token } )
81
- const result = await octokit . pulls . merge ( inputs )
82
- printOutput ( { json, resource : result } )
83
- }
84
- catch ( error ) {
85
- throw new Error ( error )
48
+ printOutput ( { json : argv . json , resource : result } ) ;
49
+ } catch ( error ) {
50
+ throw new Error ( error ) ;
86
51
}
87
52
}
88
53
89
54
module . exports = {
90
- command : "merge" ,
55
+ command : "merge <pull-request> " ,
91
56
desc : "Merge an existing pull request" ,
92
57
builder,
93
58
handler
0 commit comments