squidfunk / terraform-aws-github-ci

[DEPRECATED] Serverless CI for GitHub using AWS CodeBuild with PR and status support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GitHub webhook Lambda function fails in 0.4.1

Stretch96 opened this issue · comments


GitHub webhook lambda function fails when triggered

Steps to reproduce the bug

terraform apply with version 0.4.1 of the module

The first noticeable failure is that when PRs are opened/updated, the AWS CodeBuild check no longer appears within the PR.

The AWS SNS integration is still in place and the lambda function does get triggered, but fails with:

TypeError: Cannot read property 'replace' of undefined
at /var/task/index.js:45:205
at Array.reduce (native)
at r.default (/var/task/index.js:44:19)

Package versions

  • terraform-aws-github-ci: 0.4.1
  • terraform: v0.11.3

The last working commit is 9035748064f7f0174319f7b292e67918b3fb32fc, which could probably be tagged as v3.1 (v3 contains a bug with the S3 bucket provisioning)

Found the bug:

Line 48:

var t = r.Sns.MessageAttributes["X-Github-Event"].StringValue # ...

StringValue is undefined:

console.log( r.Sns.MessageAttributes["X-Github-Event"]);
# { 'X-Github-Event': { Type: 'String', Value: 'pull_request' } }

Changing to this fixes the issue:

var t = r.Sns.MessageAttributes["X-Github-Event"].Value

I'll open a PR 👍

Okay ... So TypeScript 🤷‍♂️

Thought it would be as simple as changing in share/lambda/src/webhook.ts

const githubEvent = record.Sns.MessageAttributes!["X-Github-Event"].StringValue
# to
const githubEvent = record.Sns.MessageAttributes!["X-Github-Event"].Value

Running make causes the error:

[tsl] ERROR in ./share/lambda/src/webhook.ts(94,30)
      TS2339: Property 'Value' does not exist on type 'MessageAttributeValue'.

I can't see a way to ensure that when it compiles, Value is used instead of StringValue

Thanks for debugging! My mistake, I trusted the typings. It should obviously be .Value - I'll fix it straight away.

Fixed and released as part of 0.5.0. Thanks for your efforts!