Skip to content

[gitlab] Add PRComment classes and GitLab support for bot: help command#376

Open
sondrebr wants to merge 11 commits into
EESSI:gitlabfrom
sondrebr:add-gitlab-support-bot-help-command
Open

[gitlab] Add PRComment classes and GitLab support for bot: help command#376
sondrebr wants to merge 11 commits into
EESSI:gitlabfrom
sondrebr:add-gitlab-support-bot-help-command

Conversation

@sondrebr
Copy link
Copy Markdown
Collaborator

Another step in implementing GitLab support for the bot, most notably making it support the bot: help command. Changes include:

  • In tools/pr_comments.py:
    • Existing PRComment class renamed to PRCommentInfo
    • Added BasePRComment class, "interface" to implement for each Git hosting platform to support creating/getting/editing PR comments
    • Added GitHubPRComment class, GitHub implementation of BasePRComment
    • Added GitLabPRComment class, GitLab implementation of BasePRComment
    • Added create_pr_comment_instance() function creating an instance of the correct PRComment class
    • Changed the create_comment() function to use the PRComment classes
  • In tools/commands.py:
    • Added ALL_COMMANDS constant (list containing all existing bot commands)
    • Added SUPPORTED_COMMANDS_PER_GIT_HOST constant (dictionary listing supported/implemented commands per Git hosting platform)
    • Added get_supported_commands() function retrieving the supported commands for the configured Git hosting platform
  • In eessi_bot_event_handler.py:
    • Change handle_issue_comment_event() method to use the EventInfo properties and get_app_name()
    • Add handle_note_event = handle_issue_comment_event to make the bot process GitLab comments
    • Change handle_bot_command() method to check if command is supported on the configured Git hosting platform
    • Change bot: help response message to include a list of unsupported commands (if any)
  • Added get_app_name() to tools/git.py to get the app/bot name (separate settings for GitHub/GitLab)
  • Updated PyGHee dependecy
  • Typo fix in EventInfo (I had used notable_type instead of noteable_type 🤦)
  • EventInfo and PRComment types (referring to subclasses of BaseEventInfo and BasePRComment, respectively)

Usage

To use the bot in its current state on GitLab, follow the Usage section in the description of #370, except:

  • When updating PyGHee, check that commit 514bdf6... is installed.
  • The GitLab access token must have the api scope and the Reporter role (not Planner!) for the bot to be able to post comments.
  • Setting up a custom Smee server is no longer required if you use GitLab.com or GitLab CE/EE 19.0 or above, as they support signing tokens on webhooks. In that case, GitLab will generate a signing token for you, which must be stored as the GITLAB_WEBHOOK_SECRET_TOKEN environment variable. Make sure to include the whsec_ prefix.
    • Side note if using GitLab.com: AFAIK it is not possible to create project access tokens on the free plan. One can however create a service account in the group/project and generate an access token for the service account.
  • If using a GitLab instance without support for signing tokens, you still need to use a custom Smee server. Additionally, you need to use a webhook secret similar to the signing tokens GitLab generates, consisting of 32 bytes encoded in base64, prefixed with whsec_. These can be generated e.g. by running python -c "import base64, secrets; print('whsec_' + base64.b64encode(secrets.token_bytes(32)).decode())".

sondrebr added 11 commits May 20, 2026 11:24
'notable' should be 'noteable'
Some docstrings already referred to subclasses of BaseEventInfo as EventInfo without EventInfo actually being defined anywhere
Commands might for example be supported on GitHub, but not GitLab. Responding with a message explicitly stating that the command is unsupported is more useful to the user than letting the command handler run until it fails.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant