diff --git a/lib/modules/platform/gitea/gitea-helper.spec.ts b/lib/modules/platform/gitea/gitea-helper.spec.ts index 9f06e6750abf06c7bb3576ff7b8f9457a87e8be2..e3680f6d11978dcfb3eea5fd47e1a6ad468c0663 100644 --- a/lib/modules/platform/gitea/gitea-helper.spec.ts +++ b/lib/modules/platform/gitea/gitea-helper.spec.ts @@ -685,37 +685,41 @@ describe('modules/platform/gitea/gitea-helper', () => { }); it('should properly determine worst commit status', async () => { - const statuses: { - status: CommitStatusType; - created_at: string; + const statuses: (Pick<CommitStatus, 'id' | 'status' | 'created_at'> & { expected: CommitStatusType; - }[] = [ + })[] = [ { + id: 122, status: 'unknown', created_at: '2020-03-25T01:00:00Z', expected: 'unknown', }, { + id: 124, status: 'pending', created_at: '2020-03-25T03:00:00Z', expected: 'pending', }, { + id: 125, status: 'warning', created_at: '2020-03-25T04:00:00Z', expected: 'warning', }, { + id: 126, status: 'failure', created_at: '2020-03-25T05:00:00Z', expected: 'failure', }, { + id: 123, status: 'success', created_at: '2020-03-25T02:00:00Z', expected: 'failure', }, { + id: 127, status: 'success', created_at: '2020-03-25T06:00:00Z', expected: 'success', @@ -726,13 +730,13 @@ describe('modules/platform/gitea/gitea-helper', () => { { ...mockCommitStatus, status: 'unknown' }, ]; - for (const statusElem of statuses) { - const { status, expected } = statusElem; + for (const { id, status, expected, created_at } of statuses) { // Add current status ot list of commit statuses, then mock the API to return the whole list commitStatuses.push({ ...mockCommitStatus, + id, status, - created_at: statusElem.created_at, + created_at, }); httpMock .scope(baseUrl) diff --git a/lib/modules/platform/gitea/gitea-helper.ts b/lib/modules/platform/gitea/gitea-helper.ts index 2514faf3e746721600143db02ecc4a66798866c0..84a8025010f8379e4964ab0e69ceba3898d09849 100644 --- a/lib/modules/platform/gitea/gitea-helper.ts +++ b/lib/modules/platform/gitea/gitea-helper.ts @@ -394,10 +394,7 @@ export const renovateToGiteaStatusMapping: Record< function filterStatus(data: CommitStatus[]): CommitStatus[] { const ret: Record<string, CommitStatus> = {}; for (const i of data) { - if ( - !ret[i.context] || - new Date(ret[i.context].created_at) < new Date(i.created_at) - ) { + if (!ret[i.context] || ret[i.context].id < i.id) { ret[i.context] = i; } } @@ -418,13 +415,14 @@ export async function getCombinedCommitStatus( }); let worstState = 0; - for (const cs of filterStatus(res.body)) { + const statuses = filterStatus(res.body); + for (const cs of statuses) { worstState = Math.max(worstState, commitStatusStates.indexOf(cs.status)); } return { worstStatus: commitStatusStates[worstState], - statuses: res.body, + statuses, }; } diff --git a/lib/modules/platform/gitea/types.ts b/lib/modules/platform/gitea/types.ts index cf4fb50b22645b6b41014b035c6728a8e3f2168f..9a20bad14708fe4e523c8c43f9147ef27f1275b4 100644 --- a/lib/modules/platform/gitea/types.ts +++ b/lib/modules/platform/gitea/types.ts @@ -138,8 +138,8 @@ export interface CommitStatus { id: number; status: CommitStatusType; context: string; - description: string; - target_url: string; + description?: string; + target_url?: string; created_at: string; }