Detect a hardcoded list of bots (#718)

This commit adds a hardcoded list of known bots. Building on #713, it
categorizes those userlikes with the bot subtype. (Note that those users
may not be bots in the GitHub ontology - GitHub doesn't actually have a
clear record of which userlikes are bots.)

Progress towards #696.

Test plan:
Observe the single snapshot change, which demonstrates that @credbot is
now correctly categorized as a bot.
This commit is contained in:
Dandelion Mané 2018-08-29 15:01:48 -07:00 committed by GitHub
parent 761b5a0875
commit 96d08dc97f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 5 deletions

View File

@ -15,7 +15,7 @@ Array [
"AUTHORS", "AUTHORS",
"3", "3",
"USERLIKE", "USERLIKE",
"USER", "BOT",
"credbot", "credbot",
"6", "6",
"COMMENT", "COMMENT",
@ -1633,7 +1633,7 @@ Array [
"sourcecred", "sourcecred",
"github", "github",
"USERLIKE", "USERLIKE",
"USER", "BOT",
"credbot", "credbot",
], ],
Array [ Array [

View File

@ -0,0 +1,19 @@
// @flow
// TODO(#638): Allow projects to specify bots via configuration,
// rather than depending on this single souce of truth
export function botSet(): Set<string> {
return new Set([
"credbot",
"facebook-github-bot",
"gitcoinbot",
"googlebot",
"greenkeeper",
"greenkeeperio-bot",
"metamaskbot",
"nodejs-github-bot",
"stickler-ci",
"tensorflow-jenkins",
"tensorflowbutler",
]);
}

View File

@ -25,6 +25,7 @@ import type {
} from "./graphql"; } from "./graphql";
import * as GitNode from "../git/nodes"; import * as GitNode from "../git/nodes";
import * as MapUtil from "../../util/map"; import * as MapUtil from "../../util/map";
import {botSet} from "./bots";
import { import {
reviewUrlToId, reviewUrlToId,
@ -342,11 +343,12 @@ export class RelationalView {
if (json == null) { if (json == null) {
return []; return [];
} else { } else {
const login = json.login;
const subtype = botSet().has(login) ? N.BOT_SUBTYPE : N.USER_SUBTYPE;
const address: UserlikeAddress = { const address: UserlikeAddress = {
type: N.USERLIKE_TYPE, type: N.USERLIKE_TYPE,
// TODO: Detect bots and give them a different subtype (#696) subtype,
subtype: N.USER_SUBTYPE, login,
login: json.login,
}; };
const entry: UserlikeEntry = {address, url: json.url}; const entry: UserlikeEntry = {address, url: json.url};
this._userlikes.set(N.toRaw(address), entry); this._userlikes.set(N.toRaw(address), entry);