Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChatMediator for GitHub issues & pull requests #127

Merged
merged 5 commits into from
Feb 5, 2023

Conversation

phil-cd
Copy link
Member

@phil-cd phil-cd commented Aug 19, 2022

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 and GitHubPRMediator.

graph BT;
    B[abstract EventChatMediator]-->A[abstract ChatMediator];
    C[abstract GitHubChatMediator]-->B;
    D[GitHubIssueMediator]-->C;
    E[GitHubPRMediator]-->C;
    style A fill:#fff
    style B fill:#fff
Loading

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 and GitHubAppHelper.

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.

@phil-cd phil-cd added the enhancement New feature or request label Aug 19, 2022
@phil-cd phil-cd linked an issue Aug 19, 2022 that may be closed by this pull request
6 tasks
@phil-cd phil-cd marked this pull request as ready for review December 27, 2022 09:28
@AlexanderNeumann AlexanderNeumann changed the base branch from develop to release/1.6.0 February 5, 2023 20:58
@AlexanderNeumann AlexanderNeumann merged commit 794a703 into release/1.6.0 Feb 5, 2023
@AlexanderNeumann AlexanderNeumann deleted the 123-enh-chatmediator-github branch October 11, 2023 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ENH] ChatMediator for GitHub issues & pull requests
2 participants