PR/MR Generation
Relevant source files
The following files were used as context for generating this wiki page:- iac-recert-engine/internal/pr/generator.go
- iac-recert-engine/internal/engine/engine.go
- iac-recert-engine/internal/types/types.go
- iac-recert-engine/internal/config/types.go
- iac-recert-engine/example.config.yaml
- iac-recert-engine/internal/provider/github.go
- iac-recert-engine/internal/provider/gitlab.go
- iac-recert-engine/internal/provider/azure.go
The Pull Request (PR) or Merge Request (MR) generation is the final, action-oriented stage of the iac-recert-engine workflow. After scanning files, checking their recertification status, and grouping them according to a defined strategy, the engine generates PRs/MRs to assign the review and recertification task to the appropriate individuals or teams. This process involves creating a new branch, committing file changes (if decorators are used), and opening a PR/MR with a templated title and description against the repository's base branch.
The entire process is orchestrated by the Engine, which uses a pr.Generator to create the PR content, an assign.Resolver to determine assignees, and a provider.GitProvider to interact with the Git service API (e.g., GitHub, GitLab). The generation can be disabled for a "dry run" via a global configuration flag.
Sources: iac-recert-engine/internal/engine/engine.go:142-258, iac-recert-engine/example.config.yaml:7-10
Configuration
The content and format of the generated PR/MR are controlled by the pr_template section in the main configuration file. This allows for customization of the title and body to fit organizational standards.
Sources: iac-recert-engine/example.config.yaml:70-76, iac-recert-engine/internal/config/types.go:88-93
pr_template Options
The following table details the configuration options available under pr_template.
| Option | Type | Description |
|---|---|---|
title | string | Required. The template for the PR/MR title. Supports placeholders like {pattern_name} and {file_count}. |
include_file_list | boolean | If true, a markdown table of files needing recertification will be included in the PR/MR description. |
include_checklist | boolean | If true, a generic review checklist is added to the PR/MR description. |
custom_instructions | string | A custom string of instructions to be appended to the PR/MR description. |
Sources: iac-recert-engine/internal/config/types.go:89-92, iac-recert-engine/internal/pr/generator.go:20-56
Example Configuration
# iac-recert-engine/example.config.yaml
pr_template:
title: "🔄 Recertification: {pattern_name}"
include_file_list: true
include_checklist: true
custom_instructions: |
Please review these files for security and compliance.
If they are no longer needed, please delete them.
Sources: iac-recert-engine/example.config.yaml:70-76
PR/MR Generation Flow
The generation process is a multi-step sequence coordinated by the Engine's processGroup method. For each group of files identified for recertification, the engine executes the following steps.
This diagram illustrates the sequence of operations within the engine for a single file group.
Core Components
pr.Generator
The pr.Generator is responsible for constructing the PRConfig object, which contains the title, description, and branch name for the new PR/MR.
Sources: iac-recert-engine/internal/pr/generator.go:10-14
Generation Logic
The Generate method performs the following actions:
- Title Generation: It takes the
titletemplate from the configuration and replaces placeholders like{pattern_name}and{file_count}. - Description Generation: It builds the PR body by conditionally adding:
- A standard header.
- A list of files in a markdown table (
include_file_list). - A review checklist (
include_checklist). - Custom instructions (
custom_instructions).
- Branch Naming: It generates a unique branch name based on the group ID, following the format
recert/{group.ID}.
Sources: iac-recert-engine/internal/pr/generator.go:16-63
This diagram shows the inputs and outputs of the pr.Generator.
engine.Engine
The Engine orchestrates the entire PR creation lifecycle. After the pr.Generator creates the initial PRConfig, the engine enriches it with assignees/reviewers from the assign.Resolver and the default_base_branch from global settings. It then interacts with the configured GitProvider to perform the necessary Git operations.
Sources: iac-recert-engine/internal/engine/engine.go:175-188
provider.GitProvider
This interface abstracts the communication with different Git hosting services. The Engine calls methods on this interface to create branches, commits, and pull requests.
The following sequence diagram shows the interactions between the main components during PR generation.
Data Structures
The PR generation process relies on several key data structures.
PRConfig and Related Types
This class diagram shows the relationship between the configuration and result types. FileGroup contains the files to be recertified, which informs the PRConfig used to create a PullRequest.
The PRConfig struct holds all the necessary information for the GitProvider to create a pull request.
| Field | Type | Description |
|---|---|---|
Title | string | The title of the pull request. |
Description | string | The body/description of the pull request. |
Branch | string | The name of the head branch (source of changes). |
BaseBranch | string | The name of the base branch (target of the PR). |
Files | []string | A list of files included in the PR (informational). |
Assignees | []string | A list of user logins to assign to the PR. |
Reviewers | []string | A list of user logins to request reviews from. |
Labels | []string | A list of labels to apply to the PR. |
Sources: iac-recert-engine/internal/types/types.go:45-53
Provider-Specific Implementations
The iac-recert-engine supports multiple Git providers. However, the implementation level for PR/MR creation features varies.
| Feature | github.go | gitlab.go | azure.go |
|---|---|---|---|
CreateBranch | ✅ Implemented | ✅ Implemented | ❌ Not Implemented |
CreateCommit | ✅ Implemented | ❌ Not Implemented | ❌ Not Implemented |
CreatePullRequest | ✅ Implemented | ✅ Implemented | ✅ Implemented |
AssignPullRequest | ✅ Implemented (via CreatePullRequest) | ❌ Not Implemented (user ID resolution needed) | ❌ Not Implemented |
RequestReviewers | ✅ Implemented (via CreatePullRequest) | ❌ Not Supported | ❌ Not Implemented |
AddLabels | ✅ Implemented (via CreatePullRequest) | ✅ Implemented | ❌ Not Implemented |
Sources: iac-recert-engine/internal/provider/github.go, iac-recert-engine/internal/provider/gitlab.go, iac-recert-engine/internal/provider/azure.go