Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'repoName' of undefined #19

Open
svenmueller opened this issue Feb 19, 2019 · 4 comments
Open

TypeError: Cannot read property 'repoName' of undefined #19

svenmueller opened this issue Feb 19, 2019 · 4 comments

Comments

@svenmueller
Copy link

svenmueller commented Feb 19, 2019

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

@benperove
Copy link

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;
    }
};

@naseemkullah
Copy link
Contributor

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.

@svachmic
Copy link

svachmic commented Apr 2, 2020

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.

@naseemkullah
Copy link
Contributor

Thanks @svachmic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants