fix: [CODE-2631] : fix issue on label unassign activity (#3062)

This commit is contained in:
Johannes Batzill 2024-11-27 18:16:03 +00:00 committed by Harness
parent 1c0e049151
commit f2d72cba46
3 changed files with 9 additions and 8 deletions

View File

@ -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)
}

View File

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

View File

@ -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")
}