@@ -9,6 +9,67 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => {
99 return Settings . sync ( context . octokit , repo , config )
1010 }
1111
12+ async function triggerRepositoryUpdate ( _context , { owner, repo } ) {
13+ /* Clone context without reference */
14+ const context = Object . assign ( Object . create ( Object . getPrototypeOf ( _context ) ) , _context )
15+
16+ /* Change context to target repository */
17+ const { repository } = context . payload
18+ context . payload . repository = Object . assign ( repository || { } , {
19+ owner : {
20+ login : owner
21+ } ,
22+ name : repo
23+ } )
24+
25+ return syncSettings ( context , { owner, repo } )
26+ }
27+
28+ robot . on ( [
29+ 'installation.created' ,
30+ 'installation.new_permissions_accepted'
31+ ] , async context => {
32+ const { payload } = context
33+ const { repositories, installation } = payload
34+ const { account } = installation
35+ const { login : repositoryOwner } = account
36+
37+ if ( ! repositories ) {
38+ robot . log . debug ( 'No new repositories found in the installation event, returning...' )
39+ return
40+ }
41+
42+ await Promise . all ( repositories . map ( async ( repository ) => {
43+ const { name : repositoryName } = repository
44+
45+ return triggerRepositoryUpdate ( context , {
46+ owner : repositoryOwner ,
47+ repo : repositoryName
48+ } )
49+ } ) )
50+ } )
51+
52+ robot . on ( 'installation_repositories.added' , async context => {
53+ const { payload } = context
54+ const { repositories_added : repositories , installation } = payload
55+ const { account } = installation
56+ const { login : repositoryOwner } = account
57+
58+ if ( ! repositories ) {
59+ robot . log . debug ( 'No new repositories found in the installation event, returning...' )
60+ return
61+ }
62+
63+ await Promise . all ( repositories . map ( async ( repository ) => {
64+ const { name : repositoryName } = repository
65+
66+ return triggerRepositoryUpdate ( context , {
67+ owner : repositoryOwner ,
68+ repo : repositoryName
69+ } )
70+ } ) )
71+ } )
72+
1273 robot . on ( 'push' , async context => {
1374 const { payload } = context
1475 const { repository } = payload
0 commit comments