[gitlab] Add GitLab connection and EventInfo classes#370
Open
sondrebr wants to merge 9 commits intoEESSI:gitlabfrom
Open
[gitlab] Add GitLab connection and EventInfo classes#370sondrebr wants to merge 9 commits intoEESSI:gitlabfrom
sondrebr wants to merge 9 commits intoEESSI:gitlabfrom
Conversation
Contains the BaseEventInfo class, the GitHubEventInfo and GitLabEventInfo classes implementing it, and the function create_event_info_instance.
Collaborator
Author
|
Had to temporarily switch the base branch to get rid of some old commits 🤦 Ready for review now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
First step towards implementing GitLab support for the bot. This PR adds:
python-gitlab,PyGHeewith GitLab support)gitandgitlabconnections/gitlab.pyfor connecting to GitLabtools/git.pywith functions:get_hosting_platform()gets the configured Git hosting platform (GitHub/GitLab)connect_to_host()performs initial connection to GitHub/GitLabtools/event_info.pywith:BaseEventInfoclass intended as an "interface" to implement for each Git hosting platformGitHubEventInfoclass implementingBaseEventInfofor GitHubGitLabEventInfoclass implementingBaseEventInfofor GitLabcreate_event_info_instance()creating an instance of the correct EventInfo classhandle_event()override in the event handler to use the new EventInfo classesThe PR does not any methods for handling GitLab events, but the events will be logged, e.g.:
get_hosting_platform()is intended to be used whenever platform-specific logic is required, to simplify adding support for other platforms in the future (e.g. Forgejo/Codeberg, Gitea, ...).The
*EventInfoclasses were implemented to handle the differences between the GitHub and GitLab webhooks, such that the necessary information can be retrieved through class properties. For example,event_info.actionreturns the event action. IfGitLabEventInfois used, theactionproperty converts the action to its GH equivalent before returning, e.g.updatebecomesedited.The classes currently have support for (as far as I can tell) all
event_infofields used by the bot.They also have a
__getitem__()override to support subscripting for compatibility with the existing uses ofevent_info- this version of the bot should therefore still have full GitHub support.Usage
Because webhooks signatures are not yet supported by GitLab (though they are in development), it is necessary to run a custom Smee server to sign the webhooks. I have a fork here which should sign the events in the same way as they will be signed on GitLab in the future. I have also added a "Quickstart" section on top of the README in the fork with instructions on how to run the server.
To "use" the bot in its current state on GitLab, you need to do the following:
pip install -r requirements.txt)Ensure the correct version of PyGHee (commit
c5e1063...) is installed.Settings->Webhooks->Add new)The webhook should have the
CommentsandMerge request eventstriggers, and must be configured with a secret token. The secret token can be generated e.g. by runningpython -c "import secrets; print(secrets.token_hex())", and must be stored as the environment variableGITLAB_WEBHOOK_SECRET_TOKEN. The webhooks must also be set up to send events to the custom Smee server.Settings->Access tokens->Add new token)In the future, the
apiscope andPlannerwill be required for the bot to be able to write comments. For this PR, however, it just needs to be able to connect to GitLab, so theread_apiscope andGuestrole should be sufficient. The access token must be stored as the environment variableGITLAB_PROJECT_ACCESS_TOKEN.gitandgitlabsections inapp.cfgIn the
gitsection,hosting_platform = gitlabmust be set (if it is set togithubinstead, the bot should function normally).In the
gitlabsection, theapi_timeout,bot_name, andinstance_urloptions must be set. For theinstance_urloption, you must enter the base URL of your GitLab instance, which is used along with the access token to connect to GitLab.