Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ The App listens to the following webhook events:

- **repository.created**: If a repository is created in the org, the settings for the repo - the default settings for the org, overlaid with settings for the suborg that the repo belongs to, overlaid with the settings for that specific repo - is applied.

- **repository.transferred**: If a repository is transferred into the org from another org or user account, the settings for the repo are applied the same way as for **repository.created**.

- **branch_protection_rule**: If a branch protection rule is modified or deleted, `safe-settings` will `sync` the settings to prevent any unauthorized changes.

- **repository.edited**: For e.g. If the default branch is renamed, or if topics change, `safe-settings` will `sync` the settings, to prevent any unauthorized changes.
Expand Down
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,16 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
return syncSettings(false, context)
})

// A repo transferred into the org gets the same treatment as a newly created one.
// GitHub delivers repository.transferred to the receiving account, so this is the
// only webhook that fires when a repo arrives from another org or user.
robot.on('repository.transferred', async context => {
const { payload } = context
const { sender } = payload
robot.log.debug('repository.transferred payload from ', JSON.stringify(sender))
return syncSettings(false, context)
})

robot.on('repository.archived', async context => {
const { payload } = context
const { sender } = payload
Expand Down
14 changes: 14 additions & 0 deletions test/integration/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,19 @@ function buildRepositoryCreatedEvent () {
}
}

function buildRepositoryTransferredEvent () {
return {
name: 'repository.transferred',
payload: {
changes: { owner: { from: { organization: { login: any.word() } } } },
repository,
organization,
sender,
installation
}
}
}

function buildTriggerEvent () {
return buildRepositoryCreatedEvent()
}
Expand All @@ -235,5 +248,6 @@ module.exports = {
buildTriggerEvent,
buildRepositoryCreatedEvent,
buildRepositoryEditedEvent,
buildRepositoryTransferredEvent,
repository
}
24 changes: 24 additions & 0 deletions test/integration/triggers/repository-transferred.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { describe, it, beforeEach, afterEach } = require('node:test')
const { buildRepositoryTransferredEvent, initializeNock, loadInstance, mockAdminRepository, repository, teardownNock } = require('../common')

describe('repository.transferred trigger', function () {
let probot, githubScope

beforeEach(async () => {
githubScope = initializeNock()
probot = await loadInstance()
})

afterEach(() => {
teardownNock(githubScope)
})

it('does not apply configuration when the repository does not have a settings.yml', async () => {
mockAdminRepository(githubScope)
githubScope
.get(`/repos/${repository.owner.login}/${repository.name}`)
.reply(200, { ...repository, archived: false })

await probot.receive(buildRepositoryTransferredEvent())
})
})
Loading