1.6 KiB
next |
---|
docs/development.md |
Hello World
A Probot plugin is just a Node.js module that exports a function:
module.exports = robot => {
// your code here
};
The robot
parameter is an instance of Robot
and gives you access to all of the bot goodness.
robot.on
will listen for any webhook events triggered by GitHub, which will notify you when anything interesting happens on GitHub that your plugin wants to know about.
module.exports = robot => {
robot.on('issues.opened', async context => {
// A new issue was opened, what should we do with it?
robot.log(context);
});
};
The context
passed to the event handler includes everything about the event that was triggered, as well as some helpful properties for doing something useful in response to the event. context.github
is an authenticated GitHub client that can be used to make API calls, and allows you to do almost anything programmatically that you can do through a web browser on GitHub.
Here is an example of an autoresponder plugin that comments on opened issues:
module.exports = robot => {
robot.on('issues.opened', async context => {
// `context` extracts information from the event, which can be passed to
// GitHub API calls. This will return:
// {owner: 'yourname', repo: 'yourrepo', number: 123, body: 'Hello World!}
const params = context.issue({body: 'Hello World!'})
// Post a comment on the issue
return context.github.issues.createComment(params);
});
}