From e46ff694a3ffd76a78e555960875d0d7a91714d7 Mon Sep 17 00:00:00 2001 From: bcoe Date: Mon, 29 Mar 2021 18:42:04 -0700 Subject: [PATCH 1/2] fix(failurechecker): check that PR returned has labels --- packages/failurechecker/src/failurechecker.ts | 7 +++ .../failurechecker/test/failurechecker.ts | 58 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/packages/failurechecker/src/failurechecker.ts b/packages/failurechecker/src/failurechecker.ts index 12c46c8b841..fac365a4071 100644 --- a/packages/failurechecker/src/failurechecker.ts +++ b/packages/failurechecker/src/failurechecker.ts @@ -19,6 +19,7 @@ // eslint-disable-next-line node/no-extraneous-import import {Probot, ProbotOctokit} from 'probot'; import {logger} from 'gcf-utils'; +import { SlowBuffer } from 'node:buffer'; type OctokitType = InstanceType; @@ -103,8 +104,14 @@ export function failureChecker(app: Probot) { ).data; if ( pr.merged_at && + pr.labels.some(l => labels.includes(l.name!)) && !pr.labels.some(l => l.name === SUCCESSFUL_PUBLISH_LABEL) ) { + logger.info( + `found failure for ${owner}/${repo} pr = ${ + pr.number + } labels = ${labels.join(',')}` + ); failed.push(pr.number); } } diff --git a/packages/failurechecker/test/failurechecker.ts b/packages/failurechecker/test/failurechecker.ts index 6d6061e7f33..4cda4afb557 100644 --- a/packages/failurechecker/test/failurechecker.ts +++ b/packages/failurechecker/test/failurechecker.ts @@ -695,4 +695,62 @@ describe('failurechecker', () => { }); requests.done(); }); + it('does not open a failure issue if PR is missing appropriate labels', async () => { + const requests = nock('https://api.github.com') + .get('/repos/bcoe/nodejs-foo/contents/.github%2Frelease-please.yml') + .reply( + 200, + Buffer.from( + JSON.stringify({ + releaseType: 'node', + }) + ) + ) + .get( + '/repos/googleapis/nodejs-foo/issues?labels=autorelease%3A%20pending&state=closed&sort=updated&direction=desc&per_page=16' + ) + .reply(200, [ + { + number: 33, + updated_at: '2020-01-30T13:33:48Z', + }, + ]) + .get( + '/repos/googleapis/nodejs-foo/issues?labels=autorelease%3A%20tagged&state=closed&sort=updated&direction=desc&per_page=16' + ) + .reply(200, []) + .get( + '/repos/googleapis/nodejs-foo/issues?labels=autorelease%3A%20failed&state=closed&sort=updated&direction=desc&per_page=16' + ) + .reply(200, []) + .get( + '/repos/googleapis/nodejs-foo/issues?labels=type%3A%20process&per_page=32' + ) + .reply(200, []) + .get('/rate_limit') + .reply(200, {}) + .get('/repos/googleapis/nodejs-foo/pulls/33') + .reply(200, { + number: 33, + merged_at: '2020-01-30T13:33:48Z', + labels: [], + }); + + await probot.receive({ + name: 'schedule.repository' as '*', + payload: { + repository: { + name: 'nodejs-foo', + owner: { + login: 'bcoe', + }, + }, + organization: { + login: 'googleapis', + }, + }, + id: 'abc123', + }); + requests.done(); + }); }); From 7f52052a722349c5bacc4091a785113f6f098a0c Mon Sep 17 00:00:00 2001 From: bcoe Date: Mon, 29 Mar 2021 18:44:11 -0700 Subject: [PATCH 2/2] chore: remove typo --- packages/failurechecker/src/failurechecker.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/failurechecker/src/failurechecker.ts b/packages/failurechecker/src/failurechecker.ts index fac365a4071..175cb3ed87b 100644 --- a/packages/failurechecker/src/failurechecker.ts +++ b/packages/failurechecker/src/failurechecker.ts @@ -19,7 +19,6 @@ // eslint-disable-next-line node/no-extraneous-import import {Probot, ProbotOctokit} from 'probot'; import {logger} from 'gcf-utils'; -import { SlowBuffer } from 'node:buffer'; type OctokitType = InstanceType;