From fad633213349d65f6b399e733138462df5d60c6a Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Sun, 28 Aug 2022 13:52:56 -0400 Subject: [PATCH] feat(plugins/notable): add `plugin_notable_self` (closes #1143) --- source/plugins/notable/index.mjs | 6 +++--- source/plugins/notable/metadata.yml | 6 ++++++ source/plugins/notable/queries/contributions.graphql | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/source/plugins/notable/index.mjs b/source/plugins/notable/index.mjs index 07bd8e23..c4035812 100644 --- a/source/plugins/notable/index.mjs +++ b/source/plugins/notable/index.mjs @@ -7,7 +7,7 @@ export default async function({login, q, imports, rest, graphql, data, account, return null //Load inputs - let {filter, skipped, repositories, types, from, indepth} = imports.metadata.plugins.notable.inputs({data, account, q}) + let {filter, skipped, repositories, types, from, indepth, self} = imports.metadata.plugins.notable.inputs({data, account, q}) skipped.push(...data.shared["repositories.skipped"]) //Iterate through contributed repositories @@ -17,7 +17,7 @@ export default async function({login, q, imports, rest, graphql, data, account, let pushed = 0 do { console.debug(`metrics/compute/${login}/plugins > notable > retrieving contributed repositories after ${cursor}`) - const {user: {repositoriesContributedTo: {edges}}} = await graphql(queries.notable.contributions({login, types: types.map(x => x.toLocaleUpperCase()).join(", "), after: cursor ? `after: "${cursor}"` : "", repositories: data.shared["repositories.batch"] || 100})) + const {user: {repositoriesContributedTo: {edges}}} = await graphql(queries.notable.contributions({login, types: types.map(x => x.toLocaleUpperCase()).join(", "), after: cursor ? `after: "${cursor}"` : "", self, repositories: data.shared["repositories.batch"] || 100})) cursor = edges?.[edges?.length - 1]?.cursor edges .filter(({node}) => !((skipped.includes(node.nameWithOwner.toLocaleLowerCase())) || (skipped.includes(node.nameWithOwner.split("/")[1].toLocaleLowerCase())))) @@ -80,7 +80,7 @@ export default async function({login, q, imports, rest, graphql, data, account, //Count total commits of user const {data: contributions = []} = await rest.repos.getContributorsStats({owner, repo}) - const commits = contributions.filter(({author}) => author.login.toLocaleLowerCase() === login.toLocaleLowerCase()).reduce((a, {total: b}) => a + b, 0) + const commits = contributions?.filter(({author}) => author.login.toLocaleLowerCase() === login.toLocaleLowerCase()).reduce((a, {total: b}) => a + b, 0) ?? NaN //Save user data contribution.user = { diff --git a/source/plugins/notable/metadata.yml b/source/plugins/notable/metadata.yml index 87c1ab05..8d4cc228 100644 --- a/source/plugins/notable/metadata.yml +++ b/source/plugins/notable/metadata.yml @@ -86,3 +86,9 @@ inputs: - commit - pull_request - issue + + plugin_notable_self: + description: | + Include own repositories + type: boolean + default: no \ No newline at end of file diff --git a/source/plugins/notable/queries/contributions.graphql b/source/plugins/notable/queries/contributions.graphql index 6bc04695..98ddfdd2 100644 --- a/source/plugins/notable/queries/contributions.graphql +++ b/source/plugins/notable/queries/contributions.graphql @@ -1,6 +1,6 @@ query NotableContributions { user(login: "$login") { - repositoriesContributedTo($after first: $repositories, contributionTypes: [$types], orderBy: { field: STARGAZERS, direction: DESC }) { + repositoriesContributedTo($after first: $repositories, contributionTypes: [$types], includeUserRepositories: $self, orderBy: { field: STARGAZERS, direction: DESC }) { edges { cursor node {