Commands
ChangesCommand
¶
Commands for working with GitLab merge requests.
__init__(project_repo, change_repo, review_repo, llm_provider)
¶
Initialises the class with repository and provider dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_repo
|
ProjectRepositoryProtocol
|
Instance of ProjectRepositoryProtocol used to handle project-related operations. |
required |
change_repo
|
ChangeRepositoryProtocol
|
Instance of ChangeRepositoryProtocol used to manage change-related operations. |
required |
review_repo
|
ReviewRepositoryProtocol
|
Instance of ReviewRepositoryProtocol used to handle review-related operations. |
required |
llm_provider
|
LLMProviderProtocol
|
Instance of LLMProviderProtocol responsible for interactions with the Language Model provider. |
required |
publish_review(project, change_request, review_content)
¶
Publishes a review comment for a specified project and change request.
This method utilises the review repository to post a comment for a previously generated review response on a specific change request within the specified project. The response is validated to ensure the comment was successfully submitted, and the body of the posted comment is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str
|
The name of the project where the review is being published. |
required |
change_request
|
int
|
The identifier of the change request to which the comment is being added. |
required |
review_content
|
str
|
The content of the review comment to be published. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The body of the published review comment as a string. |
review(project, change_request, work_type=PromptEnum.DESIGN_RECOMMENDATIONS)
¶
Reviews code differences from a GitLab merge request using an AI model.
The function fetches diffs for a specified merge request, submits these diffs to an AI model, and retrieves the review response. The AI is prompted to act as an expert developer while providing feedback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str
|
str. Full project name in Gitlab |
required |
change_request
|
int
|
int. Gitlab Merge request id |
required |
work_type
|
PromptEnum
|
PromptEnum. |
DESIGN_RECOMMENDATIONS
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The review response content generated by the AI model. |
ConfigRepository
¶
Handles configuration management logic.
This class provides static methods to locate a configuration file, validate its permissions and data content, and read its contents into a configuration object. It can operate using default directories, environment variables, or a custom path provided by the user. The class also allows for creating a default configuration if none exists or the existing configuration data is invalid.
The main entry point for this class is the load method, which
returns a Configuration object based on the provided configuration file path.
create_default_config()
staticmethod
¶
Create the default config at the default location, return its configuration.
Returns:
| Name | Type | Description |
|---|---|---|
Configuration |
Configuration
|
An instance of the Configuration class with default data |
load(config_file_path=None)
staticmethod
¶
Loads a configuration from a file or creates a default one if none is found.
This method handles retrieving a configuration file, validating its correctness, and returning a Configuration instance. If no configuration file exists, it creates a default configuration file and returns the respective Configuration instance. In case of parsing errors or invalid configuration data, exceptions are raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file_path
|
str | None
|
Optional path to the configuration file. If not provided, a default configuration location will be used. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Configuration |
Configuration
|
An instance of the Configuration class containing |
Configuration
|
the loaded or default data. |
Raises:
| Type | Description |
|---|---|
RARepositoryError
|
Raised when there is an error parsing the configuration file or the configuration data is invalid. |
read_and_validate(config_location)
staticmethod
¶
Reads and validates a configuration file from the provided location.
This method reads a configuration file and validates its contents against specific requirements. If the reading or validation fails, appropriate errors are raised. Once the configuration file is successfully read and validated, it returns the parsed configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_location
|
str
|
The path to the configuration file to be loaded. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ConfigParser |
ConfigParser
|
A configuration parser instance containing the parsed and |
ConfigParser
|
validated configuration data. |
Raises:
| Type | Description |
|---|---|
RAConfigError
|
If an error occurs while reading the configuration file. or if the configuration data is invalid (schema validation fails). |
resolve_config_location(custom_path=None)
staticmethod
¶
Resolves the configuration file location based on a given custom path.
This method checks for a configuration file in the following order:
1. If custom_path is provided and exists, it is returned as the config path.
2. If no custom path or test mode path is found, the method iterates through
the default configuration directories, searching for the configuration file.
Returns None if no configuration file is found.
custom_path: str | None A custom path to the configuration file. If None, fallback methods are used to resolve the configuration file location.
str | None The resolved path to the configuration file, or None if no configuration file is found.
SystemCommand
¶
Commands related to the system health.
health(component='both')
¶
Check the health of system components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
str
|
str, optional
The component to check. Acceptable values are
|
'both'
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If component is not one of the accepted values. |