Skip to main content

💧 Actions

Actions are the building blocks of AutoPR. They are the smallest unit of work that can be performed by the system.

For an in-depth tutorial on how to write a basic action, check out the tutorial.

🌱 The Hello World Example

import pydantic
from autopr.actions.base import Action


class Inputs(pydantic.BaseModel):
name: str


class Outputs(pydantic.BaseModel):
greeting: str


class Hello(Action[Inputs, Outputs]):
id = "hello"

async def run(self, inputs: Inputs) -> Outputs:
return Outputs(greeting=f"Hello, {inputs.name}!")

📝 Anatomy of an Action

Actions are defined as classes that inherit from Action[Inputs, Outputs], where Inputs and Outputs are Pydantic models that define the input and output data of the action.

The run method is the asynchronous entrypoint of the action. It receives the input data as a parameter and returns the output data as a result.

The id attribute is a unique identifier for the action. It is used to reference the action in the workflows.

🚚 Services

Actions are able to perform both routine and platform-specific throught the utilization of services. These services abstract and encapsulate specialized functions, enabling actions to operate seamlessly across different contexts.

They are accessible as instance attributes. For example, if you'd like to cache some data, you can do so by calling self.cache_service.store(key, value), and retrieve it later with self.cache_service.retrieve(key).

The services available are:

  • publish_service: Streamlines the creation, management, and publishing of structured updates to pull request (PR) descriptions.
  • platform_service: Provides a suite of tools tailored for interactions with platforms (eg. Github), allowing for tasks like fetching issue or PR metadata.
  • cache_service: Ensures data persistence by allowing actions to save and retrieve data across different runs.
  • commit_service: Offers a structured approach to git operations, such as staging, committing, and pushing changes.

Below are listed all the mentioned services, with their methods and properties.

PublishService provides a structured way to publish updates on the status of the action. You can modify the PR, add simple textual updates, code blocks, or create collapsible sections.

Example of usage can be seen in prompt.

Key Methods:

  • publish_update(text, section_title=None): Adds a textual update to the current section.
  • publish_code_block(heading, code, ...): Embeds a code block as a collapsible child in the current section.
  • start_section(title): Initializes a new section.
  • update_section(title: str): Updates the title of the current section.
  • end_section(title=None): Concludes the current section.