Skip to content

Commit 18a2168

Browse files
committed
fix: reset inactive reason on open
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent c89142f commit 18a2168

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

services/libs/data-access-layer/src/osspckgs/stewardships.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,29 @@ export async function openStewardshipByPurl(
125125
WITH pkg AS (
126126
SELECT id FROM packages WHERE purl = $(purl) LIMIT 1
127127
),
128+
prev AS (
129+
SELECT s.status AS old_status
130+
FROM stewardships s
131+
WHERE s.package_id = (SELECT id FROM pkg)
132+
),
128133
upserted AS (
129134
INSERT INTO stewardships (package_id, status, origin, opened_at, last_status_at)
130135
SELECT id, 'open', 'opened_for_claim', NOW(), NOW()
131136
FROM pkg
132137
ON CONFLICT (package_id) DO UPDATE
133-
SET status = 'open',
134-
opened_at = COALESCE(stewardships.opened_at, NOW()),
135-
last_status_at = NOW(),
136-
updated_at = NOW()
138+
SET status = 'open',
139+
opened_at = COALESCE(stewardships.opened_at, NOW()),
140+
last_status_at = NOW(),
141+
inactive_reason = NULL,
142+
updated_at = NOW()
137143
RETURNING id, package_id, status, origin, version, opened_at,
138144
last_status_at, inactive_reason, created_at, updated_at
139145
),
140146
_log AS (
141147
INSERT INTO stewardship_activity (stewardship_id, actor_user_id, actor_type, activity_type, content)
142-
SELECT id, $(actorUserId), 'user', 'state_changed', 'Opened for stewardship'
148+
SELECT upserted.id, $(actorUserId), 'user', 'state_changed', 'Opened for stewardship'
143149
FROM upserted
150+
WHERE NOT EXISTS (SELECT 1 FROM prev WHERE prev.old_status = 'open')
144151
)
145152
SELECT * FROM upserted
146153
`,

0 commit comments

Comments
 (0)