The great refactor (#82)
This commit is contained in:
22
source/plugins/stars/README.md
Normal file
22
source/plugins/stars/README.md
Normal file
@@ -0,0 +1,22 @@
|
||||
### 🌟 Recently starred repositories
|
||||
|
||||
The *stars* plugin displays your recently starred repositories.
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.stars.svg">
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</table>
|
||||
|
||||
#### ℹ️ Examples workflows
|
||||
|
||||
[➡️ Available options for this plugin](metadata.yml)
|
||||
|
||||
```yaml
|
||||
- uses: lowlighter/metrics@latest
|
||||
with:
|
||||
# ... other options
|
||||
plugin_stars: yes
|
||||
plugin_stars_limit: 4 # Limit to 4 entries
|
||||
```
|
||||
@@ -1,19 +1,18 @@
|
||||
//Setup
|
||||
export default async function ({login, graphql, q, queries, account}, {enabled = false} = {}) {
|
||||
export default async function ({login, data, graphql, q, queries, imports, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.stars))
|
||||
return null
|
||||
if (account === "organization")
|
||||
throw {error:{message:"Not available for organizations"}}
|
||||
//Parameters override
|
||||
let {"stars.limit":limit = 4} = q
|
||||
//Limit
|
||||
limit = Math.max(1, Math.min(100, Number(limit)))
|
||||
|
||||
//Load inputs
|
||||
let {limit} = imports.metadata.plugins.stars.inputs({data, account, q})
|
||||
|
||||
//Retrieve user stars from graphql api
|
||||
console.debug(`metrics/compute/${login}/plugins > stars > querying api`)
|
||||
const {user:{starredRepositories:{edges:repositories}}} = await graphql(queries.starred({login, limit}))
|
||||
const {user:{starredRepositories:{edges:repositories}}} = await graphql(queries.stars({login, limit}))
|
||||
|
||||
//Format starred repositories
|
||||
for (const edge of repositories) {
|
||||
//Format date
|
||||
@@ -25,6 +24,7 @@
|
||||
updated = `${Math.floor(time)} day${time >= 2 ? "s" : ""} ago`
|
||||
edge.starred = updated
|
||||
}
|
||||
|
||||
//Results
|
||||
return {repositories}
|
||||
}
|
||||
|
||||
19
source/plugins/stars/metadata.yml
Normal file
19
source/plugins/stars/metadata.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
name: "🌟 Recently starred repositories"
|
||||
cost: 1 GraphQL request
|
||||
supports:
|
||||
- user
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_stars:
|
||||
description: Display recently starred repositories
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# Number of stars to display
|
||||
plugin_stars_limit:
|
||||
description: Maximum number of stars to display
|
||||
type: number
|
||||
default: 4
|
||||
min: 1
|
||||
max: 100
|
||||
32
source/plugins/stars/queries/stars.graphql
Normal file
32
source/plugins/stars/queries/stars.graphql
Normal file
@@ -0,0 +1,32 @@
|
||||
query StarsDefault {
|
||||
user(login: "$login") {
|
||||
starredRepositories(first: $limit, orderBy: {field: STARRED_AT, direction: DESC}) {
|
||||
edges {
|
||||
starredAt
|
||||
node {
|
||||
description
|
||||
forkCount
|
||||
isFork
|
||||
issues {
|
||||
totalCount
|
||||
}
|
||||
nameWithOwner
|
||||
openGraphImageUrl
|
||||
licenseInfo {
|
||||
nickname
|
||||
spdxId
|
||||
name
|
||||
}
|
||||
pullRequests {
|
||||
totalCount
|
||||
}
|
||||
stargazerCount
|
||||
primaryLanguage {
|
||||
color
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user