# Angular Github bot The bot is available on https://github.com/angular/github-robot/. It uses [Probot](https://probot.github.io/) which is a project developed and maintained by Github. Probot is a nodejs application that offers an API to communicate with Github (receive events and make api calls). The bot is hosted on Firebase: https://console.firebase.google.com/project/angular-robot/ but it’s private. Ask Igor if you want to get access. ## Installation To install the bot on a repository, the first thing that you need to do is to create a config file on that repository in `.github/` named `angular-robot.yml`. You can find an example of the config file here: https://github.com/angular/github-robot/blob/master/test/fixtures/angular-robot.yml Once this config file is created, you can install the bot on that repository. To do that you need to be an admin of the Angular organisation. You then go to the URL https://github.com/apps/ngbot. From there you can click on "configure" and choose on which repositories you want to install it. Once you've installed the bot, it will automatically start gathering information on the existing PRs (to build the cache database). After that, any event received from Github will be automatically handled. ## Development Since the bot is supposed to interact with Github, it might be difficult to test the code. To do that I've created a dev version of the bot called Wheatley-dev. It is installed on my test repository: https://github.com/ocombe/test. When you run the command `yarn start:dev` it will start the bot in dev mode and automatically start watching for events from that repository. It will read the config from the folder `functions/private`. You need to put the private API keys in this. Ask Joey or Charles for those files. The dev bot also uses the following dev Firebase account: https://console.firebase.google.com/project/probot-triage. Since this is a free account, it cannot make api request to external servers, only receive events. It is mostly used to store the database, not to run the bot itself (since you're starting it locally in dev mode). To run the Firebase functions, you can either use `yarn start:functions` or `yarn serve:functions`. ## Deployment To deploy the bot on Firebase, just run `yarn deploy:functions:prod`. It will run the tests, lint, and then deploy the code to Firebase. Don't forget to monitor the logs to check if anything goes wrong. ## How to debug the Github ng-bot ### Node app You can see the logs [on Firebase](https://console.firebase.google.com/project/angular-robot/) by clicking on `functions` in the left menu, and then logs (by default it's showing everything, but you can filter to only see the errors). You can also see the logs on Google cloud (easier to read because the interface is cleaner) at https://console.cloud.google.com/logs/viewer?project=angular-robot. The bots reacts either to events that it receives or to manual api calls: - Event driven: Github sends the events to Firebase that will trigger the functions. - Manual: some functions have an external url that you can call to start them. Those functions are protected by a flag in the database (firestore), they only work if you set `admin > config > allowInit` to `true`. Don't forget to set this flag to false once you're done to avoid any issue with people that would abuse this (since the urls can be found on Github). You can also start the functions via Google Cloud functions (click on the small menu on the right of a function, and select "test the function"): https://console.cloud.google.com/functions/list?project=angular-robot. The advantage is that you will be able to see the logs at the same time. The functions that you can call manually are: - [deleteCachedConfigs](https://us-central1-angular-robot.cloudfunctions.net/deleteCachedConfigs): if you changed the config file it should update automatically the cached config once your PR is merged (the bot monitors the config file), but if there is an issue you can call this url to manually clear the cache. - [init](https://us-central1-angular-robot.cloudfunctions.net/init): trigger init for all repositories, you shouldn't need to use that unless you clean the database for some reason and you need to repopulate the cache with all opened issues and PRs. - [initTriage](https://us-central1-angular-robot.cloudfunctions.net/initTriage): force the triage of all opened issues on all the repositories, it'll check all issues and only update the ones that aren't correctly triaged. - [initTriagePR](https://us-central1-angular-robot.cloudfunctions.net/initTriagePR): Same thing for PRs. - [updatePRStatuses](https://us-central1-angular-robot.cloudfunctions.net/updatePRStatuses): force an update of the status (`ci/angular: merge status` and `google3`) of all opened PRs. Unfortunately this will usually timeout because we have too many opened PRs... **Don't abuse those functions**, they make a lot of requests to the Github API and might end up maxing out the API rate limit for the current hour... ### What to do when there is an issue - Check the [Github API status](https://www.githubstatus.com/) to see if there is any issue right now. - The issue/PRs isn't triaged: you can add/remove a monitored label to force an update (see the config file on Github, such as https://github.com/angular/angular/blob/master/.github/angular-robot.yml, for the list of monitored labels). The bot will then triage it after a few seconds. - The `ci/angular: merge status` is wrong or hasn't been updated: you can add/remove a monitored label to force an update (see above). Usually the `target: *` label is a good candidate. If you're feeling adventurous, you can check the API information that Github provides. For that you take the url of your issue or PR and replace the first part of the url with `api.github.com/repos/`, and add a `s` to `pull` for PRs. For example if you take the PR https://github.com/angular/angular/pull/29634 then you can access the API data at https://api.github.com/repos/angular/angular/pulls/29634. For the issue https://github.com/angular/angular/issues/29710 it would be https://api.github.com/repos/angular/angular/issues/29710. You can then follow the urls given on this api page to see more stuff (such as reviews, comments, statuses...). If the result is paginated (30 items max per page), you can use `?page=2` to access the next page. ### "Common" errors - `Update status for unknown PR, ignored. [...]`: we received an event for a commit that belongs to a PR that was just created and we don't have any information about this PR in our database yet. There is nothing to do, the next event will fix this (we receive a lot of events when a PR is created). - `'HttpError', code: 500, status: 'Internal Server Error'`: the Github api server failed, it happens from time to time... - `API rate limit exceeded for installation ID ...`: We've exceded our quota for the current hour. We cache a lot of things to avoid this, but sometimes there is just too much activity on our repositories (when the caretaker merges a lot of PRs at the same time usually) that we get this error. There is nothing to do but wait for a while. - `Error: cannot communicate with function. Function invocation was interrupted.`: No idea what's causing this, it's a new error the started at the end of March and it's probably an issue with Firebase memory management... Firebase will automatically restart the function again when this happens.