Skip to content

Commit 95db107

Browse files
authored
Allow branch protection to be applied on default branch creation on new repository (#536)
1 parent f0466d7 commit 95db107

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,23 @@ module.exports = (robot, _, Settings = require('./lib/settings')) => {
254254
robot.log.debug(`No changes in '${Settings.FILE_NAME}' detected, returning...`)
255255
})
256256

257+
robot.on('create', async context => {
258+
const { payload } = context
259+
const { sender } = payload
260+
robot.log.debug('Branch Creation by ', JSON.stringify(sender))
261+
if (sender.type === 'Bot') {
262+
robot.log.debug('Branch Creation by Bot')
263+
return
264+
}
265+
robot.log.debug('Branch Creation by a Human')
266+
if(payload.repository.default_branch !== payload.ref) {
267+
robot.log.debug('Not default Branch')
268+
return
269+
}
270+
271+
return syncSettings(false, context)
272+
})
273+
257274
robot.on('branch_protection_rule', async context => {
258275
const { payload } = context
259276
const { sender } = payload

0 commit comments

Comments
 (0)