@@ -33,20 +33,29 @@ describe("logName", () => {
3333
3434describe ( "githubInputs" , ( ) => {
3535 const OLD_ENV = { ...process . env } ;
36+ const { context : OLD_CONTEXT } = require ( "@actions/github" ) ;
37+ const { payload : OLD_PAYLOAD , eventName : OLD_EVENT_NAME } = OLD_CONTEXT ;
3638 afterEach ( ( ) => {
3739 process . env = { ...OLD_ENV } ;
40+ const { context } = require ( "@actions/github" ) ;
41+ context . eventName = OLD_EVENT_NAME ;
42+ context . payload = OLD_PAYLOAD ;
3843 } ) ;
3944
4045 const projectName = "project_name" ;
4146 const repoInfo = "owner/repo" ;
4247 const sha = "1234abcd-12ab-34cd-56ef-1234567890ab" ;
48+ const pullRequestSha = "181600acb3cfb803f4570d0018928be5d730c00d" ;
4349
4450 it ( "build basic parameters for codeBuild.startBuild" , ( ) => {
4551 // This is how GITHUB injects its input values.
4652 // It would be nice if there was an easy way to test this...
4753 process . env [ `INPUT_PROJECT-NAME` ] = projectName ;
4854 process . env [ `GITHUB_REPOSITORY` ] = repoInfo ;
4955 process . env [ `GITHUB_SHA` ] = sha ;
56+ // These tests run in pull requests
57+ // so to tests things that are NOT pull request...
58+ process . env [ `GITHUB_EVENT_NAME` ] = "not_pull_request" ;
5059 const test = githubInputs ( ) ;
5160 expect ( test ) . to . haveOwnProperty ( "projectName" ) . and . to . equal ( projectName ) ;
5261 expect ( test ) . to . haveOwnProperty ( "sourceVersion" ) . and . to . equal ( sha ) ;
@@ -84,6 +93,44 @@ describe("githubInputs", () => {
8493 . to . haveOwnProperty ( "envPassthrough" )
8594 . and . to . deep . equal ( [ "one" , "two" , "three" , "four" ] ) ;
8695 } ) ;
96+
97+ it ( "can handle pull requests" , ( ) => {
98+ // This is how GITHUB injects its input values.
99+ // It would be nice if there was an easy way to test this...
100+ process . env [ `INPUT_PROJECT-NAME` ] = projectName ;
101+ process . env [ `GITHUB_REPOSITORY` ] = repoInfo ;
102+ process . env [ `GITHUB_SHA` ] = sha ;
103+ process . env [ `GITHUB_EVENT_NAME` ] = "pull_request" ;
104+ const { context } = require ( "@actions/github" ) ;
105+ context . payload = { pull_request : { head : { sha : pullRequestSha } } } ;
106+ const test = githubInputs ( ) ;
107+ expect ( test ) . to . haveOwnProperty ( "projectName" ) . and . to . equal ( projectName ) ;
108+ expect ( test )
109+ . to . haveOwnProperty ( "sourceVersion" )
110+ . and . to . equal ( pullRequestSha ) ;
111+ expect ( test ) . to . haveOwnProperty ( "owner" ) . and . to . equal ( `owner` ) ;
112+ expect ( test ) . to . haveOwnProperty ( "repo" ) . and . to . equal ( `repo` ) ;
113+ expect ( test )
114+ . to . haveOwnProperty ( "buildspecOverride" )
115+ . and . to . equal ( undefined ) ;
116+ expect ( test ) . to . haveOwnProperty ( "envPassthrough" ) . and . to . deep . equal ( [ ] ) ;
117+ } ) ;
118+
119+ it ( "will not continue if there is no payload" , ( ) => {
120+ // This is how GITHUB injects its input values.
121+ // It would be nice if there was an easy way to test this...
122+ process . env [ `INPUT_PROJECT-NAME` ] = projectName ;
123+ process . env [ `GITHUB_REPOSITORY` ] = repoInfo ;
124+ process . env [ `GITHUB_SHA` ] = sha ;
125+ process . env [ `GITHUB_EVENT_NAME` ] = "pull_request" ;
126+ // These tests run in pull requests
127+ // so to tests things that are NOT pull request...
128+ require ( "@actions/github" ) . context . payload = { } ;
129+
130+ expect ( ( ) => githubInputs ( ) ) . to . throw (
131+ "No source version could be evaluated."
132+ ) ;
133+ } ) ;
87134} ) ;
88135
89136describe ( "inputs2Parameters" , ( ) => {
0 commit comments