Skip to content

Commit

Permalink
Merge node18upgrade into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-branch-merger[bot] authored Oct 12, 2023
2 parents 9f3b320 + da093cf commit 2c97a18
Show file tree
Hide file tree
Showing 6 changed files with 2,432 additions and 1,310 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '18'
cache: 'yarn'
- run: yarn install --frozen-lockfile
- run: yarn test
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 16.14.2
nodejs 18.18.1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"nock": "^13.2.4",
"nodemon": "^2.0.15",
"rollbar-sourcemap-webpack-plugin": "^3.3.0",
"serverless": "^3.12.0",
"serverless": "^3.35.2",
"serverless-offline": "^8.5.0",
"serverless-webpack": "^5.7.0",
"smee-client": "^1.2.2",
Expand Down
3 changes: 1 addition & 2 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins:

provider:
name: aws
runtime: nodejs18.x
stage: ${env:ENVIRONMENT}
region: us-east-1
vpc:
Expand All @@ -23,8 +24,6 @@ provider:
env: ${self:custom.environmentMap.${env:ENVIRONMENT}}
managed_by: serverless-framework
function: lambda
layers:
- arn:aws:lambda:us-east-1:072686360478:layer:node-16_14_2:1
environment: ${file(env.js)}

package:
Expand Down
38 changes: 20 additions & 18 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ interface Config {
enabled: boolean,
label_name: string,
comment: boolean,
watch_default_branch: boolean
watch_default_branch: boolean,
base_name: string
}

export const MergerBot: ApplicationFunction = (app: Application) => {
const defaultConfig = {
enabled: false,
label_name: 'On Staging',
comment: true,
watch_default_branch: false
watch_default_branch: false,
base_name: 'staging'
}

// app.router.use(rollbar.errorHandler())
Expand All @@ -38,10 +40,10 @@ export const MergerBot: ApplicationFunction = (app: Application) => {
}

if (config.comment) {
const commentBody = `I see you added the "${config.label_name}" label, I'll get this merged to the staging branch!`
const commentBody = `I see you added the "${config.label_name}" label, I'll get this merged to the ${config.base_name} branch!`
await addComment(commentBody, context)
}
await mergePRIntoStaging(context)
await mergePRIntoStaging(context, config)
app.log.debug('merged and commented')
})

Expand All @@ -55,8 +57,8 @@ export const MergerBot: ApplicationFunction = (app: Application) => {
return
}

if (config.comment) { await addComment("I'll get this merged to the staging branch!", context) }
await mergePRIntoStaging(context)
if (config.comment) { await addComment(`I'll get this merged to the ${config.base_name} branch!`, context) }
await mergePRIntoStaging(context, config)
await addLabel(context, config.label_name)
}
})
Expand All @@ -65,7 +67,7 @@ export const MergerBot: ApplicationFunction = (app: Application) => {
const config = (await loadConfig(context)) as Config
if (!config.enabled) return
if (await pullRequestHasLabel(context, config.label_name)) {
await mergePRIntoStaging(context)
await mergePRIntoStaging(context, config)
}
})

Expand All @@ -74,8 +76,8 @@ export const MergerBot: ApplicationFunction = (app: Application) => {
if (!config.enabled || !config.watch_default_branch) return
const defaultBranch = context.payload.repository.default_branch
if (context.payload.ref !== `refs/${defaultBranch}` && context.payload.ref !== `refs/heads/${defaultBranch}`) return
app.log.debug(`attempting to merge ${defaultBranch} into staging`)
await mergeIntoStaging(context, defaultBranch)
app.log.debug(`attempting to merge ${defaultBranch} into ${config.base_name}`)
await mergeIntoStaging(context, defaultBranch, config)
})

async function loadConfig(context: Context) {
Expand All @@ -94,17 +96,17 @@ export const MergerBot: ApplicationFunction = (app: Application) => {
return false
}

async function mergePRIntoStaging (context: Context) {
app.log.debug('attempting to merge PR into staging')
async function mergePRIntoStaging (context: Context, config: Config) {
app.log.debug(`attempting to merge PR into ${config.base_name}`)
const { data: prDetails } = await context.github.pulls.get(context.issue())
await mergeIntoStaging(context, prDetails.head.ref).catch(async error => {
await mergeError(error, context)
await mergeIntoStaging(context, prDetails.head.ref, config).catch(async error => {
await mergeError(error, context, config)
})
}

async function mergeIntoStaging (context: Context, head: string) {
async function mergeIntoStaging (context: Context, head: string, config: Config) {
const mergePayload = context.repo({
base: 'staging',
base: config.base_name,
head: head
})
await context.github.repos.merge(mergePayload)
Expand All @@ -128,14 +130,14 @@ export const MergerBot: ApplicationFunction = (app: Application) => {
return result
}

async function mergeError(error: { message: string }, context: Context) {
async function mergeError(error: { message: string }, context: Context, config: Config) {
if (error.message === 'Merge conflict') {
await addComment(
'Merge conflict attempting to merge this into staging. Please fix manually.',
`Merge conflict attempting to merge this into ${config.base_name}. Please fix manually.`,
context
)
} else {
app.log.error(`issue merging branch: ${error}`)
}
}
}
}
Loading

0 comments on commit 2c97a18

Please sign in to comment.