1
- const GitHubApi = require ( 'github' ) ;
2
- const Menu = require ( 'terminal-menu' ) ;
3
- const {
4
- execSync
5
- } = require ( 'child_process' ) ;
6
- const parse = require ( 'parse-github-repo-url' ) ;
1
+ const GitHubApi = require ( "github" ) ;
2
+ const Menu = require ( "terminal-menu" ) ;
3
+ const { execFileSync } = require ( "child_process" ) ;
4
+ const parse = require ( "parse-github-repo-url" ) ;
7
5
8
6
class Pullit {
9
7
constructor ( ) {
@@ -12,8 +10,8 @@ class Pullit {
12
10
}
13
11
14
12
init ( ) {
15
- const url = execSync ( ` git config --get remote.origin.url` , {
16
- encoding : ' utf8'
13
+ const url = execFileSync ( " git" , [ " config" , " --get" , " remote.origin.url" ] , {
14
+ encoding : " utf8"
17
15
} ) . trim ( ) ;
18
16
19
17
return this . parsedGithubUrl ( url ) ;
@@ -34,12 +32,11 @@ class Pullit {
34
32
} )
35
33
. then ( res => {
36
34
const branch = res . data . head . ref ;
37
- execSync (
38
- `git fetch origin pull/${ id } /head:${ branch } && git checkout ${ branch } `
39
- ) ;
35
+ execFileSync ( "git" , [ "fetch" , "origin" , `pull/${ id } /head:${ branch } ` ] ) ;
36
+ execFileSync ( "git" , [ "checkout" , branch ] ) ;
40
37
} )
41
38
. catch ( err => {
42
- console . log ( ' Error: Could not find the specified pull request.' ) ;
39
+ console . log ( " Error: Could not find the specified pull request." ) ;
43
40
} ) ;
44
41
}
45
42
@@ -51,36 +48,42 @@ class Pullit {
51
48
}
52
49
53
50
display ( ) {
54
- this . fetchRequests ( ) . then ( results => {
55
- const menu = Menu ( {
56
- width : process . stdout . columns - 4 ,
57
- x : 0 ,
58
- y : 2
59
- } ) ;
60
- menu . reset ( ) ;
61
- menu . write ( 'Currently open pull requests:\n' ) ;
62
- menu . write ( '-------------------------\n' ) ;
51
+ this . fetchRequests ( )
52
+ . then ( results => {
53
+ const menu = Menu ( {
54
+ width : process . stdout . columns - 4 ,
55
+ x : 0 ,
56
+ y : 2
57
+ } ) ;
58
+ menu . reset ( ) ;
59
+ menu . write ( "Currently open pull requests:\n" ) ;
60
+ menu . write ( "-------------------------\n" ) ;
63
61
64
- results . data . forEach ( element => {
65
- menu . add ( `${ element . number } - ${ element . title } - ${ element . head . user . login } ` ) ;
66
- } ) ;
62
+ results . data . forEach ( element => {
63
+ menu . add (
64
+ `${ element . number } - ${ element . title } - ${ element . head . user . login } `
65
+ ) ;
66
+ } ) ;
67
67
68
- menu . add ( `Exit` ) ;
68
+ menu . add ( `Exit` ) ;
69
69
70
- menu . on ( ' select' , label => {
71
- menu . close ( ) ;
72
- this . fetch ( label . split ( ' ' ) [ 0 ] ) ;
73
- } ) ;
74
- process . stdin . pipe ( menu . createStream ( ) ) . pipe ( process . stdout ) ;
70
+ menu . on ( " select" , label => {
71
+ menu . close ( ) ;
72
+ this . fetch ( label . split ( " " ) [ 0 ] ) ;
73
+ } ) ;
74
+ process . stdin . pipe ( menu . createStream ( ) ) . pipe ( process . stdout ) ;
75
75
76
- process . stdin . setRawMode ( true ) ;
77
- menu . on ( 'close' , ( ) => {
78
- process . stdin . setRawMode ( false ) ;
79
- process . stdin . end ( ) ;
76
+ process . stdin . setRawMode ( true ) ;
77
+ menu . on ( "close" , ( ) => {
78
+ process . stdin . setRawMode ( false ) ;
79
+ process . stdin . end ( ) ;
80
+ } ) ;
81
+ } )
82
+ . catch ( err => {
83
+ console . log (
84
+ "Error: could not display pull requests. Please make sure this is a valid repository."
85
+ ) ;
80
86
} ) ;
81
- } ) . catch ( err => {
82
- console . log ( 'Error: could not display pull requests. Please make sure this is a valid repository.' )
83
- } ) ;
84
87
}
85
88
}
86
89
0 commit comments