Skip to content

Commit beceb53

Browse files
committed
Merge branch 'main' into argo-cd-corrupt-data-fix-from-main
2 parents ece740f + ea98cd9 commit beceb53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1688
-419
lines changed

Wire.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ import (
155155
repository3 "github.com/devtron-labs/devtron/pkg/pipeline/history/repository"
156156
repository5 "github.com/devtron-labs/devtron/pkg/pipeline/repository"
157157
"github.com/devtron-labs/devtron/pkg/pipeline/types"
158+
"github.com/devtron-labs/devtron/pkg/pipeline/workflowStatus"
159+
repository6 "github.com/devtron-labs/devtron/pkg/pipeline/workflowStatus/repository"
158160
"github.com/devtron-labs/devtron/pkg/plugin"
159161
"github.com/devtron-labs/devtron/pkg/policyGovernance"
160162
resourceGroup2 "github.com/devtron-labs/devtron/pkg/resourceGroup"
@@ -471,6 +473,11 @@ func InitializeApp() (*App, error) {
471473
pipeline.NewCiServiceImpl,
472474
wire.Bind(new(pipeline.CiService), new(*pipeline.CiServiceImpl)),
473475

476+
workflowStatus.NewWorkflowStageFlowStatusServiceImpl,
477+
wire.Bind(new(workflowStatus.WorkFlowStageStatusService), new(*workflowStatus.WorkFlowStageStatusServiceImpl)),
478+
repository6.NewWorkflowStageRepositoryImpl,
479+
wire.Bind(new(repository6.WorkflowStageRepository), new(*repository6.WorkflowStageRepositoryImpl)),
480+
474481
pipelineConfig.NewCiWorkflowRepositoryImpl,
475482
wire.Bind(new(pipelineConfig.CiWorkflowRepository), new(*pipelineConfig.CiWorkflowRepositoryImpl)),
476483

api/bean/UserRequest.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package bean
1919
import (
2020
"encoding/json"
2121
"github.com/devtron-labs/devtron/pkg/auth/user/bean"
22+
"github.com/devtron-labs/devtron/pkg/sql"
2223
"time"
2324
)
2425

@@ -168,3 +169,40 @@ type BulkDeleteRequest struct {
168169
type UserRoleGroup struct {
169170
RoleGroup *RoleGroup `json:"roleGroup"`
170171
}
172+
173+
type GroupPermissionsAuditDto struct {
174+
RoleGroupInfo *RoleGroup `json:"roleGroupInfo,omitempty"`
175+
EntityAudit sql.AuditLog `json:"entityAudit,omitempty"`
176+
}
177+
178+
func NewGroupPermissionsAuditDto() *GroupPermissionsAuditDto {
179+
return &GroupPermissionsAuditDto{}
180+
}
181+
182+
func (pa *GroupPermissionsAuditDto) WithRoleGroupInfo(roleGroupInfo *RoleGroup) *GroupPermissionsAuditDto {
183+
pa.RoleGroupInfo = roleGroupInfo
184+
return pa
185+
}
186+
func (pa *GroupPermissionsAuditDto) WithEntityAudit(entityAudit sql.AuditLog) *GroupPermissionsAuditDto {
187+
pa.EntityAudit = entityAudit
188+
return pa
189+
}
190+
191+
type UserPermissionsAuditDto struct {
192+
UserInfo *UserInfo `json:"userInfo,omitempty"`
193+
EntityAudit sql.AuditLog `json:"entityAudit,omitempty"`
194+
}
195+
196+
func NewUserPermissionsAuditDto() *UserPermissionsAuditDto {
197+
return &UserPermissionsAuditDto{}
198+
}
199+
200+
func (pa *UserPermissionsAuditDto) WithUserInfo(userInfo *UserInfo) *UserPermissionsAuditDto {
201+
pa.UserInfo = userInfo
202+
return pa
203+
}
204+
205+
func (pa *UserPermissionsAuditDto) WithEntityAudit(entityAudit sql.AuditLog) *UserPermissionsAuditDto {
206+
pa.EntityAudit = entityAudit
207+
return pa
208+
}

api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/devtron-labs/devtron/internal/sql/constants"
2626
"github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging"
2727
bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
28+
constants2 "github.com/devtron-labs/devtron/pkg/pipeline/constants"
2829
"github.com/devtron-labs/devtron/util/stringsUtil"
2930
"golang.org/x/exp/maps"
3031
"io"
@@ -45,7 +46,6 @@ import (
4546
"github.com/devtron-labs/devtron/internal/util"
4647
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
4748
"github.com/devtron-labs/devtron/pkg/bean"
48-
"github.com/devtron-labs/devtron/pkg/pipeline"
4949
bean1 "github.com/devtron-labs/devtron/pkg/pipeline/bean"
5050
"github.com/devtron-labs/devtron/pkg/pipeline/types"
5151
resourceGroup "github.com/devtron-labs/devtron/pkg/resourceGroup"
@@ -663,7 +663,7 @@ func (handler *PipelineConfigRestHandlerImpl) validateCiTriggerRBAC(token string
663663
// This is being done for jobs, jobs execute in default-env (devtron-ci) namespace by default. so considering DefaultCiNamespace as env for rbac enforcement
664664
envName := ""
665665
if triggerEnvironmentId == 0 {
666-
envName = pipeline.DefaultCiWorkflowNamespace
666+
envName = constants2.DefaultCiWorkflowNamespace
667667
}
668668
appObject := handler.enforcerUtil.GetAppRBACNameByAppId(ciPipeline.AppId)
669669
workflowObject := handler.enforcerUtil.GetWorkflowRBACByCiPipelineId(ciPipelineId, workflowName)

env_gen.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

env_gen.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
| DEFAULT_TARGET_PLATFORM | string | | | | false |
7777
| DOCKER_BUILD_CACHE_PATH | string |/var/lib/docker | | | false |
7878
| ENABLE_BUILD_CONTEXT | bool |false | | | false |
79+
| ENABLE_WORKFLOW_EXECUTION_STAGE | bool |true | if enabled then we will display build stages separately for CI/Job/Pre-Post CD | true | false |
7980
| EXTERNAL_BLOB_STORAGE_CM_NAME | string |blob-storage-cm | | | false |
8081
| EXTERNAL_BLOB_STORAGE_SECRET_NAME | string |blob-storage-secret | | | false |
8182
| EXTERNAL_CD_NODE_LABEL_SELECTOR | | | | | false |

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ require gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
288288

289289
replace (
290290
github.com/argoproj/argo-workflows/v3 v3.5.10 => github.com/devtron-labs/argo-workflows/v3 v3.5.13
291-
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250130075053-69cdda98e3e2
292-
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250130075053-69cdda98e3e2
291+
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250213085216-b49895a5c8c4
292+
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250213085216-b49895a5c8c4
293293
github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
294294
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5
295295
k8s.io/api => k8s.io/api v0.29.7

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,10 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
792792
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
793793
github.com/devtron-labs/argo-workflows/v3 v3.5.13 h1:3pINq0gXOSeTw2z/vYe+j80lRpSN5Rp/8mfQORh8SmU=
794794
github.com/devtron-labs/argo-workflows/v3 v3.5.13/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA=
795-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250130075053-69cdda98e3e2 h1:8QjRav7pCDb32Pz8HwbS1P8QQJ1QSDb3wJgAmNYkNeU=
796-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250130075053-69cdda98e3e2/go.mod h1:5lv4Wfj5ERhhvDGXe2IeES6qxjvUVCcohaRwKnWBMNo=
797-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250130075053-69cdda98e3e2 h1:8VByFEk14t2z2DDaD/7pTgwSM7zFYEMqfthLWpt2M3w=
798-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250130075053-69cdda98e3e2/go.mod h1:1QJJLpgJSkb5Jm9xPeKAk+kXb0QgBOOOgJj0cgYhAVA=
795+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250213085216-b49895a5c8c4 h1:JMD2Vokncnz4dUjOm3/FfajaW7OgPc6W2zo+XbDFBvQ=
796+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250213085216-b49895a5c8c4/go.mod h1:5lv4Wfj5ERhhvDGXe2IeES6qxjvUVCcohaRwKnWBMNo=
797+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250213085216-b49895a5c8c4 h1:+24669YDx1BSew0KXQnf5UVpjHnL1QHCZPH0UQsM/6o=
798+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250213085216-b49895a5c8c4/go.mod h1:1QJJLpgJSkb5Jm9xPeKAk+kXb0QgBOOOgJj0cgYhAVA=
799799
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
800800
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
801801
github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 h1:xwbTeijNTf4/j1v+tSfwVqwLVnReas/NqEKeQHvSTys=

internal/sql/repository/AppListingRepository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ func (impl AppListingRepositoryImpl) FetchAppsByEnvironmentV2(appListingFilter h
308308

309309
// if any pipeline found get the latest deployment time
310310
if len(pipelineIds) > 0 {
311-
query := impl.appListingRepositoryQueryBuilder.BuildAppListingQueryLastDeploymentTimeV2(pipelineIds)
311+
query, queryParams := impl.appListingRepositoryQueryBuilder.BuildAppListingQueryLastDeploymentTimeV2(pipelineIds)
312312
impl.Logger.Debugw("basic app detail query: ", query)
313313
start := time.Now()
314-
_, err := impl.dbConnection.Query(&lastDeployedTimeDTO, query)
314+
_, err := impl.dbConnection.Query(&lastDeployedTimeDTO, query, queryParams...)
315315
middleware.AppListingDuration.WithLabelValues("buildAppListingQueryLastDeploymentTime", "devtron").Observe(time.Since(start).Seconds())
316316
if err != nil {
317317
impl.Logger.Errorw("error in getting latest deployment time for given pipelines", "err", err, "pipelines", pipelineIds, "query", query)

internal/sql/repository/CiArtifactRepository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ func (impl CiArtifactRepositoryImpl) GetArtifactsByCDPipelineV3(listingFilterOpt
362362
artifactsResp := make([]*CiArtifactWithExtraData, 0, listingFilterOpts.Limit)
363363
var artifacts []*CiArtifact
364364
totalCount := 0
365-
finalQuery := BuildQueryForParentTypeCIOrWebhook(*listingFilterOpts)
366-
_, err := impl.dbConnection.Query(&artifactsResp, finalQuery)
365+
finalQuery, finalQueryParams := BuildQueryForParentTypeCIOrWebhook(*listingFilterOpts)
366+
_, err := impl.dbConnection.Query(&artifactsResp, finalQuery, finalQueryParams...)
367367
if err != nil {
368368
return nil, totalCount, err
369369
}

internal/sql/repository/CiArtifactsListingQueryBuilder.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,28 @@ import (
2020
"fmt"
2121
"github.com/devtron-labs/devtron/api/bean"
2222
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
23+
"github.com/go-pg/pg"
2324
)
2425

2526
const EmptyLikeRegex = "%%"
2627

27-
func BuildQueryForParentTypeCIOrWebhook(listingFilterOpts bean.ArtifactsListFilterOptions) string {
28-
commonPaginatedQueryPart := fmt.Sprintf(" cia.image LIKE '%v'", listingFilterOpts.SearchString)
28+
func BuildQueryForParentTypeCIOrWebhook(listingFilterOpts bean.ArtifactsListFilterOptions) (string, []interface{}) {
29+
commonPaginatedQueryPart, commonPaginatedQueryParams := " cia.image LIKE ?", []interface{}{listingFilterOpts.SearchString}
2930
orderByClause := " ORDER BY cia.id DESC"
30-
limitOffsetQueryPart := fmt.Sprintf(" LIMIT %v OFFSET %v", listingFilterOpts.Limit, listingFilterOpts.Offset)
31+
limitOffsetQueryPart, limitOffsetQueryParams := fmt.Sprintf(" LIMIT ? OFFSET ?"), []interface{}{listingFilterOpts.Limit, listingFilterOpts.Offset}
3132
finalQuery := ""
33+
var finalQueryParams []interface{}
34+
var remainingQueryParams []interface{}
3235
if listingFilterOpts.ParentStageType == bean.CI_WORKFLOW_TYPE {
3336
selectQuery := " SELECT cia.* "
3437
remainingQuery := " FROM ci_artifact cia" +
3538
" INNER JOIN ci_pipeline cp ON (cp.id=cia.pipeline_id or (cp.id=cia.component_id and cia.data_source='post_ci' ) )" +
36-
" INNER JOIN pipeline p ON (p.ci_pipeline_id = cp.id and p.id=%v )" +
39+
" INNER JOIN pipeline p ON (p.ci_pipeline_id = cp.id and p.id=? )" +
3740
" WHERE "
38-
remainingQuery = fmt.Sprintf(remainingQuery, listingFilterOpts.PipelineId)
41+
remainingQueryParams = []interface{}{listingFilterOpts.PipelineId}
3942
if len(listingFilterOpts.ExcludeArtifactIds) > 0 {
40-
remainingQuery += fmt.Sprintf("cia.id NOT IN (%s) AND ", helper.GetCommaSepratedString(listingFilterOpts.ExcludeArtifactIds))
43+
remainingQuery += "cia.id NOT IN (?) AND "
44+
remainingQueryParams = append(remainingQueryParams, pg.In(listingFilterOpts.ExcludeArtifactIds))
4145
}
4246

4347
countQuery := " SELECT count(cia.id) as total_count"
@@ -47,19 +51,24 @@ func BuildQueryForParentTypeCIOrWebhook(listingFilterOpts bean.ArtifactsListFilt
4751
} else if listingFilterOpts.ParentStageType == bean.WEBHOOK_WORKFLOW_TYPE {
4852
selectQuery := " SELECT cia.* "
4953
remainingQuery := " FROM ci_artifact cia " +
50-
" WHERE cia.external_ci_pipeline_id = %v AND "
51-
remainingQuery = fmt.Sprintf(remainingQuery, listingFilterOpts.ParentId)
54+
" WHERE cia.external_ci_pipeline_id = ? AND "
55+
remainingQueryParams = []interface{}{listingFilterOpts.ParentId}
5256
if len(listingFilterOpts.ExcludeArtifactIds) > 0 {
53-
remainingQuery += fmt.Sprintf("cia.id NOT IN (%s) AND ", helper.GetCommaSepratedString(listingFilterOpts.ExcludeArtifactIds))
57+
remainingQuery += "cia.id NOT IN (?) AND "
58+
remainingQueryParams = append(remainingQueryParams, pg.In(listingFilterOpts.ExcludeArtifactIds))
5459
}
5560

5661
countQuery := " SELECT count(cia.id) as total_count"
5762
totalCountQuery := countQuery + remainingQuery + commonPaginatedQueryPart
5863
selectQuery = fmt.Sprintf("%s,(%s) ", selectQuery, totalCountQuery)
5964
finalQuery = selectQuery + remainingQuery + commonPaginatedQueryPart + orderByClause + limitOffsetQueryPart
60-
6165
}
62-
return finalQuery
66+
finalQueryParams = append(finalQueryParams, remainingQueryParams...)
67+
finalQueryParams = append(finalQueryParams, commonPaginatedQueryParams...)
68+
finalQueryParams = append(finalQueryParams, remainingQueryParams...)
69+
finalQueryParams = append(finalQueryParams, commonPaginatedQueryParams...)
70+
finalQueryParams = append(finalQueryParams, limitOffsetQueryParams...)
71+
return finalQuery, finalQueryParams
6372
}
6473

6574
func BuildQueryForArtifactsForCdStage(listingFilterOptions bean.ArtifactsListFilterOptions) string {

internal/sql/repository/helper/AppListingRepositoryQueryBuilder.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,17 @@ func (impl AppListingRepositoryQueryBuilder) TestForCommonAppFilter(appListingFi
160160
return query, queryParams
161161
}
162162

163-
func (impl AppListingRepositoryQueryBuilder) BuildAppListingQueryLastDeploymentTimeV2(pipelineIDs []int) string {
163+
func (impl AppListingRepositoryQueryBuilder) BuildAppListingQueryLastDeploymentTimeV2(pipelineIDs []int) (string, []interface{}) {
164164
whereCondition := ""
165+
queryParams := []interface{}{}
165166
if len(pipelineIDs) > 0 {
166-
whereCondition += fmt.Sprintf(" Where pco.pipeline_id IN (%s) ", GetCommaSepratedString(pipelineIDs))
167+
whereCondition += " Where pco.pipeline_id IN (?) "
168+
queryParams = append(queryParams, pg.In(pipelineIDs))
167169
}
168170
query := "select pco.pipeline_id , MAX(pco.created_on) as last_deployed_time" +
169171
" from pipeline_config_override pco" + whereCondition +
170172
" GROUP BY pco.pipeline_id;"
171-
return query
173+
return query, queryParams
172174
}
173175

174176
func (impl AppListingRepositoryQueryBuilder) GetAppIdsQueryWithPaginationForLastDeployedSearch(appListingFilter AppListingFilter) (string, []interface{}) {

internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package pipelineConfig
1919
import (
2020
"context"
2121
"errors"
22-
"fmt"
2322
apiBean "github.com/devtron-labs/devtron/api/bean"
2423
"github.com/devtron-labs/devtron/client/gitSensor"
2524
"github.com/devtron-labs/devtron/internal/sql/repository"
@@ -41,8 +40,8 @@ type CdWorkflowRepository interface {
4140
FindCdWorkflowMetaByEnvironmentId(appId int, environmentId int, offset int, size int) ([]CdWorkflowRunner, error)
4241
FindCdWorkflowMetaByPipelineId(pipelineId int, offset int, size int) ([]CdWorkflowRunner, error)
4342
FindArtifactByPipelineIdAndRunnerType(pipelineId int, runnerType apiBean.WorkflowType, limit int, runnerStatuses []string) ([]CdWorkflowRunner, error)
44-
SaveWorkFlowRunner(wfr *CdWorkflowRunner) (*CdWorkflowRunner, error)
45-
UpdateWorkFlowRunner(wfr *CdWorkflowRunner) error
43+
SaveWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) (*CdWorkflowRunner, error)
44+
UpdateWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) error
4645
UpdateIsArtifactUploaded(wfrId int, isArtifactUploaded workflow.ArtifactUploadedType) error
4746
GetPreviousQueuedRunners(cdWfrId, pipelineId int) ([]*CdWorkflowRunner, error)
4847
UpdateRunnerStatusToFailedForIds(errMsg string, triggeredBy int32, cdWfrIds ...int) error
@@ -452,14 +451,14 @@ func (impl *CdWorkflowRepositoryImpl) FindLastPreOrPostTriggeredByEnvironmentId(
452451
return wfr, err
453452
}
454453

455-
func (impl *CdWorkflowRepositoryImpl) SaveWorkFlowRunner(wfr *CdWorkflowRunner) (*CdWorkflowRunner, error) {
456-
err := impl.dbConnection.Insert(wfr)
454+
func (impl *CdWorkflowRepositoryImpl) SaveWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) (*CdWorkflowRunner, error) {
455+
err := tx.Insert(wfr)
457456
return wfr, err
458457
}
459458

460-
func (impl *CdWorkflowRepositoryImpl) UpdateWorkFlowRunner(wfr *CdWorkflowRunner) error {
459+
func (impl *CdWorkflowRepositoryImpl) UpdateWorkFlowRunnerWithTx(wfr *CdWorkflowRunner, tx *pg.Tx) error {
461460
wfr.Message = util.GetTruncatedMessage(wfr.Message, 1000)
462-
err := impl.dbConnection.Update(wfr)
461+
err := tx.Update(wfr)
463462
return err
464463
}
465464

@@ -539,10 +538,9 @@ func (impl *CdWorkflowRepositoryImpl) FindBasicWorkflowRunnerById(wfrId int) (*C
539538

540539
func (impl *CdWorkflowRepositoryImpl) FindRetriedWorkflowCountByReferenceId(wfrId int) (int, error) {
541540
retryCount := 0
542-
query := fmt.Sprintf("select count(id) "+
543-
"from cd_workflow_runner where ref_cd_workflow_runner_id = %v", wfrId)
541+
query := "select count(id) from cd_workflow_runner where ref_cd_workflow_runner_id = ?"
544542

545-
_, err := impl.dbConnection.Query(&retryCount, query)
543+
_, err := impl.dbConnection.Query(&retryCount, query, wfrId)
546544
return retryCount, err
547545
}
548546

internal/sql/repository/pipelineConfig/CiWorkflowRepository.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
package pipelineConfig
1818

1919
import (
20-
"fmt"
2120
"github.com/devtron-labs/devtron/internal/sql/constants"
22-
"github.com/devtron-labs/devtron/internal/sql/repository/helper"
2321
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow"
2422
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow"
2523
"github.com/go-pg/pg"
@@ -28,9 +26,9 @@ import (
2826
)
2927

3028
type CiWorkflowRepository interface {
31-
SaveWorkFlow(wf *CiWorkflow) error
29+
SaveWorkFlowWithTx(wf *CiWorkflow, tx *pg.Tx) error
3230
FindLastTriggeredWorkflow(pipelineId int) (*CiWorkflow, error)
33-
UpdateWorkFlow(wf *CiWorkflow) error
31+
UpdateWorkFlowWithTx(wf *CiWorkflow, tx *pg.Tx) error
3432
UpdateArtifactUploaded(id int, isUploaded workflow.ArtifactUploadedType) error
3533
FindByStatusesIn(activeStatuses []string) ([]*CiWorkflow, error)
3634
FindByPipelineId(pipelineId int, offset int, size int) ([]WorkflowWithArtifact, error)
@@ -236,10 +234,9 @@ func (impl *CiWorkflowRepositoryImpl) FindById(id int) (*CiWorkflow, error) {
236234

237235
func (impl *CiWorkflowRepositoryImpl) FindRetriedWorkflowCountByReferenceId(id int) (int, error) {
238236
retryCount := 0
239-
query := fmt.Sprintf("select count(*) "+
240-
"from ci_workflow where ref_ci_workflow_id = %v", id)
237+
query := "select count(*) from ci_workflow where ref_ci_workflow_id = ?"
241238

242-
_, err := impl.dbConnection.Query(&retryCount, query)
239+
_, err := impl.dbConnection.Query(&retryCount, query, id)
243240
return retryCount, err
244241
}
245242

@@ -266,13 +263,13 @@ func (impl *CiWorkflowRepositoryImpl) FindCiWorkflowGitTriggersByIds(ids []int)
266263
return workflows, err
267264
}
268265

269-
func (impl *CiWorkflowRepositoryImpl) SaveWorkFlow(wf *CiWorkflow) error {
270-
err := impl.dbConnection.Insert(wf)
266+
func (impl *CiWorkflowRepositoryImpl) SaveWorkFlowWithTx(wf *CiWorkflow, tx *pg.Tx) error {
267+
err := tx.Insert(wf)
271268
return err
272269
}
273270

274-
func (impl *CiWorkflowRepositoryImpl) UpdateWorkFlow(wf *CiWorkflow) error {
275-
err := impl.dbConnection.Update(wf)
271+
func (impl *CiWorkflowRepositoryImpl) UpdateWorkFlowWithTx(wf *CiWorkflow, tx *pg.Tx) error {
272+
err := tx.Update(wf)
276273
return err
277274
}
278275

@@ -339,9 +336,8 @@ func (impl *CiWorkflowRepositoryImpl) FindLastTriggeredWorkflowGitTriggersByArti
339336
}
340337
query := "SELECT cw.git_triggers,cw.id,cw.triggered_by,cw.ci_pipeline_id,cia.id as ci_artifact_id" +
341338
" FROM ci_workflow cw INNER JOIN ci_artifact cia on cia.ci_workflow_id = cw.id " +
342-
" WHERE cia.id IN (%s)"
343-
query = fmt.Sprintf(query, helper.GetCommaSepratedString(ciArtifactIds))
344-
_, err := impl.dbConnection.Query(&workflows, query)
339+
" WHERE cia.id IN (?)"
340+
_, err := impl.dbConnection.Query(&workflows, query, pg.In(ciArtifactIds))
345341
return workflows, err
346342
}
347343

internal/sql/repository/pipelineConfig/bean/workflow/cdWorkflow/CdWorkflowBean.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/devtron-labs/devtron/client/argocdServer/bean"
77
)
88

9-
var WfrTerminalStatusList = []string{WorkflowAborted, WorkflowFailed, WorkflowSucceeded, bean.HIBERNATING, string(health.HealthStatusHealthy), string(health.HealthStatusDegraded)}
9+
var WfrTerminalStatusList = []string{WorkflowAborted, WorkflowFailed, WorkflowSucceeded, bean.HIBERNATING, string(health.HealthStatusHealthy), string(health.HealthStatusDegraded), WorkflowTimedOut, WorkflowCancel}
1010

1111
type WorkflowStatus int
1212

@@ -34,6 +34,7 @@ const (
3434
WorkflowTypeDeploy = "DEPLOY"
3535
WorkflowTypePre = "PRE"
3636
WorkflowTypePost = "POST"
37+
WorkflowWaitingToStart = "WaitingToStart"
3738
)
3839

3940
func (a WorkflowStatus) String() string {
@@ -60,3 +61,6 @@ type CdWorkflowRunnerArtifactMetadata struct {
6061
ParentCiArtifact int `pg:"parent_ci_artifact"`
6162
Scanned bool `pg:"scanned"`
6263
}
64+
65+
const WorkflowCancel = "CANCELLED"
66+
const POD_DELETED_MESSAGE = "pod deleted"

internal/util/adapter.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package util
2+
3+
func GetApiErrorAdapter(httpStatusCode int, code, userMessage, internalMessage string) *ApiError {
4+
return &ApiError{
5+
HttpStatusCode: httpStatusCode,
6+
Code: code,
7+
UserMessage: userMessage,
8+
InternalMessage: internalMessage,
9+
}
10+
}

0 commit comments

Comments
 (0)