Add new Repositories plugin (#431) [skip ci]
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user