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

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

Merged
merged 66 commits into from
Jun 5, 2023

Conversation

trz42
Copy link
Contributor

@trz42 trz42 commented Apr 6, 2023

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
Copy link
Contributor

boegel commented May 12, 2023

@trz42 Can you look into fixing the merge conflicts?

@trz42
Copy link
Contributor Author

trz42 commented May 12, 2023

@trz42 Can you look into fixing the merge conflicts?

Done.

Copy link
Contributor

@boegel boegel left a comment

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

eessi_bot_event_handler.py Outdated Show resolved Hide resolved
eessi_bot_event_handler.py Show resolved Hide resolved
eessi_bot_event_handler.py Outdated Show resolved Hide resolved
eessi_bot_event_handler.py Outdated Show resolved Hide resolved
eessi_bot_event_handler.py Show resolved Hide resolved
eessi_bot_event_handler.py Outdated Show resolved Hide resolved
eessi_bot_event_handler.py Outdated Show resolved Hide resolved
eessi_bot_event_handler.py Outdated Show resolved Hide resolved
eessi_bot_event_handler.py Outdated Show resolved Hide resolved
tasks/build.py Outdated Show resolved Hide resolved
Copy link
Contributor

@boegel boegel left a comment

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)

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

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
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

eessi_bot_event_handler.py Outdated Show resolved Hide resolved
eessi_bot_event_handler.py Show resolved Hide resolved
eessi_bot_event_handler.py Show resolved Hide resolved
tools/filter.py Show resolved Hide resolved
tools/filter.py Outdated Show resolved Hide resolved
tools/filter.py Outdated Show resolved Hide resolved
tools/permissions.py Outdated Show resolved Hide resolved
COMMAND_PERMISSION = "command_permission"


def check_command_permission(account):
Copy link
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
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

tools/pr_comments.py Outdated Show resolved Hide resolved
eessi_bot_event_handler.py Show resolved Hide resolved
eessi_bot_event_handler.py Outdated Show resolved Hide resolved
eessi_bot_event_handler.py Show resolved Hide 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
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
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

Copy link
Contributor

@boegel boegel left a comment

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