From f2d72cba46e373268d15830d9f125b429379a953 Mon Sep 17 00:00:00 2001 From: Johannes Batzill Date: Wed, 27 Nov 2024 18:16:03 +0000 Subject: [PATCH] fix: [CODE-2631] : fix issue on label unassign activity (#3062) --- app/services/label/label_pullreq.go | 2 +- app/store/database.go | 2 +- app/store/database/label_pullreq.go | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/services/label/label_pullreq.go b/app/services/label/label_pullreq.go index 89a19bef0..736e1e903 100644 --- a/app/services/label/label_pullreq.go +++ b/app/services/label/label_pullreq.go @@ -191,7 +191,7 @@ func (s *Service) UnassignFromPullReq( return nil, nil, err } - value, err := s.pullReqLabelAssignmentStore.FindValueByLabelID(ctx, labelID) + value, err := s.pullReqLabelAssignmentStore.FindValueByLabelID(ctx, pullreqID, labelID) if err != nil && !errors.Is(err, store.ErrResourceNotFound) { return nil, nil, fmt.Errorf("failed to find label value: %w", err) } diff --git a/app/store/database.go b/app/store/database.go index f772f7803..7aa686d5e 100644 --- a/app/store/database.go +++ b/app/store/database.go @@ -1224,7 +1224,7 @@ type ( ) (*types.PullReqLabel, error) // FindValueByLabelID finds a value assigned to a pullreq label. - FindValueByLabelID(ctx context.Context, labelID int64) (*types.LabelValue, error) + FindValueByLabelID(ctx context.Context, pullreqID int64, labelID int64) (*types.LabelValue, error) // ListAssignedByPullreqIDs list labels assigned to specified pullreqs. ListAssignedByPullreqIDs( diff --git a/app/store/database/label_pullreq.go b/app/store/database/label_pullreq.go index f890e8a9f..a19ef150f 100644 --- a/app/store/database/label_pullreq.go +++ b/app/store/database/label_pullreq.go @@ -85,10 +85,10 @@ func (s *pullReqLabelStore) Assign(ctx context.Context, label *types.PullReqLabe ,:pullreq_label_created ,:pullreq_label_updated ,:pullreq_label_created_by - ,:pullreq_label_updated_by + ,:pullreq_label_updated_by ) - ON CONFLICT (pullreq_label_pullreq_id, pullreq_label_label_id) - DO UPDATE SET + ON CONFLICT (pullreq_label_pullreq_id, pullreq_label_label_id) + DO UPDATE SET pullreq_label_label_value_id = EXCLUDED.pullreq_label_label_value_id, pullreq_label_updated = EXCLUDED.pullreq_label_updated, pullreq_label_updated_by = EXCLUDED.pullreq_label_updated_by @@ -147,7 +147,7 @@ func (s *pullReqLabelStore) ListAssigned( pullreqID int64, ) (map[int64]*types.LabelAssignment, error) { const sqlQuery = ` - SELECT + SELECT label_id ,label_repo_id ,label_space_id @@ -224,17 +224,18 @@ func (s *pullReqLabelStore) ListAssignedByPullreqIDs( func (s *pullReqLabelStore) FindValueByLabelID( ctx context.Context, + pullreqID int64, labelID int64, ) (*types.LabelValue, error) { const sqlQuery = `SELECT label_value_id, ` + labelValueColumns + ` FROM pullreq_labels JOIN label_values ON pullreq_label_label_value_id = label_value_id - WHERE pullreq_label_label_id = $1` + WHERE pullreq_label_pullreq_id = $1 AND pullreq_label_label_id = $2` db := dbtx.GetAccessor(ctx, s.db) var dst labelValue - if err := db.GetContext(ctx, &dst, sqlQuery, labelID); err != nil { + if err := db.GetContext(ctx, &dst, sqlQuery, pullreqID, labelID); err != nil { return nil, database.ProcessSQLErrorf(ctx, err, "Failed to find label") }