chore: code formatting

This commit is contained in:
github-actions[bot]
2022-04-23 23:18:43 +00:00
parent 73cd43c18f
commit 4c98629bbc
130 changed files with 1839 additions and 1788 deletions

View File

@@ -17,19 +17,20 @@ 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}"` : "", 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()))))
.filter(({node}) => ({all:true, organization:node.isInOrganization, user:!node.isInOrganization}[from]))
.filter(({node}) => imports.ghfilter(filter, {name:node.nameWithOwner, user:node.owner.login, stars:node.stargazers.totalCount, watchers:node.watchers.totalCount, forks:node.forks.totalCount}))
.map(({node}) => contributions.push({handle:node.nameWithOwner, stars:node.stargazers.totalCount, issues:node.issues.totalCount, pulls:node.pullRequests.totalCount, organization:node.isInOrganization, avatarUrl:node.owner.avatarUrl}))
.filter(({node}) => ({all: true, organization: node.isInOrganization, user: !node.isInOrganization}[from]))
.filter(({node}) => imports.ghfilter(filter, {name: node.nameWithOwner, user: node.owner.login, stars: node.stargazers.totalCount, watchers: node.watchers.totalCount, forks: node.forks.totalCount}))
.map(({node}) => contributions.push({handle: node.nameWithOwner, stars: node.stargazers.totalCount, issues: node.issues.totalCount, pulls: node.pullRequests.totalCount, organization: node.isInOrganization, avatarUrl: node.owner.avatarUrl}))
pushed = edges.length
} while ((pushed) && (cursor))
}
//Set contributions
contributions = (await Promise.all(contributions.map(async ({handle, stars, issues, pulls, avatarUrl, organization}) => ({name:handle.split("/").shift(), handle, stars, issues, pulls, avatar:await imports.imgb64(avatarUrl), organization})))).sort((a, b) => a.name.localeCompare(b.name)
contributions = (await Promise.all(contributions.map(async ({handle, stars, issues, pulls, avatarUrl, organization}) => ({name: handle.split("/").shift(), handle, stars, issues, pulls, avatar: await imports.imgb64(avatarUrl), organization})))).sort((a, b) =>
a.name.localeCompare(b.name)
)
console.debug(`metrics/compute/${login}/plugins > notable > found ${contributions.length} notable contributions`)
@@ -46,9 +47,9 @@ export default async function({login, q, imports, rest, graphql, data, account,
let pushed = 0
do {
console.debug(`metrics/compute/${login}/plugins > notable > retrieving user issues after ${cursor}`)
const {user:{issues:{edges}}} = await graphql(queries.notable.issues({login, type:"issues", after:cursor ? `after: "${cursor}"` : ""}))
const {user: {issues: {edges}}} = await graphql(queries.notable.issues({login, type: "issues", after: cursor ? `after: "${cursor}"` : ""}))
cursor = edges?.[edges?.length - 1]?.cursor
edges.map(({node:{repository:{nameWithOwner:repository}}}) => issues[repository] = (issues[repositories] ?? 0) + 1)
edges.map(({node: {repository: {nameWithOwner: repository}}}) => issues[repository] = (issues[repositories] ?? 0) + 1)
pushed = edges.length
} while ((pushed) && (cursor))
}
@@ -60,9 +61,9 @@ export default async function({login, q, imports, rest, graphql, data, account,
let pushed = 0
do {
console.debug(`metrics/compute/${login}/plugins > notable > retrieving user pull requests after ${cursor}`)
const {user:{pullRequests:{edges}}} = await graphql(queries.notable.issues({login, type:"pullRequests", after:cursor ? `after: "${cursor}"` : ""}))
const {user: {pullRequests: {edges}}} = await graphql(queries.notable.issues({login, type: "pullRequests", after: cursor ? `after: "${cursor}"` : ""}))
cursor = edges?.[edges?.length - 1]?.cursor
edges.map(({node:{repository:{nameWithOwner:repository}}}) => pulls[repository] = (pulls[repositories] ?? 0) + 1)
edges.map(({node: {repository: {nameWithOwner: repository}}}) => pulls[repository] = (pulls[repositories] ?? 0) + 1)
pushed = edges.length
} while ((pushed) && (cursor))
}
@@ -74,24 +75,24 @@ export default async function({login, q, imports, rest, graphql, data, account,
const [owner, repo] = handle.split("/")
try {
//Count total commits on repository
const {repository:{defaultBranchRef:{target:{history}}}} = await graphql(queries.notable.commits({owner, repo}))
const {repository: {defaultBranchRef: {target: {history}}}} = await graphql(queries.notable.commits({owner, repo}))
contribution.history = history.totalCount
//Load maintainers (errors probably means that token is not allowed to list contributors hence not a maintainer of said repo)
const {data:collaborators} = await rest.repos.listCollaborators({owner, repo}).catch(() => ({data:[]}))
const maintainers = collaborators.filter(({role_name:role}) => ["admin", "maintain", "write"].includes(role)).map(({login}) => login)
const {data: collaborators} = await rest.repos.listCollaborators({owner, repo}).catch(() => ({data: []}))
const maintainers = collaborators.filter(({role_name: role}) => ["admin", "maintain", "write"].includes(role)).map(({login}) => login)
//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 {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)
//Save user data
contribution.user = {
commits,
percentage:commits / contribution.history,
maintainer:maintainers.includes(login),
issues:issues[handle] ?? 0,
pulls:pulls[handle] ?? 0,
percentage: commits / contribution.history,
maintainer: maintainers.includes(login),
issues: issues[handle] ?? 0,
pulls: pulls[handle] ?? 0,
get stars() {
return Math.round(this.maintainer ? stars : this.percentage * stars)
},
@@ -115,7 +116,7 @@ export default async function({login, q, imports, rest, graphql, data, account,
const aggregate = aggregated.get(key)
aggregate.aggregated++
if (indepth) {
const {history = 0, user:{commits = 0, percentage = 0, maintainer = false} = {}} = _extras
const {history = 0, user: {commits = 0, percentage = 0, maintainer = false} = {}} = _extras
aggregate.history = aggregate.history ?? 0
aggregate.history += history
aggregate.user = aggregate.user ?? {}
@@ -124,16 +125,16 @@ export default async function({login, q, imports, rest, graphql, data, account,
aggregate.user.maintainer = aggregate.user.maintainer || maintainer
}
}
else
aggregated.set(key, {name:key, handle, avatar, organization, stars, aggregated:1, ..._extras})
else {
aggregated.set(key, {name: key, handle, avatar, organization, stars, aggregated: 1, ..._extras})
}
}
contributions = [...aggregated.values()]
if (indepth) {
//Normalize contribution percentage
contributions.map(aggregate => aggregate.user ? aggregate.user.percentage /= aggregate.aggregated : null)
//Additional filtering (no user commits means that API wasn't able to answer back, considering it as matching by default)
contributions = contributions.filter(({handle, user}) => !user?.commits ? true : imports.ghfilter(filter, {handle, commits:contributions.history, "commits.user":user.commits, "commits.user%":user.percentage * 100, maintainer:user.maintainer}))
contributions = contributions.filter(({handle, user}) => !user?.commits ? true : imports.ghfilter(filter, {handle, commits: contributions.history, "commits.user": user.commits, "commits.user%": user.percentage * 100, maintainer: user.maintainer}))
//Sort contribution by maintainer first and then by contribution percentage
contributions = contributions.sort((a, b) => ((b.user?.percentage + b.user?.maintainer) || 0) - ((a.user?.percentage + a.user?.maintainer) || 0))
}
@@ -143,6 +144,6 @@ export default async function({login, q, imports, rest, graphql, data, account,
}
//Handle errors
catch (error) {
throw {error:{message:"An error occured", instance:error}}
throw {error: {message: "An error occured", instance: error}}
}
}