Skip to content

support for sending commands to bot instances via PR comments - #172

Merged
boegel merged 66 commits into
EESSI:mainfrom
trz42:feature/bot-rebuild
Jun 5, 2023
Merged

boegel merged 66 commits into
EESSI:mainfrom
trz42:feature/bot-rebuild

Conversation

@trz42

@trz42 trz42 commented Apr 6, 2023 •

Copy link
Copy Markdown
Contributor

This PR probably needs some updates/polishing but it has been tested already with a few PRs to the software-layer repository. It includes the following additions:

  • class to model action filters where an action is something like submitting a build job
    • compared to setting a label bot:build an action can be filtered wrt a repository, an architecture and a bot instance name
    • idea is that an action is only performed if its context (repository, architecture and bot instance) matches the filter
  • class to model bot commands which are composed of a command such as help and build and an action filter
  • adds code to parse NEW comments for bot commands (beginning at the start of a line with bot: ), displays if a command has been received, processes the command(s) and adds some result/output in the same comment
  • handlers for commands: help, build and showconfig
  • adds an app.cfg setting for limiting which GH accounts can send commands to the bot
  • refactors existing code to work well with the addition of action filters: one major change is how configuration settings are passed to where they are accessed
  • includes some polishing of docstrings and other things
  • last but not least, adds some unit tests for the action filters

TODOs done

  • addressed the below by only running the critical code if the event is an issue_comment ... then the request_body has the key 'issue'
    • clarify that update_pr_comment is working only with issue comment events (not with pull request events) because it accesses the issue section of an event, see line (in tools/pr_comments.py)
      pr_number = int(request_body['issue']['number'])
    • or change the code such that it works with both pull request events and issue comment events, e.g., by determining the type of the event

truib added 30 commits March 28, 2023 22:20
@boegel

boegel commented May 12, 2023

Copy link
Copy Markdown
Contributor

@trz42 Can you look into fixing the merge conflicts?

@trz42

trz42 commented May 12, 2023

Copy link
Copy Markdown
Contributor Author

@trz42 Can you look into fixing the merge conflicts?

Done.

@boegel boegel 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.

first part of review, more coming soon...

Comment thread eessi_bot_event_handler.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
Comment thread tasks/build.py Resolved

@boegel boegel 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.

Minor issue: tests are missing for stuff in tools/commands.py for example, but that's not a huge disaster (not worth blocking PR over imho)

Comment thread eessi_bot_event_handler.py Outdated
return handler(event_info, bot_command)
else:
self.log(f"No handler for command '{cmd}'")
raise EESSIBotCommandError(f"unknown command '{cmd}'; use `bot: help` for usage information")

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.

Maybe this should also result in a comment back to the issue/PR where the bot command was issued?

Unknown bot command 'foo', only valid bot commands are: ...

This can be done in a follow-up PR imho.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, will create an issue for that.

Comment thread eessi_bot_event_handler.py Outdated
help_msg += "\n - Commands must be sent with a **new** comment (edits of existing comments are ignored)."
help_msg += "\n - A comment may contain multiple commands, one per line."
help_msg += "\n - Every command begins at the start of a line and has the syntax `bot: COMMAND [ARGUMENTS]*`"
help_msg += "\n - Currently supported COMMANDs are: `help`, `build`, `showconfig`"

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.

This should eventually be replaced by a pointer to documentation (once it's there) - can be done in follow-up PR

Comment thread eessi_bot_event_handler.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
Comment thread tools/filter.py Resolved
Comment thread tools/filter.py Resolved
Comment thread tools/filter.py Resolved
Comment thread tools/permissions.py Resolved
Comment thread tools/permissions.py
COMMAND_PERMISSION = "command_permission"


def check_command_permission(account):

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.

Checking of build and deploy permission should also come from here (eventually)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes makes sense

Comment thread tools/pr_comments.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
Comment thread eessi_bot_event_handler.py Resolved
# ... in order to prevent surprises we should be careful what the bot
# adds to comments, for example, before updating a comment it could
# run the update through the function checking for a bot command.
if check_command_permission(sender) is False:

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.

Since this is triggered for every issue comment being made, it's done too early, since for accounts that don't have permission to send commands to the bot this will immediately trigger a account XXX has NO permission to send commands to the bot (see boegel/software-layer#24 (comment)).

That should only be done if the comment effectively includes bot commands.

Let's try and make this the first thing we fix after merging this PR...

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.

Opened #184 to follow up on this

@boegel boegel 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.

I've tested this extensively with boegel/software-layer#24, and it's good to merge imho.

There's definitely room for improvement, but it's a nice step forward.

Thanks a lot for all the effort on this @trz42!

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.

3 participants