1
0
mirror of synced 2025-12-22 03:16:52 -05:00

Add PR author as app collaborator (#21353)

This commit is contained in:
Robert Sese
2021-09-07 19:53:42 -05:00
committed by GitHub
parent 279608e55d
commit 2c20d13927

View File

@@ -10,6 +10,7 @@ export default async function createApp(pullRequest) {
repo: { name: repo },
},
head: { ref: branch },
user: author,
} = pullRequest
const appName = createAppName({ prefix: 'ghd', repo, pullNumber, branch })
@@ -36,6 +37,23 @@ export default async function createApp(pullRequest) {
} catch (error) {
throw new Error(`Failed to create Heroku App ${appName}. Error: ${error}`)
}
// Add PR author (if staff) as a collaborator on the new staging app
try {
if (author.site_admin === true) {
await heroku.post(`/apps/${appName}/collaborators`, {
body: {
user: `${author.login}@github.com`,
// We don't want an email invitation for every new staging app
silent: true,
},
})
console.log(`Added PR author @${author.login} as a Heroku app collaborator`)
}
} catch (error) {
// It's fine if this fails, it shouldn't block the app from deploying!
console.warn(`Warning: failed to add PR author as a Heroku app collaborator. Error: ${error}`)
}
} else {
console.log(`Heroku App ${appName} already exists.`)
}