chenwei791129 opened a new pull request, #9228:
URL: https://github.com/apache/devlake/pull/9228

   ### Summary
   
   Validate metric plugin options when a project is created or updated, instead 
of only when a pipeline plan
   is generated.
   
   - `refactor(project)`: extract the single-metric plan generation of 
`GeneratePlanJsonV200` into
     `makeMetricPluginPlan`. No behavior change; it lets plan generation and 
save-time validation share the
     same rules (e.g. empty options default to `{}`).
   - `fix(project)`: `CreateProject` and `PatchProject` call 
`validateProjectMetrics` before opening the
     transaction or touching the database. It dry-runs 
`MakeMetricPluginPipelinePlanV200` for every
     **enabled** metric, discards the plan, and returns `errors.BadInput` (HTTP 
400)
     `invalid options for metric plugin <name>` wrapping the plugin's error.
     - Disabled metrics are skipped, matching `MakePlanForBlueprint` (the 
Settings page always sends every
       metric, with `enable: false` for disabled ones).
     - An enabled metric whose plugin is not loaded or does not implement 
`MetricPluginBlueprintV200` is
       rejected too, since plan generation would fail on it anyway.
     - `PatchProject` validates with the post-save project name (the new name 
on rename).
   - Update the monorepo comment that claimed a bad regex is reported "when the 
blueprint is saved".
   
   No Config UI change: the Save button already shows the API error as a toast 
and the settings are not
   stored.
   
   ### Does this close any open issues?
   
   Closes #9227
   
   ### Screenshots
   
   N/A — backend only.
   
   ### Other Information
   
   **Compatibility**
   
   - `POST /projects` / `PATCH /projects/:projectName` now return 400 instead 
of 2xx when an enabled metric
     has invalid options (e.g. an invalid monorepo `deployJobPattern`, or 
monorepo enabled with no
     `subProjects`). Such requests previously stored settings that broke the 
next pipeline run.
   - Invalid settings already stored in the database are not affected until the 
project is saved again;
     no migration.
   
   **Tests**
   
   New `backend/server/services/project_metric_validation_test.go`:
   
   - valid options pass; empty options reach the plugin as `{}`;
   - a plugin error becomes `BadInput` and keeps the original error in the 
chain;
   - disabled and `nil` metrics are never invoked;
   - unknown / non-metric plugins are rejected;
   - `CreateProject` and `PatchProject` reject invalid options with a DAL mock 
that has no expectations,
     proving nothing is written and no transaction is opened; `PatchProject` 
uses the new name on rename
     and the current name otherwise.
   
   `go test ./server/services/...` plus the dora / linker / issue_trace / 
monorepo unit tests pass;
   `golangci-lint run ./server/...` is clean.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to