@@ -36,24 +36,29 @@ async function main() {
3636 return ;
3737 }
3838
39+ const [ owner , repo ] = process . env . GITHUB_REPOSITORY . split ( "/" ) ;
40+
3941 try {
4042 const inputs = {
4143 title : core . getInput ( "title" ) ,
4244 body : core . getInput ( "body" ) ,
4345 branch : core . getInput ( "branch" ) . replace ( / ^ r e f s \/ h e a d s \/ / , "" ) ,
4446 path : core . getInput ( "path" ) ,
4547 commitMessage : core . getInput ( "commit-message" ) ,
46- author : core . getInput ( "author" )
48+ author : core . getInput ( "author" ) ,
49+ labels : core . getInput ( "labels" ) ,
4750 } ;
4851
4952 core . debug ( `Inputs: ${ inspect ( inputs ) } ` ) ;
5053
5154 const {
52- data : { default_branch }
53- } = await request ( `GET /repos/${ process . env . GITHUB_REPOSITORY } ` , {
55+ data : { default_branch } ,
56+ } = await request ( `GET /repos/{owner}/{repo }` , {
5457 headers : {
55- authorization : `token ${ process . env . GITHUB_TOKEN } `
56- }
58+ authorization : `token ${ process . env . GITHUB_TOKEN } ` ,
59+ } ,
60+ owner,
61+ repo,
5762 } ) ;
5863 const DEFAULT_BRANCH = default_branch ;
5964 core . debug ( `DEFAULT_BRANCH: ${ DEFAULT_BRANCH } ` ) ;
@@ -86,7 +91,7 @@ async function main() {
8691
8792 await setGitUser ( {
8893 name,
89- email
94+ email,
9095 } ) ;
9196 }
9297
@@ -128,7 +133,7 @@ async function main() {
128133 if ( remoteBranchExists ) {
129134 const q = `head:${ inputs . branch } type:pr is:open repo:${ process . env . GITHUB_REPOSITORY } ` ;
130135 const { data } = await request ( "GET /search/issues" , {
131- q
136+ q,
132137 } ) ;
133138
134139 if ( data . total_count > 0 ) {
@@ -141,21 +146,43 @@ async function main() {
141146
142147 core . debug ( `Creating pull request` ) ;
143148 const {
144- data : { html_url }
145- } = await request ( `POST /repos/${ process . env . GITHUB_REPOSITORY } /pulls` , {
149+ data : { html_url, number } ,
150+ } = await request ( `POST /repos/{owner}/{repo }/pulls` , {
146151 headers : {
147- authorization : `token ${ process . env . GITHUB_TOKEN } `
152+ authorization : `token ${ process . env . GITHUB_TOKEN } ` ,
148153 } ,
154+ owner,
155+ repo,
149156 title : inputs . title ,
150157 body : inputs . body ,
151158 head : inputs . branch ,
152- base : DEFAULT_BRANCH
159+ base : DEFAULT_BRANCH ,
153160 } ) ;
154161
155- core . info ( `Pull request created: ${ html_url } ` ) ;
162+ core . info ( `Pull request created: ${ html_url } (#${ number } )` ) ;
163+
164+ if ( inputs . labels ) {
165+ core . debug ( `Adding labels: ${ inputs . labels } ` ) ;
166+ const labels = inputs . labels . trim ( ) . split ( / \s * , \s * / ) ;
167+ const { data } = await request (
168+ `POST /repos/{owner}/{repo}/issues/{issue_number}/labels` ,
169+ {
170+ headers : {
171+ authorization : `token ${ process . env . GITHUB_TOKEN } ` ,
172+ } ,
173+ owner,
174+ repo,
175+ issue_number : number ,
176+ labels,
177+ }
178+ ) ;
179+ core . info ( `Labels added: ${ labels . join ( ", " ) } ` ) ;
180+ core . debug ( inspect ( data ) ) ;
181+ }
182+
156183 await runShellCommand ( `git stash pop || true` ) ;
157184 } catch ( error ) {
158- core . debug ( inspect ( error ) ) ;
185+ core . info ( inspect ( error ) ) ;
159186 core . setFailed ( error . message ) ;
160187 }
161188}
@@ -173,7 +200,7 @@ async function getLocalChanges(path) {
173200
174201 return {
175202 hasUncommitedChanges,
176- hasChanges : hasUncommitedChanges
203+ hasChanges : hasUncommitedChanges ,
177204 } ;
178205}
179206
@@ -184,7 +211,7 @@ async function getGitUser() {
184211
185212 return {
186213 name,
187- email
214+ email,
188215 } ;
189216 } catch ( error ) {
190217 return ;
0 commit comments