Skip to content

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

Merged
trz42 merged 18 commits into
EESSI:gitlabfrom
sondrebr:add-gitlab-support-bot-help-command
Jun 16, 2026
Merged

[gitlab] Add PRComment classes and GitLab support for bot: help command#376
trz42 merged 18 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.

@trz42 trz42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this PR @sondrebr ! Looks quite good. A few comments added for consideration.

I'll try to run it too, to get a feeling what is needed to setup a bot responding to web hooks from GitLab.

Comment thread tools/pr_comments.py
Comment thread tools/pr_comments.py Outdated
Comment thread tools/pr_comments.py Outdated
Comment thread tools/pr_comments.py Outdated
Comment thread tools/pr_comments.py
Comment thread tools/pr_comments.py Outdated
Comment thread tools/pr_comments.py Outdated
Comment thread tools/pr_comments.py Outdated
Comment thread tools/pr_comments.py Outdated
Comment thread tools/pr_comments.py Outdated
sondrebr and others added 2 commits June 10, 2026 13:36
- Inherit from `ABC` and make methods abstract
- Improve docstring and comments
- Improve `body` XOR `id` check
- Ensure `id` is not an empty string
- Use `ValueError`s
- Add arguments to `edit` and `append`

Co-authored-by: Thomas Röblitz <trz42@users.noreply.github.com>
Co-authored-by: Thomas Röblitz <trz42@users.noreply.github.com>
Comment thread tools/pr_comments.py Outdated
if not self.body:
raise Exception("'body' must be set to create a comment.")
if self.id:
# Safeguard: id should not be set when body is initialized, but guard

@sondrebr sondrebr Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😝

Edit: Hound noticed the missing indentation

sondrebr and others added 5 commits June 10, 2026 15:10
`_require_body` and `_require_id` for checking if respectively
`self.body` and `self.id` are set.

Co-authored-by: Thomas Röblitz <trz42@users.noreply.github.com>
Apply suggestions to use `_require_body` and `_require_id`

Co-authored-by: Thomas Röblitz <trz42@users.noreply.github.com>
@sondrebr sondrebr requested a review from trz42 June 11, 2026 10:00

@trz42 trz42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I'll give it another try against GitLab and also check if it works on GitHub, and merge it then.

@trz42

trz42 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Looks good to me! I'll give it another try against GitLab and also check if it works on GitHub, and merge it then.

Tested PR against both GitLab and GitHub with all supported commands. All good.

@trz42 trz42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this @sondrebr !

@trz42 trz42 merged commit be61061 into EESSI:gitlab Jun 16, 2026
7 checks passed
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.

2 participants