Add PR author as app collaborator (#21353)
This commit is contained in:
@@ -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.`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user