Ownership Assignment
Relevant source files
The following files were used as context for generating this wiki page:- iac-recert-engine/internal/assign/resolver.go
- iac-recert-engine/internal/scan/git_history.go
- iac-recert-engine/internal/config/types.go
- iac-recert-engine/example.config.yaml
- iac-recert-engine/internal/engine/engine.go
- iac-recert-engine/internal/types/types.go
- iac-recert-engine/internal/assign/resolver_test.go
- iac-recert-engine/internal/plugin/plugin.go
The Ownership Assignment module is responsible for determining who should be assigned the pull requests generated for file recertification. After files requiring recertification are identified and grouped, the Resolver component applies a configured strategy to select appropriate assignees. This ensures that recertification tasks are routed to the correct individuals or teams based on predefined logic.
The assignment process is a critical step within the main engine's run cycle, occurring after files have been grouped and before a pull request is created. The outcome of the resolver is an AssignmentResult containing lists of assignees and reviewers, which is then used to populate the final pull request.
Sources: iac-recert-engine/internal/engine/engine.go:121-125, iac-recert-engine/internal/assign/resolver.go:26-28
Architecture and Data Flow
The Engine orchestrates the overall process. It initializes an assign.Resolver with the assignment configuration and a plugin manager. During the processing of each FileGroup, the engine invokes the resolver.Resolve method, passing the group of files. The resolver then executes the configured assignment strategy and returns an AssignmentResult, which the engine uses to configure the pull request.
Sources: iac-recert-engine/internal/engine/engine.go:57-59, iac-recert-engine/internal/engine/engine.go:121-125
The following diagram illustrates the data flow for the assignment resolution process.
Configuration
Ownership assignment is configured in the assignment section of the main config.yaml file. This configuration is mapped to the AssignmentConfig struct.
Sources: iac-recert-engine/example.config.yaml:63-74, iac-recert-engine/internal/config/types.go:58-65
assignment Configuration Block
| Key | Type | Description | Required |
|---|---|---|---|
strategy | string | The assignment strategy to use. Options: static, last_committer, plugin, composite. | Yes |
rules | []AssignmentRule | A list of rules used by the composite strategy. | No |
fallback_assignees | []string | A list of default assignees if a strategy fails or no rule matches. | No |
Sources: iac-recert-engine/internal/config/types.go:58-65, iac-recert-engine/example.config.yaml:63-74
AssignmentRule Configuration
| Key | Type | Description | Required |
|---|---|---|---|
pattern | string | A glob pattern to match against file paths. | Yes |
strategy | string | The strategy to apply for files matching the pattern. Options: static, last_committer, plugin. | Yes |
plugin | string | The name of the plugin to use if strategy is plugin. | No |
fallback_assignees | []string | Assignees to use for this rule, particularly for the static strategy. | No |
Sources: iac-recert-engine/internal/config/types.go:67-73, iac-recert-engine/example.config.yaml:65-71
Example Configuration
# Assignment Strategy
# Options: static, last_committer, plugin, composite
assignment:
strategy: "composite"
rules:
- pattern: "terraform/prod/**"
strategy: "static"
fallback_assignees: ["infra-team"]
- pattern: "k8s/**"
strategy: "last_committer"
# Default assignees if no rule matches or strategy fails
fallback_assignees:
- "devops-team"
Sources: iac-recert-engine/example.config.yaml:63-74
Assignment Strategies
The Resolver implements several strategies to determine ownership. The strategy is selected based on the assignment.strategy field in the configuration.
Sources: iac-recert-engine/internal/assign/resolver.go:68-96
static
This is the simplest strategy. It assigns the pull request to the list of users defined in the fallback_assignees configuration key.
// from internal/assign/resolver.go
case "static":
result := types.AssignmentResult{
Assignees: r.cfg.FallbackAssignees,
}
r.logger.Debug("assigned using static strategy", zap.Strings("assignees", result.Assignees))
return result, nil
Sources: iac-recert-engine/internal/assign/resolver.go:70-75, iac-recert-engine/internal/config/types.go:64
last_committer
This strategy identifies the author of the most recent commit across all files within the FileGroup. It iterates through each file, compares their LastModified timestamps, and selects the CommitAuthor associated with the latest timestamp. If no author can be determined, the assignment will be empty.
The file history, including the author and modification date, is enriched by the HistoryAnalyzer before the assignment phase.
Sources: iac-recert-engine/internal/assign/resolver.go:76-90, iac-recert-engine/internal/scan/git_history.go:29-45, iac-recert-engine/internal/assign/resolver_test.go:49-68
The following diagram shows the logic for the last_committer strategy.
composite
The composite strategy is designed to apply different assignment rules based on file paths. It uses the rules list from the configuration. However, the current implementation does not perform pattern matching against the files in the group. It logs a debug message and defaults to using the global fallback_assignees.
Note: The implementation for composite strategy is incomplete and currently falls back to the default behavior.
Sources: iac-recert-engine/internal/assign/resolver.go:47-67, iac-recert-engine/example.config.yaml:64-71
plugin
The plugin strategy is intended to delegate assignment logic to an external or registered plugin. The Resolver is initialized with a PluginManager, but the logic to invoke an assignment plugin is not implemented. If this strategy is selected, the resolver will return an error.
Note: The plugin assignment strategy is not implemented.
Sources: iac-recert-engine/internal/assign/resolver.go:91-94, iac-recert-engine/internal/plugin/plugin.go:48-52
Data Structures
The assignment process revolves around a few key data structures.
| Struct | File | Description |
|---|---|---|
AssignmentConfig | internal/config/types.go | Holds the assignment configuration from config.yaml. |
FileGroup | internal/types/types.go | Represents a collection of files that will be handled in a single PR. |
FileInfo | internal/types/types.go | Contains enriched data about a single file, including commit author and modification date. |
AssignmentResult | internal/types/types.go | The output of the resolver, containing the list of assignees and reviewers. |
Sources: iac-recert-engine/internal/config/types.go, iac-recert-engine/internal/types/types.go
AssignmentResult
This struct encapsulates the output of the assignment resolution.
// from internal/types/types.go
type AssignmentResult struct {
Assignees []string
Reviewers []string
Team string
Priority string
}