Add new Repositories plugin (#431) [skip ci]
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > stars/default")
|
||||
return ({
|
||||
repository:{
|
||||
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",
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -678,7 +678,31 @@
|
||||
},
|
||||
})
|
||||
: null),
|
||||
//Stars
|
||||
//Repositories
|
||||
...(set.plugins.enabled.repositories
|
||||
? ({
|
||||
repositories: {
|
||||
list: new Array(Number(options["repositories.featured"].split(",").length) - 1).fill(null).map((_, i) => ({
|
||||
created: faker.date.past(),
|
||||
description: faker.lorem.sentence(),
|
||||
forkCount: faker.datatype.number(100),
|
||||
isFork: faker.datatype.boolean(),
|
||||
issues: {
|
||||
totalCount: faker.datatype.number(100),
|
||||
},
|
||||
nameWithOwner: `${faker.random.word()}/${faker.random.word()}`,
|
||||
openGraphImageUrl: faker.internet.url(),
|
||||
pullRequests: {
|
||||
totalCount: faker.datatype.number(100),
|
||||
},
|
||||
stargazerCount: faker.datatype.number(10000),
|
||||
licenseInfo: { nickname: null, name: "License" },
|
||||
primaryLanguage: { color: faker.internet.color(), name: faker.lorem.word() },
|
||||
})),
|
||||
},
|
||||
})
|
||||
: null),
|
||||
//Stargazers
|
||||
...(set.plugins.enabled.stargazers
|
||||
? ({
|
||||
get stargazers() {
|
||||
|
||||
26
source/plugins/repositories/README.md
Normal file
26
source/plugins/repositories/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
### 📓 Repositories
|
||||
|
||||
The *repositories* plugin can display a list of chosen featured repositories.
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.repositories.svg">
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</table>
|
||||
|
||||
It is mostly intended for external usage as [pinned repositories](https://www.google.com/search?client=firefox-b-d&q=github+pinned+repositories) is probably a better alternative if you want to embed them on your profile.
|
||||
|
||||
Because of limitations of using SVG inside of `<img>` tags, people won't be able to click on it.
|
||||
|
||||
#### ℹ️ Examples workflows
|
||||
|
||||
[➡️ Available options for this plugin](metadata.yml)
|
||||
|
||||
```yaml
|
||||
- uses: lowlighter/metrics@latest
|
||||
with:
|
||||
# ... other options
|
||||
plugin_repositories: yes
|
||||
plugin_repositories_list: lowlighter/metrics, denoland/deno # List of repositories you want to feature
|
||||
```
|
||||
38
source/plugins/repositories/index.mjs
Normal file
38
source/plugins/repositories/index.mjs
Normal file
@@ -0,0 +1,38 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, graphql, queries, data, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.repositories))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {featured} = imports.metadata.plugins.repositories.inputs({data, account, q})
|
||||
|
||||
//Initialization
|
||||
const repositories = {list:[]}
|
||||
|
||||
//Fetch repositories informations
|
||||
for (const repo of featured) {
|
||||
const {owner = login, name} = repo.match(/^(?:(?<owner>[\s\S]*)[/])?(?<name>[\s\S]+)$/)?.groups ?? {}
|
||||
const {repository} = await graphql(queries.repositories.repository({owner, name}))
|
||||
repositories.list.push(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
|
||||
return repositories
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error:{message:"An error occured", instance:error}}
|
||||
}
|
||||
}
|
||||
22
source/plugins/repositories/metadata.yml
Normal file
22
source/plugins/repositories/metadata.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
name: "📓 Repositories"
|
||||
cost: 1 GraphQL request per repository
|
||||
category: github
|
||||
supports:
|
||||
- user
|
||||
- organization
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_repositories:
|
||||
description: Display chosen featured repositories
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# Featured repositories to display
|
||||
# If no owner is specified, it will implicitly use the current account login as owner
|
||||
plugin_repositories_featured:
|
||||
description: List of repositories to display
|
||||
type: array
|
||||
format: comma-separated
|
||||
default: ""
|
||||
example: lowlighter/metrics
|
||||
26
source/plugins/repositories/queries/repository.graphql
Normal file
26
source/plugins/repositories/queries/repository.graphql
Normal file
@@ -0,0 +1,26 @@
|
||||
query RepositoriesRepository {
|
||||
repository(owner: "$owner", name: "$name") {
|
||||
createdAt
|
||||
description
|
||||
forkCount
|
||||
isFork
|
||||
issues {
|
||||
totalCount
|
||||
}
|
||||
nameWithOwner
|
||||
openGraphImageUrl
|
||||
licenseInfo {
|
||||
nickname
|
||||
spdxId
|
||||
name
|
||||
}
|
||||
pullRequests {
|
||||
totalCount
|
||||
}
|
||||
stargazerCount
|
||||
primaryLanguage {
|
||||
color
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
6
source/plugins/repositories/tests.yml
Normal file
6
source/plugins/repositories/tests.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
- name: Repositories plugin (default)
|
||||
uses: lowlighter/metrics@latest
|
||||
with:
|
||||
token: MOCKED_TOKEN
|
||||
plugin_repositories: yes
|
||||
plugin_repositories_list: metrics
|
||||
@@ -7,6 +7,7 @@
|
||||
"languages",
|
||||
"notable",
|
||||
"projects",
|
||||
"repositories",
|
||||
"gists",
|
||||
"pagespeed",
|
||||
"habits",
|
||||
|
||||
78
source/templates/classic/partials/repositories.ejs
Normal file
78
source/templates/classic/partials/repositories.ejs
Normal file
@@ -0,0 +1,78 @@
|
||||
<% if (plugins.repositories) { %>
|
||||
<section>
|
||||
<h2 class="field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M0 2.75A2.75 2.75 0 012.75 0h10.5A2.75 2.75 0 0116 2.75v10.5A2.75 2.75 0 0113.25 16H2.75A2.75 2.75 0 010 13.25V2.75zM2.75 1.5c-.69 0-1.25.56-1.25 1.25v10.5c0 .69.56 1.25 1.25 1.25h10.5c.69 0 1.25-.56 1.25-1.25V2.75c0-.69-.56-1.25-1.25-1.25H2.75z"></path><path d="M8 4a.75.75 0 01.75.75V6.7l1.69-.975a.75.75 0 01.75 1.3L9.5 8l1.69.976a.75.75 0 01-.75 1.298L8.75 9.3v1.951a.75.75 0 01-1.5 0V9.299l-1.69.976a.75.75 0 01-.75-1.3L6.5 8l-1.69-.975a.75.75 0 01.75-1.3l1.69.976V4.75A.75.75 0 018 4z"></path></svg>
|
||||
Featured repositories
|
||||
</h2>
|
||||
<div class="row">
|
||||
<section class="largeable-flex-wrap">
|
||||
<% if (plugins.repositories.error) { %>
|
||||
<div class="field error">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2.343 13.657A8 8 0 1113.657 2.343 8 8 0 012.343 13.657zM6.03 4.97a.75.75 0 00-1.06 1.06L6.94 8 4.97 9.97a.75.75 0 101.06 1.06L8 9.06l1.97 1.97a.75.75 0 101.06-1.06L9.06 8l1.97-1.97a.75.75 0 10-1.06-1.06L8 6.94 6.03 4.97z"></path></svg>
|
||||
<%= plugins.repositories.error.message %>
|
||||
</div>
|
||||
<% } else if (plugins.repositories.list.length) { %>
|
||||
<% for (const repository of plugins.repositories.list) { %>
|
||||
<div class="row fill-width largeable-width-half">
|
||||
<section class="repository">
|
||||
<div class="field">
|
||||
<% if (repository.isFork) { %>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75h-4.5A.75.75 0 015 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"></path></svg>
|
||||
<% } else { %>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2 2.5A2.5 2.5 0 014.5 0h8.75a.75.75 0 01.75.75v12.5a.75.75 0 01-.75.75h-2.5a.75.75 0 110-1.5h1.75v-2h-8a1 1 0 00-.714 1.7.75.75 0 01-1.072 1.05A2.495 2.495 0 012 11.5v-9zm10.5-1V9h-8c-.356 0-.694.074-1 .208V2.5a1 1 0 011-1h8zM5 12.25v3.25a.25.25 0 00.4.2l1.45-1.087a.25.25 0 01.3 0L8.6 15.7a.25.25 0 00.4-.2v-3.25a.25.25 0 00-.25-.25h-3.5a.25.25 0 00-.25.25z"></path></svg>
|
||||
<% } %>
|
||||
<div class="name">
|
||||
<span><%= repository.nameWithOwner %></span>
|
||||
<span>created <%= repository.created %></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field description">
|
||||
<%= repository.description %>
|
||||
</div>
|
||||
<div class="field infos">
|
||||
<% if (repository.primaryLanguage) { %>
|
||||
<div class="language">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill="<%= repository.primaryLanguage.color %>" fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8z"></path></svg>
|
||||
<%= repository.primaryLanguage.name %>
|
||||
</div>
|
||||
<% } %>
|
||||
<% if (repository.licenseInfo) { %>
|
||||
<div>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8.75.75a.75.75 0 00-1.5 0V2h-.984c-.305 0-.604.08-.869.23l-1.288.737A.25.25 0 013.984 3H1.75a.75.75 0 000 1.5h.428L.066 9.192a.75.75 0 00.154.838l.53-.53-.53.53v.001l.002.002.002.002.006.006.016.015.045.04a3.514 3.514 0 00.686.45A4.492 4.492 0 003 11c.88 0 1.556-.22 2.023-.454a3.515 3.515 0 00.686-.45l.045-.04.016-.015.006-.006.002-.002.001-.002L5.25 9.5l.53.53a.75.75 0 00.154-.838L3.822 4.5h.162c.305 0 .604-.08.869-.23l1.289-.737a.25.25 0 01.124-.033h.984V13h-2.5a.75.75 0 000 1.5h6.5a.75.75 0 000-1.5h-2.5V3.5h.984a.25.25 0 01.124.033l1.29.736c.264.152.563.231.868.231h.162l-2.112 4.692a.75.75 0 00.154.838l.53-.53-.53.53v.001l.002.002.002.002.006.006.016.015.045.04a3.517 3.517 0 00.686.45A4.492 4.492 0 0013 11c.88 0 1.556-.22 2.023-.454a3.512 3.512 0 00.686-.45l.045-.04.01-.01.006-.005.006-.006.002-.002.001-.002-.529-.531.53.53a.75.75 0 00.154-.838L13.823 4.5h.427a.75.75 0 000-1.5h-2.234a.25.25 0 01-.124-.033l-1.29-.736A1.75 1.75 0 009.735 2H8.75V.75zM1.695 9.227c.285.135.718.273 1.305.273s1.02-.138 1.305-.273L3 6.327l-1.305 2.9zm10 0c.285.135.718.273 1.305.273s1.02-.138 1.305-.273L13 6.327l-1.305 2.9z"></path></svg>
|
||||
<%= f.license(repository.licenseInfo) %>
|
||||
</div>
|
||||
<% } %>
|
||||
<div>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"></path></svg>
|
||||
<%= f(repository.stargazerCount) %>
|
||||
</div>
|
||||
<div>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M5 3.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm0 2.122a2.25 2.25 0 10-1.5 0v.878A2.25 2.25 0 005.75 8.5h1.5v2.128a2.251 2.251 0 101.5 0V8.5h1.5a2.25 2.25 0 002.25-2.25v-.878a2.25 2.25 0 10-1.5 0v.878a.75.75 0 01-.75.75h-4.5A.75.75 0 015 6.25v-.878zm3.75 7.378a.75.75 0 11-1.5 0 .75.75 0 011.5 0zm3-8.75a.75.75 0 100-1.5.75.75 0 000 1.5z"></path></svg>
|
||||
<%= f(repository.forkCount) %>
|
||||
</div>
|
||||
<div>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path d="M8 9.5a1.5 1.5 0 100-3 1.5 1.5 0 000 3z"></path><path fill-rule="evenodd" d="M8 0a8 8 0 100 16A8 8 0 008 0zM1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0z"></path></svg>
|
||||
<%= f(repository.issues.totalCount) %>
|
||||
</div>
|
||||
<div>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.177 3.073L9.573.677A.25.25 0 0110 .854v4.792a.25.25 0 01-.427.177L7.177 3.427a.25.25 0 010-.354zM3.75 2.5a.75.75 0 100 1.5.75.75 0 000-1.5zm-2.25.75a2.25 2.25 0 113 2.122v5.256a2.251 2.251 0 11-1.5 0V5.372A2.25 2.25 0 011.5 3.25zM11 2.5h-1V4h1a1 1 0 011 1v5.628a2.251 2.251 0 101.5 0V5A2.5 2.5 0 0011 2.5zm1 10.25a.75.75 0 111.5 0 .75.75 0 01-1.5 0zM3.75 12a.75.75 0 100 1.5.75.75 0 000-1.5z"></path></svg>
|
||||
<%= f(repository.pullRequests.totalCount) %>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<% } %>
|
||||
<% } else { %>
|
||||
<div class="row fill-width largeable-width-half">
|
||||
<section>
|
||||
<div class="field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM0 8a8 8 0 1116 0A8 8 0 010 8zm6.5-.25A.75.75 0 017.25 7h1a.75.75 0 01.75.75v2.75h.25a.75.75 0 010 1.5h-2a.75.75 0 010-1.5h.25v-2h-.25a.75.75 0 01-.75-.75zM8 6a1 1 0 100-2 1 1 0 000 2z"></path></svg>
|
||||
Configure this plugin with repositories you want to feature!
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<% } %>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
<% } %>
|
||||
Reference in New Issue
Block a user