leric opened a new issue, #6077:
URL: https://github.com/apache/incubator-devlake/issues/6077

   ## What and why to refactor
   
   In the CICD domain model, cicd_pipelines table has a field "type" might take 
a value of "DEPLOYMENT" or empty, and a field "environment" could take a value 
"PRODUCTION" or empty. It seem to imply that these two field indicate if this 
pipeline is a deployment, and if it deploy to production environment. But it's 
not. these two fields are intermediate result for some DORA metrics, the real 
"type" and "environment" of a pipeline don't exist.
   
   ## Describe the solution you'd like
   
   As this is in a domain layer table, every field should be a meaningful 
property of an entity, instead of some intermediate result. Some login need to 
apply to these two fields:
   
   1. a pipeline can be identified as DEPLOYMENT and PRODUCTION by itself.
   2. the environment of a pipeline can be set only if the pipeline is a 
deployment, 
   3. if any job of a pipeline is deployment, the pipeline is a deployment
   4. if any job of a deployment pipeline is PRODUCTION, the pipeline is 
PRODUCTION.
   
   In this case, it's just need one more sql update to make 'type' and 
'environment' fields meaningful in cicd_pipelines:
   
   ```sql
   UPDATE cicd_pipelines 
   SET 
        "type"=CASE WHEN "type"='DEPLOYMENT' OR tasks.deployment > 0 THEN 
'DEPLOYMENT' ELSE '' END,
        environment=CASE WHEN ("type"='DEPLOYMENT' OR tasks.deployment > 0) AND 
(environment='PRODUCTION' OR tasks.env > 0) THEN 'PRODUCTION' ELSE '' END
   FROM (
        SELECT pipeline_id, 
                COUNT(1) FILTER (WHERE "type" = 'DEPLOYMENT') AS deployment, 
                COUNT(1) FILTER (WHERE "type" = 'DEPLOYMENT' AND "environment" 
= 'PRODUCTION') AS env
        FROM "cicd_tasks" WHERE cicd_scope_id='gitlab:GitlabProject:1:34262769'
        GROUP BY pipeline_id
   ) AS tasks
   WHERE tasks.pipeline_id=cicd_pipelines."id"
    AND cicd_pipelines.cicd_scope_id='gitlab:GitlabProject:1:34262769';
   ```
   
   
   
   ## Related issues
   Please link any other
   
   ## Additional context
   Add any other context or screenshots about the feature request here.
   


-- 
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