diff --git a/lib/platform/gitlab/index.js b/lib/platform/gitlab/index.js index 52d69e2ff24842e9a2f88683c9e8322bd1654b2c..af0549c3dba99a44dd780fb8da1b87c7f535fd65 100644 --- a/lib/platform/gitlab/index.js +++ b/lib/platform/gitlab/index.js @@ -242,10 +242,12 @@ async function getBranchStatus(branchName, requiredStatusChecks) { res.body.forEach(check => { // If one is failed then don't overwrite that if (status !== 'failure') { - if (check.status === 'failed') { - status = 'failure'; - } else if (check.status !== 'success') { - ({ status } = check); + if (!check.allow_failure) { + if (check.status === 'failed') { + status = 'failure'; + } else if (check.status !== 'success') { + ({ status } = check); + } } } }); diff --git a/test/platform/gitlab/index.spec.js b/test/platform/gitlab/index.spec.js index cfc9d94cf91945c1d6ef5d46f3526ada3e035f80..a2015e606b436a495c0ee6f420b516ea485b3006 100644 --- a/test/platform/gitlab/index.spec.js +++ b/test/platform/gitlab/index.spec.js @@ -308,9 +308,23 @@ describe('platform/gitlab', () => { const res = await gitlab.getBranchStatus('somebranch', []); expect(res).toEqual('success'); }); - it('returns failure if any are failed', async () => { + it('returns success if optional jobs fail', async () => { get.mockReturnValueOnce({ - body: [{ status: 'success' }, { status: 'failed' }], + body: [ + { status: 'success' }, + { status: 'failed', allow_failure: true }, + ], + }); + const res = await gitlab.getBranchStatus('somebranch', []); + expect(res).toEqual('success'); + }); + it('returns failure if any mandatory jobs fails', async () => { + get.mockReturnValueOnce({ + body: [ + { status: 'success' }, + { status: 'failed', allow_failure: true }, + { status: 'failed' }, + ], }); const res = await gitlab.getBranchStatus('somebranch', []); expect(res).toEqual('failure');