Skip to content

Commit a15b4d6

Browse files
authored
Merge pull request #6551 from devtron-labs/rollback-for-1st-trigger-issue
fix: Rollback artifact list incorrect after 1st trigger
2 parents 8fbdd88 + d27c90c commit a15b4d6

File tree

2 files changed

+2
-85
lines changed

2 files changed

+2
-85
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,11 +1418,8 @@ func (handler *PipelineConfigRestHandlerImpl) GetArtifactsForRollback(w http.Res
14181418
// rbac for edit tags access
14191419
var ciArtifactResponse bean.CiArtifactResponse
14201420
triggerAccess := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionTrigger, object)
1421-
if handler.pipelineRestHandlerEnvConfig.UseArtifactListApiV2 {
1422-
ciArtifactResponse, err = handler.pipelineBuilder.FetchArtifactForRollbackV2(cdPipelineId, app.Id, offset, limit, searchString, app, deploymentPipeline)
1423-
} else {
1424-
ciArtifactResponse, err = handler.pipelineBuilder.FetchArtifactForRollback(cdPipelineId, app.Id, offset, limit, searchString)
1425-
}
1421+
1422+
ciArtifactResponse, err = handler.pipelineBuilder.FetchArtifactForRollbackV2(cdPipelineId, app.Id, offset, limit, searchString, app, deploymentPipeline)
14261423

14271424
if err != nil {
14281425
handler.Logger.Errorw("service err, GetArtifactsForRollback", "err", err, "cdPipelineId", cdPipelineId)

pkg/pipeline/AppArtifactManager.go

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ import (
4040
type AppArtifactManager interface {
4141
RetrieveArtifactsByCDPipelineV2(pipeline *pipelineConfig.Pipeline, stage bean.WorkflowType, artifactListingFilterOpts *bean.ArtifactsListFilterOptions) (*bean2.CiArtifactResponse, error)
4242

43-
//FetchArtifactForRollback :
44-
FetchArtifactForRollback(cdPipelineId, appId, offset, limit int, searchString string) (bean2.CiArtifactResponse, error)
45-
4643
FetchArtifactForRollbackV2(cdPipelineId, appId, offset, limit int, searchString string, app *bean2.CreateAppDTO, deploymentPipeline *pipelineConfig.Pipeline) (bean2.CiArtifactResponse, error)
4744

4845
BuildArtifactsForCdStage(pipelineId int, stageType bean.WorkflowType, ciArtifacts []bean2.CiArtifactBean, artifactMap map[int]int, parent bool, limit int, parentCdId int) ([]bean2.CiArtifactBean, map[int]int, int, string, error)
@@ -212,83 +209,6 @@ func (impl *AppArtifactManagerImpl) BuildArtifactsForCIParent(cdPipelineId int,
212209
return ciArtifacts, nil
213210
}
214211

215-
func (impl *AppArtifactManagerImpl) FetchArtifactForRollback(cdPipelineId, appId, offset, limit int, searchString string) (bean2.CiArtifactResponse, error) {
216-
var deployedCiArtifacts []bean2.CiArtifactBean
217-
var deployedCiArtifactsResponse bean2.CiArtifactResponse
218-
219-
cdWfrs, err := impl.cdWorkflowRepository.FetchArtifactsByCdPipelineId(cdPipelineId, bean.CD_WORKFLOW_TYPE_DEPLOY, offset, limit, searchString)
220-
if err != nil {
221-
impl.logger.Errorw("error in getting artifacts for rollback by cdPipelineId", "err", err, "cdPipelineId", cdPipelineId)
222-
return deployedCiArtifactsResponse, err
223-
}
224-
var ids []int32
225-
for _, item := range cdWfrs {
226-
ids = append(ids, item.TriggeredBy)
227-
}
228-
userEmails := make(map[int32]string)
229-
users, err := impl.userService.GetByIds(ids)
230-
if err != nil {
231-
impl.logger.Errorw("unable to fetch users by ids", "err", err, "ids", ids)
232-
}
233-
for _, item := range users {
234-
userEmails[item.Id] = item.EmailId
235-
}
236-
237-
imageTagsDataMap, err := impl.imageTaggingService.GetTagsDataMapByAppId(appId)
238-
if err != nil {
239-
impl.logger.Errorw("error in getting image tagging data with appId", "err", err, "appId", appId)
240-
return deployedCiArtifactsResponse, err
241-
}
242-
artifactIds := make([]int, 0)
243-
244-
for _, cdWfr := range cdWfrs {
245-
ciArtifact := &repository.CiArtifact{}
246-
if cdWfr.CdWorkflow != nil && cdWfr.CdWorkflow.CiArtifact != nil {
247-
ciArtifact = cdWfr.CdWorkflow.CiArtifact
248-
}
249-
if ciArtifact == nil {
250-
continue
251-
}
252-
mInfo, err := parseMaterialInfo([]byte(ciArtifact.MaterialInfo), ciArtifact.DataSource)
253-
if err != nil {
254-
mInfo = []byte("[]")
255-
impl.logger.Errorw("error in parsing ciArtifact material info", "err", err, "ciArtifact", ciArtifact)
256-
}
257-
userEmail := userEmails[cdWfr.TriggeredBy]
258-
deployedCiArtifacts = append(deployedCiArtifacts, bean2.CiArtifactBean{
259-
Id: ciArtifact.Id,
260-
Image: ciArtifact.Image,
261-
MaterialInfo: mInfo,
262-
DeployedTime: formatDate(cdWfr.StartedOn, bean2.LayoutRFC3339),
263-
WfrId: cdWfr.Id,
264-
DeployedBy: userEmail,
265-
})
266-
artifactIds = append(artifactIds, ciArtifact.Id)
267-
}
268-
imageCommentsDataMap, err := impl.imageTaggingService.GetImageCommentsDataMapByArtifactIds(artifactIds)
269-
if err != nil {
270-
impl.logger.Errorw("error in getting GetImageCommentsDataMapByArtifactIds", "err", err, "appId", appId, "artifactIds", artifactIds)
271-
return deployedCiArtifactsResponse, err
272-
}
273-
274-
for i, _ := range deployedCiArtifacts {
275-
if imageTaggingResp := imageTagsDataMap[deployedCiArtifacts[i].Id]; imageTaggingResp != nil {
276-
deployedCiArtifacts[i].ImageReleaseTags = imageTaggingResp
277-
}
278-
if imageCommentResp := imageCommentsDataMap[deployedCiArtifacts[i].Id]; imageCommentResp != nil {
279-
deployedCiArtifacts[i].ImageComment = imageCommentResp
280-
}
281-
}
282-
283-
deployedCiArtifactsResponse.CdPipelineId = cdPipelineId
284-
if deployedCiArtifacts == nil {
285-
deployedCiArtifacts = []bean2.CiArtifactBean{}
286-
}
287-
deployedCiArtifactsResponse.CiArtifacts = deployedCiArtifacts
288-
289-
return deployedCiArtifactsResponse, nil
290-
}
291-
292212
func (impl *AppArtifactManagerImpl) FetchArtifactForRollbackV2(cdPipelineId, appId, offset, limit int, searchString string, app *bean2.CreateAppDTO, deploymentPipeline *pipelineConfig.Pipeline) (bean2.CiArtifactResponse, error) {
293213
var deployedCiArtifactsResponse bean2.CiArtifactResponse
294214
imageTagsDataMap, err := impl.imageTaggingService.GetTagsDataMapByAppId(appId)

0 commit comments

Comments
 (0)