A bot to manage GitHub repository using Azure Functions
The objective of the day is to describe you path that lead us to create a bot for the UWP Community Toolkit repository hosted on GitHub. The bot was needed in order to manage the growing number of issues and Pull Requests. A simple process can really be time-consuming, especially on repetitive tasks without value-added.
In order to maintain the process viable, Nikola Metulev and I decided to make a bot with a minimal set of features that can reduce the workload and help focus on what matter the most: the code.
The bot was divided in different areas of improvements:
- Closing inactive issues
- Send a reminder on unanswered issues
- Send a reminder for undone issues
- Send a message if a merged PR have related issues still opened
- Send a message if a UserVoice entry is not created yet
The source code
The simplest solution was to create functions using the GitHub API. Each task we discussed earlier will be separated into different functions. The core of the bot will be able to communicate with the GitHub API.
The major part of the API calls will be to read data about issues and Pull Requests and to be able to reply to contributors and to close issues. To do this, I started to review the API endpoints available in the GitHub
documentation here. And for an aha moment, I saw there was a GraphQL API that I could leverage to make powerful and flexible queries like this one:
Each function of the bot will trigger a GraphQL query and use this result to execute mutations on the according object (
issue or PR).
The rest of the GraphQL queries used are available on GitHub here.
Hosting the bot
Functions are working and the code is hosted on GitHub (https://github.com/nmetulev/github-bot-uwp-toolkit).
But now, where do we host these functions so it can be triggered automatically the way we want? In most cases, the functions will be triggered every day or by listening to a webhook. The answer: Azure functions!
Azure functions is a Serverless architecture that lets you run fast & minimal code/functions which have a dedicated purpose, and so it really suits our use-case.
Oh, and by the way, there is a 3-steps guide you can follow to setup a CI/CD pipeline using GitHub or any other source code services supported.
Call to action
Feel free to read and reuse the code. (https://github.com/nmetulev/github-bot-uwp-toolkit)
And star the repository if you found it useful.