ChatMediator for GitHub issues & pull requests #127
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR corresponds to issue #123. It extends the bot framework with two new chat mediators which allow SBF bots to interact with users through the comments on GitHub issues and pull requests. In the Social-Bot-Framework repo there's also a branch
enh-chatmediator-github
containing the updated bot metamodel.Usage:
Both new "messengers" can be used in the bot model similar to the existing messengers.
For using the GitHub API, the bot needs to use a GitHub app. Therefore, a GitHub app needs to be created and can then be installed in organizations, user accounts and repositories. Every app has an id and a private key should be generated for it.
After downloading the private key, it needs to be "converted" from PKCS#1 to PKCS#8 (see https://stackoverflow.com/questions/8290435/convert-pem-traditional-private-key-to-pkcs8-private-key).
In the bot model, the "Authentication Token" of the messenger needs to be set to [GitHub App Id]:[GitHub App Private Key]. Use the private key in PKCS#8 format, but remove the first and last line before copying it.
On GitHub, set the webhook url of the app to
.../SBFManager/github/webhook/{gitHubAppId}
. For testing this locally, https://smee.io can be used.Implementation details:
There are two new mediator classes, the
GitHubIssueMediator
andGitHubPRMediator
.Both mediators use the new
GitHubChatMediator
as a parent class, because the implementation for handling incoming comments and for posting new comments is very similar for issues and pull requests. This is reasoned in the fact that in GitHub a pull request also seems to be an issue.Besides that, there are two more new classes:
GitHubWebhookReceiver
andGitHubAppHelper
.The new
GitHubWebhookReceiver
class contains the endpoint/github/webhook/{gitHubAppId}
that receives the webhook events from the GitHub app. These events are redirected to the chat mediators.The
GitHubAppHelper
supports with the following:To authenticate as an app, a JWT needs to be generated and signed with the app's private key. This JWT can then be used to list the installations of the app (e.g., organizations or repositories) and to create app installation tokens. With these, the GitHub API for the respective repositories can be used to post comments on issues and pull requests.