The function of a bot is to listen and interact with events.
Github is a platform used in hosting git projects.
It is also a social network designed for developers.
For every action done on a project, Github dedicates an event and allow you to listen to the event.
When Github dispatches events, web hook catches these events.
Your bots Payload URL is the first endpoint that listens to events.
There are various ways to communicate with Github:
You can communicate manually, i.e.
When your account is logged on and issues and comments are made.
Or, use the GraphQL API which is a very powerful tool.
The REST API is also available and very useful in listening to events.
##Making a Github bot
To create a bot which can react and listen to a Github activity, we can use the Github REST API which is an event listener and Knplabs Github API client.
The REST concepts includes:
- Using GET requests to get a resource.
- Using PUT/PATCH to POST requests to create a resource.
- Using DELETE to delete resources.
- The knpLabs Github API client can be installed using a composer.
- A sample is provided in the project README file and can be used to play around
- Query the API to get all the followers of a Github user.
- A client which can query the API is needed. This API can be managed using "domains". Now, we have a query method which can accept parameters.
- Sometimes, we want to do more than querying, we need authentication to Github. There are ways of doing this from Github and Knplabs library, these includes; simple "login/password" to complete authentication which is done using OAuth. Personal API Token is another authentication method that can be used for simple applications. It comes with its own benefits which includes: increase in the limit of your API Rate and selecting the actions you are permitted to do. With the bot, we can authenticate to Github.