From 32b61f0b7039f9f0b0d7377b0ff31de435792ff9 Mon Sep 17 00:00:00 2001 From: Simon Lecoq <22963968+lowlighter@users.noreply.github.com> Date: Sun, 18 Apr 2021 20:19:39 +0200 Subject: [PATCH] Feat notable options (#240) --- source/app/metrics/utils.mjs | 28 +++++++++++++++++++ .../github/graphql/notable.contributions.mjs | 4 +++ .../github/graphql/notable.organizations.mjs | 14 ---------- source/plugins/notable/README.md | 5 ++++ source/plugins/notable/index.mjs | 16 ++++------- source/plugins/notable/metadata.yml | 15 ++++++++++ .../notable/queries/contributions.graphql | 10 +++++++ .../notable/queries/organizations.graphql | 11 -------- 8 files changed, 67 insertions(+), 36 deletions(-) delete mode 100644 source/app/mocks/api/github/graphql/notable.organizations.mjs delete mode 100644 source/plugins/notable/queries/organizations.graphql diff --git a/source/app/metrics/utils.mjs b/source/app/metrics/utils.mjs index 88e3e425..a4d0eed7 100644 --- a/source/app/metrics/utils.mjs +++ b/source/app/metrics/utils.mjs @@ -180,6 +180,34 @@ return rendered } +/**Check GitHub filter against object */ + export function ghfilter(text, object) { + console.debug(`metrics/svg/ghquery > checking ${text} against ${JSON.stringify(object)}`) + const result = text.split(" ").map(x => x.trim()).filter(x => x).map(criteria => { + const [key, filters] = criteria.split(":") + const value = object[key] + console.debug(`metrics/svg/ghquery > checking ${criteria} against ${value}`) + return filters.split(",").map(x => x.trim()).filter(x => x).map(filter => { + switch (true) { + case /^>\d+$/.test(filter): + return value > Number(filter.substring(1)) + case /^<\d+$/.test(filter): + return value < Number(filter.substring(1)) + case /^\d+$/.test(filter): + return value === Number(filter) + case /^\d+..\d+$/.test(filter):{ + const [a, b] = filter.split("..").map(Number) + return (value >= a)&&(value <= b) + } + default: + return false + } + }).reduce((a, b) => a||b, false) + }).reduce((a, b) => a&&b, true) + console.debug(`metrics/svg/ghquery > ${result ? "matching" : "not matching"}`) + return result + } + /**Image to base64 */ export async function imgb64(image, {width, height, fallback = true} = {}) { //Undefined image diff --git a/source/app/mocks/api/github/graphql/notable.contributions.mjs b/source/app/mocks/api/github/graphql/notable.contributions.mjs index a27e7639..9c19d86c 100644 --- a/source/app/mocks/api/github/graphql/notable.contributions.mjs +++ b/source/app/mocks/api/github/graphql/notable.contributions.mjs @@ -19,6 +19,10 @@ login:faker.internet.userName(), avatarUrl:null, }, + nameWithOwner:`${faker.internet.userName()}/${faker.lorem.slug()}`, + stargazers:{totalCount:faker.datatype.number(1000)}, + watchers:{totalCount:faker.datatype.number(1000)}, + forks:{totalCount:faker.datatype.number(1000)}, }, }, ], diff --git a/source/app/mocks/api/github/graphql/notable.organizations.mjs b/source/app/mocks/api/github/graphql/notable.organizations.mjs deleted file mode 100644 index 9d47a2a5..00000000 --- a/source/app/mocks/api/github/graphql/notable.organizations.mjs +++ /dev/null @@ -1,14 +0,0 @@ -/**Mocked data */ - export default function({faker, query, login = faker.internet.userName()}) { - console.debug("metrics/compute/mocks > mocking graphql api result > notable/organizations") - return ({ - user:{ - organizations:{ - nodes:[{ - login:faker.internet.userName(), - avatarUrl:null, - }], - }, - }, - }) - } diff --git a/source/plugins/notable/README.md b/source/plugins/notable/README.md index c67c3279..9cb3fe71 100644 --- a/source/plugins/notable/README.md +++ b/source/plugins/notable/README.md @@ -5,6 +5,9 @@ The *notable* plugin displays badges of organization where you commited at least
With repository name+ |