google-cloud-build-slack icon indicating copy to clipboard operation
google-cloud-build-slack copied to clipboard

TypeError: Cannot read property 'repoName' of undefined

Open svenmueller opened this issue 6 years ago • 4 comments

The cloud function crashes with the following error:

TypeError: Cannot read property 'repoName' of undefined
    at Object.module.exports.createSlackMessage (/user_code/index.js:86:37)
    at module.exports.subscribe (/user_code/index.js:19:34)
    at /var/tmp/worker/worker.js:770:16
    at /var/tmp/worker/worker.js:718:11
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9)"

Any idea what's causing this error?

-- Sven

svenmueller avatar Feb 19 '19 10:02 svenmueller

I ran into the same issue... it appears that GCB has changed the event object.

Here's what my getGithubCommit looks like:

module.exports.getGithubCommit = async (build, octokit) => {
    try {
        const githubRepo   = build.substitutions.REPO_NAME;
        const githubBranch = build.substitutions.BRANCH_NAME;
        const commitSha    = build.substitutions.COMMIT_SHA;

        const githubCommit = await octokit.git.getCommit({
            commit_sha: commitSha,
            owner: 'xxxxxxxx',
            repo: githubRepo,
        });

        return githubCommit;
    } catch (err) {
        return err;
    }
};

benperove avatar May 16 '19 20:05 benperove

Hi @svenmueller, perhaps the build did not have a .source.repoSource property (if it was a github app triggered build this would be the case).

#26 was just merged and might help, could you try it out and confirm please?

@benperove that's a nice approach by explicitly setting the github owner, you don't have to deal with parsing build.source.repoSource.repoName for it and $REPO_NAME for github app triggers is indeed the github repo name, but for mirrored repos, build.substitutions.REPO_NAME will give the mirrored repo's Cloud Source Repository counterpart name, and won't work as value for repo in the getCommit's argument because it will need to be parsed.

naseemkullah avatar Jun 06 '19 03:06 naseemkullah

Hello folks, I have also recently come across the issue of repoName not being present in the JSON. While I have shifted away from this codebase here, I did find the reason (in my case) behind the crash.

Because we needed to use a custom build step container, we pushed a dockerfile into our gcr.io repository. Turns out that Cloud Build is triggered at that point, building the image and sending a Cloud Build notification. repoName and other various fields were obviously left as null.

Hope this helps for any future references.

svachmic avatar Apr 02 '20 07:04 svachmic

Thanks @svachmic

naseemkullah avatar Apr 02 '20 21:04 naseemkullah