TaskCluster-GitHub Bulletin

Yesterday I got the integration working, hooray! I’m happy, because I seriously wanted the integration to work before Toronto… oh my goodness! I haven’t told you about Toronto yet! But I’ll start with the integration :)

So, the last time we left off on me having trouble with getting authentication process right. My mentors helped me with this, and I’ve learned a new trick of “delayed action”, as I call it. Let me demonstrate :)

So, previously TaskCluster was an oAuth app, and the GitHub authentication was done once at the very beginning, during loading:

github: {
requires: [‘cfg’],
setup: ({cfg}) => {
let github = new Github({promise: Promise});

if (cfg.github.credentials.token) {
github.authenticate(cfg.github.credentials);
}

return github;
},
}
// Usage later:
context.github.repos.getSomeStuff();

The returned github object was all ready-to-use. This is no good for integration, because you have to authenticate separately for each request with the credentials of the particular installation (instance of integration) that sent the request.

So, what we do is we don’t authenticate at the beginning, but just preparing for it; what we return is a github object with authentication function — at any point in the program you grab that object, pass the installation ID to it, and boom! — you’ve made a custom authentication. This is what it looks like:

github: {
requires: [‘cfg’],
setup: async ({cfg}) => {
let github = new Github({promise: Promise});
    /**
Making preparations for authentication, namely, reading the
integration ID and the PEM certificate.
**/
    return {
getInstallationGithub: async (inst_id) => {

/**
Here we authenticate as integration first.
Second, we use these credentials and the installation ID to
generate the authentication token for the installation.
**/

// …and finally:
let gh = new Github({promise: Promise});
gh.authenticate({type: ‘token’, token});

// The very end result is fully ready-to-use github object
return gh;
}
};
}
}
// Usage later:
var iGithub = await this.github.getInstallationGithub(instID);
iGithub.repos.getSomeStuff();

Groovy, huh? And after some debugging, I’ve got a working integration! Of course, I’ll have to do some manual testing, and then write some automated tests (or maybe just correct the existing ones), and then we will let users try it out, but generally speaking, this is the victory!

And another big news is that in one week, I’m going to Mozilla’s Toronto office to work with my mentors in person! The release engineering team will be gathering there too, so I hope to meet lots of people. Not to mention that I’ve never been to Toronto, and I’m dying to see it. This is going to be an insanely great trip, and I’m really excited! Thank you, Mozilla! ❤️