Code formatting (#280)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**Template processor */
|
||||
export default async function(_, __, {imports}) {
|
||||
//Core
|
||||
await imports.plugins.core(...arguments)
|
||||
}
|
||||
export default async function(_, __, {imports}) {
|
||||
//Core
|
||||
await imports.plugins.core(...arguments)
|
||||
}
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
/**Template processor */
|
||||
export default async function(_, {data}, {imports}) {
|
||||
//Core
|
||||
await imports.plugins.core(...arguments)
|
||||
await imports.plugins.core(...arguments)
|
||||
//Aliases
|
||||
const {user, computed, plugins} = data
|
||||
Object.assign(data, {
|
||||
//Base
|
||||
NAME:user.name,
|
||||
LOGIN:user.login,
|
||||
REGISTRATION_DATE:user.createdAt,
|
||||
REGISTERED_YEARS:computed.registered.years,
|
||||
LOCATION:user.location,
|
||||
WEBSITE:user.websiteUrl,
|
||||
REPOSITORIES:user.repositories.totalCount,
|
||||
REPOSITORIES_DISK_USAGE:user.repositories.totalDiskUsage,
|
||||
PACKAGES:user.packages.totalCount,
|
||||
STARRED:user.starredRepositories.totalCount,
|
||||
WATCHING:user.watching.totalCount,
|
||||
SPONSORING:user.sponsorshipsAsSponsor.totalCount,
|
||||
SPONSORS:user.sponsorshipsAsMaintainer.totalCount,
|
||||
REPOSITORIES_CONTRIBUTED_TO:user.repositoriesContributedTo.totalCount,
|
||||
COMMITS:computed.commits,
|
||||
COMMITS_PUBLIC:user.contributionsCollection.totalCommitContributions,
|
||||
COMMITS_PRIVATE:user.contributionsCollection.restrictedContributionsCount,
|
||||
ISSUES:user.contributionsCollection.totalIssueContributions,
|
||||
PULL_REQUESTS:user.contributionsCollection.totalPullRequestContributions,
|
||||
PULL_REQUESTS_REVIEWS:user.contributionsCollection.totalPullRequestReviewContributions,
|
||||
FOLLOWERS:user.followers.totalCount,
|
||||
FOLLOWING:user.following.totalCount,
|
||||
ISSUE_COMMENTS:user.issueComments.totalCount,
|
||||
ORGANIZATIONS:user.organizations.totalCount,
|
||||
WATCHERS:computed.repositories.watchers,
|
||||
STARGAZERS:computed.repositories.stargazers,
|
||||
FORKS:computed.repositories.forks,
|
||||
RELEASES:computed.repositories.releases,
|
||||
VERSION:data.meta.version,
|
||||
//Lines
|
||||
LINES_ADDED:plugins.lines?.added ?? 0,
|
||||
LINES_DELETED:plugins.lines?.deleted ?? 0,
|
||||
//Gists
|
||||
GISTS:plugins.gists?.totalCount ?? 0,
|
||||
GISTS_STARGAZERS:plugins.gists?.stargazers ?? 0,
|
||||
//Languages
|
||||
LANGUAGES:plugins.languages?.favorites?.map(({name, value, size, color}) => ({name, value, size, color})) ?? [],
|
||||
//Posts
|
||||
POSTS:plugins.posts?.list ?? [],
|
||||
//Tweets
|
||||
TWEETS:plugins.tweets?.list ?? [],
|
||||
//Topics
|
||||
TOPICS:plugins.topics?.list ?? [],
|
||||
})
|
||||
}
|
||||
const {user, computed, plugins} = data
|
||||
Object.assign(data, {
|
||||
//Base
|
||||
NAME:user.name,
|
||||
LOGIN:user.login,
|
||||
REGISTRATION_DATE:user.createdAt,
|
||||
REGISTERED_YEARS:computed.registered.years,
|
||||
LOCATION:user.location,
|
||||
WEBSITE:user.websiteUrl,
|
||||
REPOSITORIES:user.repositories.totalCount,
|
||||
REPOSITORIES_DISK_USAGE:user.repositories.totalDiskUsage,
|
||||
PACKAGES:user.packages.totalCount,
|
||||
STARRED:user.starredRepositories.totalCount,
|
||||
WATCHING:user.watching.totalCount,
|
||||
SPONSORING:user.sponsorshipsAsSponsor.totalCount,
|
||||
SPONSORS:user.sponsorshipsAsMaintainer.totalCount,
|
||||
REPOSITORIES_CONTRIBUTED_TO:user.repositoriesContributedTo.totalCount,
|
||||
COMMITS:computed.commits,
|
||||
COMMITS_PUBLIC:user.contributionsCollection.totalCommitContributions,
|
||||
COMMITS_PRIVATE:user.contributionsCollection.restrictedContributionsCount,
|
||||
ISSUES:user.contributionsCollection.totalIssueContributions,
|
||||
PULL_REQUESTS:user.contributionsCollection.totalPullRequestContributions,
|
||||
PULL_REQUESTS_REVIEWS:user.contributionsCollection.totalPullRequestReviewContributions,
|
||||
FOLLOWERS:user.followers.totalCount,
|
||||
FOLLOWING:user.following.totalCount,
|
||||
ISSUE_COMMENTS:user.issueComments.totalCount,
|
||||
ORGANIZATIONS:user.organizations.totalCount,
|
||||
WATCHERS:computed.repositories.watchers,
|
||||
STARGAZERS:computed.repositories.stargazers,
|
||||
FORKS:computed.repositories.forks,
|
||||
RELEASES:computed.repositories.releases,
|
||||
VERSION:data.meta.version,
|
||||
//Lines
|
||||
LINES_ADDED:plugins.lines?.added ?? 0,
|
||||
LINES_DELETED:plugins.lines?.deleted ?? 0,
|
||||
//Gists
|
||||
GISTS:plugins.gists?.totalCount ?? 0,
|
||||
GISTS_STARGAZERS:plugins.gists?.stargazers ?? 0,
|
||||
//Languages
|
||||
LANGUAGES:plugins.languages?.favorites?.map(({name, value, size, color}) => ({name, value, size, color})) ?? [],
|
||||
//Posts
|
||||
POSTS:plugins.posts?.list ?? [],
|
||||
//Tweets
|
||||
TWEETS:plugins.tweets?.list ?? [],
|
||||
//Topics
|
||||
TOPICS:plugins.topics?.list ?? [],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
/**Template processor */
|
||||
export default async function({login, q}, {data, rest, graphql, queries, account}, {pending, imports}) {
|
||||
//Check arguments
|
||||
const {repo} = q
|
||||
if (!repo) {
|
||||
console.debug(`metrics/compute/${login}/${repo} > error, repo was undefined`)
|
||||
data.errors.push({error:{message:"You must pass a \"repo\" argument to use this template"}})
|
||||
return imports.plugins.core(...arguments)
|
||||
}
|
||||
console.debug(`metrics/compute/${login}/${repo} > switching to mode ${account}`)
|
||||
|
||||
//Retrieving single repository
|
||||
console.debug(`metrics/compute/${login}/${repo} > retrieving single repository ${repo}`)
|
||||
const {[account === "bypass" ? "user" : account]:{repository}} = await graphql(queries.base.repository({login, repo, account}))
|
||||
data.user.repositories.nodes = [repository]
|
||||
data.repo = repository
|
||||
|
||||
//Contributors and sponsors
|
||||
data.repo.contributors = {totalCount:(await rest.repos.listContributors({owner:data.repo.owner.login, repo})).data.length}
|
||||
data.repo.sponsorshipsAsMaintainer = data.user.sponsorshipsAsMaintainer
|
||||
|
||||
//Get commit activity
|
||||
console.debug(`metrics/compute/${login}/${repo} > querying api for commits`)
|
||||
const commits = []
|
||||
for (let page = 1; page < 100; page++) {
|
||||
console.debug(`metrics/compute/${login}/${repo} > loading page ${page}`)
|
||||
try {
|
||||
const {data} = await rest.repos.listCommits({owner:login, repo, per_page:100, page})
|
||||
if (!data.length) {
|
||||
console.debug(`metrics/compute/${login}/${repo} > no more page to load`)
|
||||
break
|
||||
}
|
||||
commits.push(...data)
|
||||
}
|
||||
catch (error) {
|
||||
if (/Git Repository is empty/.test(error))
|
||||
break
|
||||
throw error
|
||||
}
|
||||
}
|
||||
console.debug(`metrics/compute/${login}/${repo} > ${commits.length} commits loaded`)
|
||||
|
||||
//Override creation date, disk usage and website url
|
||||
data.user.createdAt = repository.createdAt
|
||||
data.user.repositories.totalDiskUsage = repository.diskUsage
|
||||
data.user.websiteUrl = repository.homepageUrl
|
||||
|
||||
//Override contributions calendar
|
||||
const days = 14
|
||||
//Compute relative date for each contribution
|
||||
const now = new Date()
|
||||
now.setHours(0, 0, 0, 0)
|
||||
const contributions = commits.map(({commit}) => Math.abs(Math.ceil((now - new Date(commit.committer.date))/(24*60*60*1000))))
|
||||
//Count contributions per relative day
|
||||
const calendar = new Array(days).fill(0)
|
||||
for (const day of contributions)
|
||||
calendar[day]++
|
||||
calendar.splice(days)
|
||||
const max = Math.max(...calendar)
|
||||
//Override contributions calendar
|
||||
data.user.calendar.contributionCalendar.weeks = calendar.map(commit => ({contributionDays:{color:commit ? `var(--color-calendar-graph-day-L${Math.ceil(commit/max/0.25)}-bg)` : "var(--color-calendar-graph-day-bg)"}}))
|
||||
|
||||
//Override plugins parameters
|
||||
q["projects.limit"] = 0
|
||||
|
||||
//Core
|
||||
await imports.plugins.core(...arguments)
|
||||
await Promise.all(pending)
|
||||
|
||||
//Set repository name
|
||||
data.user.name = `${data.user.login}/${repo}`
|
||||
|
||||
//Reformat projects names
|
||||
if (data.plugins.projects)
|
||||
data.plugins.projects.list?.map(project => project.name = project.name.replace(`(${login}/${repo})`, "").trim())
|
||||
export default async function({login, q}, {data, rest, graphql, queries, account}, {pending, imports}) {
|
||||
//Check arguments
|
||||
const {repo} = q
|
||||
if (!repo) {
|
||||
console.debug(`metrics/compute/${login}/${repo} > error, repo was undefined`)
|
||||
data.errors.push({error:{message:'You must pass a "repo" argument to use this template'}})
|
||||
return imports.plugins.core(...arguments)
|
||||
}
|
||||
console.debug(`metrics/compute/${login}/${repo} > switching to mode ${account}`)
|
||||
|
||||
//Retrieving single repository
|
||||
console.debug(`metrics/compute/${login}/${repo} > retrieving single repository ${repo}`)
|
||||
const {[account === "bypass" ? "user" : account]:{repository}} = await graphql(queries.base.repository({login, repo, account}))
|
||||
data.user.repositories.nodes = [repository]
|
||||
data.repo = repository
|
||||
|
||||
//Contributors and sponsors
|
||||
data.repo.contributors = {totalCount:(await rest.repos.listContributors({owner:data.repo.owner.login, repo})).data.length}
|
||||
data.repo.sponsorshipsAsMaintainer = data.user.sponsorshipsAsMaintainer
|
||||
|
||||
//Get commit activity
|
||||
console.debug(`metrics/compute/${login}/${repo} > querying api for commits`)
|
||||
const commits = []
|
||||
for (let page = 1; page < 100; page++) {
|
||||
console.debug(`metrics/compute/${login}/${repo} > loading page ${page}`)
|
||||
try {
|
||||
const {data} = await rest.repos.listCommits({owner:login, repo, per_page:100, page})
|
||||
if (!data.length) {
|
||||
console.debug(`metrics/compute/${login}/${repo} > no more page to load`)
|
||||
break
|
||||
}
|
||||
commits.push(...data)
|
||||
}
|
||||
catch (error) {
|
||||
if (/Git Repository is empty/.test(error))
|
||||
break
|
||||
throw error
|
||||
}
|
||||
}
|
||||
console.debug(`metrics/compute/${login}/${repo} > ${commits.length} commits loaded`)
|
||||
|
||||
//Override creation date, disk usage and website url
|
||||
data.user.createdAt = repository.createdAt
|
||||
data.user.repositories.totalDiskUsage = repository.diskUsage
|
||||
data.user.websiteUrl = repository.homepageUrl
|
||||
|
||||
//Override contributions calendar
|
||||
const days = 14
|
||||
//Compute relative date for each contribution
|
||||
const now = new Date()
|
||||
now.setHours(0, 0, 0, 0)
|
||||
const contributions = commits.map(({commit}) => Math.abs(Math.ceil((now - new Date(commit.committer.date)) / (24 * 60 * 60 * 1000))))
|
||||
//Count contributions per relative day
|
||||
const calendar = new Array(days).fill(0)
|
||||
for (const day of contributions)
|
||||
calendar[day]++
|
||||
calendar.splice(days)
|
||||
const max = Math.max(...calendar)
|
||||
//Override contributions calendar
|
||||
data.user.calendar.contributionCalendar.weeks = calendar.map(commit => ({contributionDays:{color:commit ? `var(--color-calendar-graph-day-L${Math.ceil(commit / max / 0.25)}-bg)` : "var(--color-calendar-graph-day-bg)"}}))
|
||||
|
||||
//Override plugins parameters
|
||||
q["projects.limit"] = 0
|
||||
|
||||
//Core
|
||||
await imports.plugins.core(...arguments)
|
||||
await Promise.all(pending)
|
||||
|
||||
//Set repository name
|
||||
data.user.name = `${data.user.login}/${repo}`
|
||||
|
||||
//Reformat projects names
|
||||
if (data.plugins.projects)
|
||||
data.plugins.projects.list?.map(project => project.name = project.name.replace(`(${login}/${repo})`, "").trim())
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**Template processor */
|
||||
export default async function({q}, _, {imports}) {
|
||||
//Core
|
||||
await imports.plugins.core(...arguments)
|
||||
//Disable optimization to keep white-spaces
|
||||
q.raw = true
|
||||
}
|
||||
export default async function({q}, _, {imports}) {
|
||||
//Core
|
||||
await imports.plugins.core(...arguments)
|
||||
//Disable optimization to keep white-spaces
|
||||
q.raw = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user