def load_action(message): action_classes = actions.get_commands() match = COMMAND_MATCHER.search(message) if match and match[1] in action_classes: action_class = action_classes[match[1]] config = action_class.command_to_config(match[2].strip()) action = voluptuous.Schema(action_class.get_schema())(config) command = "%s%s" % (match[1], match[2]) return command, action
def load_action(message): """Load an action from a message. :return: A tuple with 3 values: the command name, the commands args and the action.""" action_classes = actions.get_commands() match = COMMAND_MATCHER.search(message) if match and match[1] in action_classes: action_class = action_classes[match[1]] command_args = match[2].strip() config = action_class.command_to_config(command_args) action = voluptuous.Schema(action_class.get_schema())(config) return match[1], command_args, action
async def on_each_event(event: github_types.GitHubEventIssueComment) -> None: action_classes = actions.get_commands() match = COMMAND_MATCHER.search(event["comment"]["body"]) if match and match[1] in action_classes: owner = event["repository"]["owner"]["login"] repo = event["repository"]["name"] async with github.aget_client(owner) as client: await client.post( f"/repos/{owner}/{repo}/issues/comments/{event['comment']['id']}/reactions", json={"content": "+1"}, api_version="squirrel-girl", )
def load_action( mergify_config: rules.MergifyConfig, message: str, ) -> typing.Optional[typing.Tuple[str, str, actions.Action]]: """Load an action from a message. :return: A tuple with 3 values: the command name, the commands args and the action.""" action_classes = actions.get_commands() match = COMMAND_MATCHER.search(message) if match and match[1] in action_classes: action_name = match[1] action_class = action_classes[action_name] command_args = match[2].strip() action_config = {} if defaults := mergify_config["raw"].get("defaults"): if defaults_actions := defaults.get("actions"): if default_action_config := defaults_actions.get(action_name): action_config = default_action_config
def UserConfigurationSchema( config: typing.Dict[str, typing.Any], partial_validation: bool = False) -> voluptuous.Schema: schema = { voluptuous.Required("pull_request_rules", default=[]): get_pull_request_rules_schema(partial_validation), voluptuous.Required("queue_rules", default=[]): QueueRulesSchema, voluptuous.Required("commands_restrictions", default={}): { voluptuous.Required(name, default={}): CommandsRestrictionsSchema for name in actions.get_commands() }, voluptuous.Required("defaults", default={}): get_defaults_schema(partial_validation), } if not partial_validation: schema = voluptuous.And(schema, voluptuous.Coerce(FullifyPullRequestRules)) return voluptuous.Schema(schema)(config)
def load_command( mergify_config: rules.MergifyConfig, message: str, ) -> Command: """Load an action from a message.""" action_classes = actions.get_commands() match = COMMAND_MATCHER.search(message) if not match: raise NotACommand( "Comment contains '@Mergify/io' tag but is not aimed to be executed as a command" ) if match[1] in action_classes: action_name = match[1] action_class = action_classes[action_name] command_args = match[2].strip() action_config = {} if defaults_actions := mergify_config["defaults"].get("actions"): if default_action_config := defaults_actions.get(action_name): action_config = default_action_config