feat(plugins/repositories): add plugin_repositories_pinned (#1100)
This commit is contained in:
@@ -6,3 +6,12 @@
|
|||||||
base: ""
|
base: ""
|
||||||
plugin_repositories: yes
|
plugin_repositories: yes
|
||||||
plugin_repositories_featured: lowlighter/metrics
|
plugin_repositories_featured: lowlighter/metrics
|
||||||
|
|
||||||
|
- name: Pinned repositories
|
||||||
|
uses: lowlighter/metrics@latest
|
||||||
|
with:
|
||||||
|
filename: metrics.plugin.repositories.pinned.svg
|
||||||
|
token: ${{ secrets.METRICS_TOKEN }}
|
||||||
|
base: ""
|
||||||
|
plugin_repositories: yes
|
||||||
|
plugin_repositories_pinned: 2
|
||||||
|
|||||||
@@ -7,25 +7,22 @@ export default async function({login, q, imports, graphql, queries, data, accoun
|
|||||||
return null
|
return null
|
||||||
|
|
||||||
//Load inputs
|
//Load inputs
|
||||||
let {featured} = imports.metadata.plugins.repositories.inputs({data, account, q})
|
let {featured, pinned} = imports.metadata.plugins.repositories.inputs({data, account, q})
|
||||||
|
|
||||||
//Initialization
|
//Initialization
|
||||||
const repositories = {list: []}
|
const repositories = {list: []}
|
||||||
|
|
||||||
|
//Fetch pinned repositories
|
||||||
|
if (pinned) {
|
||||||
|
const {user:{pinnedItems:{edges}}} = await graphql(queries.repositories.pinned({login, limit:pinned}))
|
||||||
|
repositories.list.push(...edges.map(({node}) => format(node)))
|
||||||
|
}
|
||||||
|
|
||||||
//Fetch repositories informations
|
//Fetch repositories informations
|
||||||
for (const repo of featured) {
|
for (const repo of featured) {
|
||||||
const {owner = login, name} = repo.match(/^(?:(?<owner>[\s\S]*)[/])?(?<name>[\s\S]+)$/)?.groups ?? {}
|
const {owner = login, name} = repo.match(/^(?:(?<owner>[\s\S]*)[/])?(?<name>[\s\S]+)$/)?.groups ?? {}
|
||||||
const {repository} = await graphql(queries.repositories.repository({owner, name}))
|
const {repository} = await graphql(queries.repositories.repository({owner, name}))
|
||||||
repositories.list.push(repository)
|
repositories.list.push(format(repository))
|
||||||
|
|
||||||
//Format date
|
|
||||||
const time = (Date.now() - new Date(repository.createdAt).getTime()) / (24 * 60 * 60 * 1000)
|
|
||||||
let created = new Date(repository.createdAt).toDateString().substring(4)
|
|
||||||
if (time < 1)
|
|
||||||
created = `${Math.ceil(time * 24)} hour${Math.ceil(time * 24) >= 2 ? "s" : ""} ago`
|
|
||||||
else if (time < 30)
|
|
||||||
created = `${Math.floor(time)} day${time >= 2 ? "s" : ""} ago`
|
|
||||||
repository.created = created
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Results
|
//Results
|
||||||
@@ -36,3 +33,17 @@ export default async function({login, q, imports, graphql, queries, data, accoun
|
|||||||
throw {error: {message: "An error occured", instance: error}}
|
throw {error: {message: "An error occured", instance: error}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**Format repository data */
|
||||||
|
function format(repository) {
|
||||||
|
//Format date
|
||||||
|
const time = (Date.now() - new Date(repository.createdAt).getTime()) / (24 * 60 * 60 * 1000)
|
||||||
|
let created = new Date(repository.createdAt).toDateString().substring(4)
|
||||||
|
if (time < 1)
|
||||||
|
created = `${Math.ceil(time * 24)} hour${Math.ceil(time * 24) >= 2 ? "s" : ""} ago`
|
||||||
|
else if (time < 30)
|
||||||
|
created = `${Math.floor(time)} day${time >= 2 ? "s" : ""} ago`
|
||||||
|
repository.created = created
|
||||||
|
|
||||||
|
return repository
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ description: |
|
|||||||
|
|
||||||
> ⚠️ People will not be able to click on it due to limitations of using SVG inside `<img>` tags.
|
> ⚠️ People will not be able to click on it due to limitations of using SVG inside `<img>` tags.
|
||||||
examples:
|
examples:
|
||||||
default: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.repositories.svg
|
+featured: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.repositories.svg
|
||||||
|
pinned: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.repositories.pinned.svg
|
||||||
index: 20
|
index: 20
|
||||||
supports:
|
supports:
|
||||||
- user
|
- user
|
||||||
@@ -31,3 +32,11 @@ inputs:
|
|||||||
default: ""
|
default: ""
|
||||||
example: lowlighter/metrics
|
example: lowlighter/metrics
|
||||||
preset: no
|
preset: no
|
||||||
|
|
||||||
|
plugin_repositories_pinned:
|
||||||
|
description: |
|
||||||
|
Display pinned repositories
|
||||||
|
type: number
|
||||||
|
default: 0
|
||||||
|
min: 0
|
||||||
|
max: 6
|
||||||
|
|||||||
34
source/plugins/repositories/queries/pinned.graphql
Normal file
34
source/plugins/repositories/queries/pinned.graphql
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
query RepositoriesPinned {
|
||||||
|
user(login: "$login") {
|
||||||
|
pinnedItems(types: REPOSITORY, first: $limit) {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
... on Repository {
|
||||||
|
createdAt
|
||||||
|
description
|
||||||
|
forkCount
|
||||||
|
isFork
|
||||||
|
issues {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
nameWithOwner
|
||||||
|
openGraphImageUrl
|
||||||
|
licenseInfo {
|
||||||
|
nickname
|
||||||
|
spdxId
|
||||||
|
name
|
||||||
|
}
|
||||||
|
pullRequests {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
stargazerCount
|
||||||
|
primaryLanguage {
|
||||||
|
color
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
tests/mocks/api/github/graphql/repositories.pinned.mjs
Normal file
35
tests/mocks/api/github/graphql/repositories.pinned.mjs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/**Mocked data */
|
||||||
|
export default function({faker, query, login = faker.internet.userName()}) {
|
||||||
|
console.debug("metrics/compute/mocks > mocking graphql api result > repositories/pinned")
|
||||||
|
return ({
|
||||||
|
user:{
|
||||||
|
pinnedItems:{
|
||||||
|
edges:[{
|
||||||
|
node: {
|
||||||
|
createdAt: faker.date.past(),
|
||||||
|
description: "📊 An image generator with 20+ metrics about your GitHub account such as activity, community, repositories, coding habits, website performances, music played, starred topics, etc. that you can put on your profile or elsewhere !",
|
||||||
|
forkCount: faker.datatype.number(100),
|
||||||
|
isFork: false,
|
||||||
|
issues: {
|
||||||
|
totalCount: faker.datatype.number(100),
|
||||||
|
},
|
||||||
|
nameWithOwner: "lowlighter/metrics",
|
||||||
|
openGraphImageUrl: "https://repository-images.githubusercontent.com/293860197/7fd72080-496d-11eb-8fe0-238b38a0746a",
|
||||||
|
pullRequests: {
|
||||||
|
totalCount: faker.datatype.number(100),
|
||||||
|
},
|
||||||
|
stargazerCount: faker.datatype.number(10000),
|
||||||
|
licenseInfo: {
|
||||||
|
nickname: null,
|
||||||
|
name: "MIT License",
|
||||||
|
},
|
||||||
|
primaryLanguage: {
|
||||||
|
color: "#f1e05a",
|
||||||
|
name: "JavaScript",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/**Mocked data */
|
/**Mocked data */
|
||||||
export default function({faker, query, login = faker.internet.userName()}) {
|
export default function({faker, query, login = faker.internet.userName()}) {
|
||||||
console.debug("metrics/compute/mocks > mocking graphql api result > stars/default")
|
console.debug("metrics/compute/mocks > mocking graphql api result > repositories/repository")
|
||||||
return ({
|
return ({
|
||||||
repository: {
|
repository: {
|
||||||
createdAt: faker.date.past(),
|
createdAt: faker.date.past(),
|
||||||
|
|||||||
Reference in New Issue
Block a user