Skip to content

Commit

Permalink
fix: ignore 404s from spam accounts (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m authored Nov 17, 2020
1 parent df09799 commit 701f5a0
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/handle-pull-request-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ async function handlePullRequestChange(app, context) {
return legacyHandler(context);
}

// ignore 404 errors coming from accounts that have been flagged as spam
// by GitHub. API request to their account works, but accessing their account
// on github.com fails.
if (error.status === 404) {
const accountName = repo.owner.login;
const isSpam = await context.github
.request(`HEAD https://github.com/${accountName}`)
.then(
() => false,
() => true
);

if (isSpam) {
context.log.info(`SPAM: Ignoring 404 for account: ${accountName}`);
return;
}
}

throw error;
}
}
53 changes: 53 additions & 0 deletions test/integration/free-plan-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,56 @@ test("Legacy commit status override - has overide (#124)", async function (t) {

t.deepEqual(mock.activeMocks(), []);
});

test("404 from hasStatusChange check (spam)", async function (t) {
const apiMock = nock("https://api.github.com")
// has no plan
.get("/marketplace_listing/accounts/1")
.reply(404)

// check for current status
.get("/repos/wip/app/commits/sha123/check-runs")
.query({
check_name: "WIP",
})
.reply(404);

const dotcomMock = nock("https://github.com").head("/wip").reply(404);

await this.probot.receive(
require("./events/new-pull-request-with-wip-title.json")
);

t.deepEqual(apiMock.activeMocks(), []);
t.deepEqual(dotcomMock.activeMocks(), []);
});

test("404 from hasStatusChange check (not spam)", async function (t) {
const apiMock = nock("https://api.github.com")
// has no plan
.get("/marketplace_listing/accounts/1")
.reply(404)

// check for current status
.get("/repos/wip/app/commits/sha123/check-runs")
.query({
check_name: "WIP",
})
.reply(404);

const dotcomMock = nock("https://github.com").head("/wip").reply(200);

try {
await this.probot.receive(
require("./events/new-pull-request-with-wip-title.json")
);
throw new Error("Should not resolve");
} catch (error) {
const errors = Array.from(error);
t.equal(errors.length, 1);
t.equal(errors[0].status, 404);
}

t.deepEqual(apiMock.activeMocks(), []);
t.deepEqual(dotcomMock.activeMocks(), []);
});

0 comments on commit 701f5a0

Please sign in to comment.