The great refactor (#82)
This commit is contained in:
55
source/plugins/projects/README.md
Normal file
55
source/plugins/projects/README.md
Normal file
@@ -0,0 +1,55 @@
|
||||
### 🗂️ Projects <sup>🚧 <code>plugin_projects_descriptions</code> on <code>@master</code></sup>
|
||||
|
||||
⚠️ This plugin requires a personal token with public_repo scope.
|
||||
|
||||
The *projects* plugin displays the progress of your profile projects.
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.projects.svg">
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</table>
|
||||
|
||||
Because of GitHub REST API limitation, provided token requires `public_repo` scope to access projects informations.
|
||||
|
||||
Note that by default, projects have progress tracking disabled.
|
||||
To enable it, open the `≡ Menu` and edit the project to opt-in to `Track project progress` (it can be a bit confusing since it's actually not in the project settings).
|
||||
|
||||

|
||||
|
||||
<details>
|
||||
<summary>💬 Create a personal project on GitHub</summary>
|
||||
|
||||
On your profile, select the `Projects` tab:
|
||||

|
||||
|
||||
Fill the informations and set visibility to *public*:
|
||||

|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>💬 Use repositories projects</summary>
|
||||
|
||||
It is possible to display projects related to repositories along with personal projects.
|
||||
|
||||
To do so, open your repository project and retrieve the last URL endpoint, in the format `:user/:repository/projects/:project_id` (for example, `lowlighter/metrics/projects/1`) and add it in the `plugin_projects_repositories` option. Enable `Track project progress` in the project settings to display a progress bar in generated metrics.
|
||||
|
||||

|
||||
|
||||
</details>
|
||||
|
||||
#### ℹ️ Examples workflows
|
||||
|
||||
[➡️ Available options for this plugin](metadata.yml)
|
||||
|
||||
```yaml
|
||||
- uses: lowlighter/metrics@latest
|
||||
with:
|
||||
# ... other options
|
||||
plugin_projects: yes
|
||||
plugin_projects_repositories: lowlighter/metrics/projects/1 # Display #1 project of lowlighter/metrics repository
|
||||
plugin_projects_limit: 4 # Limit to 4 entries
|
||||
plugin_projects_descriptions: yes # Display projects descriptions
|
||||
```
|
||||
@@ -1,25 +1,26 @@
|
||||
//Setup
|
||||
export default async function ({login, graphql, q, queries, account}, {enabled = false} = {}) {
|
||||
export default async function ({login, data, imports, graphql, q, queries, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.projects))
|
||||
return null
|
||||
//Parameters override
|
||||
let {"projects.limit":limit = 4, "projects.repositories":repositories = "", "projects.descriptions":descriptions = false} = q
|
||||
|
||||
//Load inputs
|
||||
let {limit, repositories, descriptions} = imports.metadata.plugins.projects.inputs({data, account, q})
|
||||
//Repositories projects
|
||||
repositories = decodeURIComponent(repositories ?? "").split(",").map(repository => repository.trim()).filter(repository => /[-\w]+[/][-\w]+[/]projects[/]\d+/.test(repository)) ?? []
|
||||
//Limit
|
||||
limit = Math.max(repositories.length, Math.min(100, Number(limit)))
|
||||
repositories = repositories.filter(repository => /[-\w]+[/][-\w]+[/]projects[/]\d+/.test(repository))
|
||||
|
||||
//Retrieve user owned projects from graphql api
|
||||
console.debug(`metrics/compute/${login}/plugins > projects > querying api`)
|
||||
const {[account]:{projects}} = await graphql(queries.projects({login, limit, account}))
|
||||
const {[account]:{projects}} = await graphql(queries.projects.user({login, limit, account}))
|
||||
|
||||
//Retrieve repositories projects from graphql api
|
||||
for (const identifier of repositories) {
|
||||
//Querying repository project
|
||||
console.debug(`metrics/compute/${login}/plugins > projects > querying api for ${identifier}`)
|
||||
const {user, repository, id} = identifier.match(/(?<user>[-\w]+)[/](?<repository>[-\w]+)[/]projects[/](?<id>\d+)/)?.groups
|
||||
const {[account]:{repository:{project}}} = await graphql(queries["projects.repository"]({user, repository, id, account}))
|
||||
const {[account]:{repository:{project}}} = await graphql(queries.projects.repository({user, repository, id, account}))
|
||||
//Adding it to projects list
|
||||
console.debug(`metrics/compute/${login}/plugins > projects > registering ${identifier}`)
|
||||
project.name = `${project.name} (${user}/${repository})`
|
||||
@@ -43,9 +44,11 @@
|
||||
//Append
|
||||
list.push({name:project.name, updated, description:project.body, progress:{enabled, todo, doing, done, total:todo+doing+done}})
|
||||
}
|
||||
|
||||
//Limit
|
||||
console.debug(`metrics/compute/${login}/plugins > projects > keeping only ${limit} projects`)
|
||||
list.splice(limit)
|
||||
|
||||
//Results
|
||||
return {list, totalCount:projects.totalCount, descriptions}
|
||||
}
|
||||
|
||||
39
source/plugins/projects/metadata.yml
Normal file
39
source/plugins/projects/metadata.yml
Normal file
@@ -0,0 +1,39 @@
|
||||
name: "🗂️ Projects"
|
||||
cost: 1 GraphQL request + 1 GraphQL request per repository project
|
||||
supports:
|
||||
- user
|
||||
- organization
|
||||
- repository
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_projects:
|
||||
description: Display active projects
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# Number of projects to display
|
||||
# Set to 0 to only display "plugin_projects_repositories" projects
|
||||
# Projects listed in "plugin_projects_repositories" are not affected by this option
|
||||
plugin_projects_limit:
|
||||
description: Maximum number of projects to display
|
||||
type: number
|
||||
default: 4
|
||||
min: 0
|
||||
max: 100
|
||||
|
||||
# List of repository projects to display, using the following format:
|
||||
# :user/:repo/projects/:project_id
|
||||
plugin_projects_repositories:
|
||||
description: List of repository project identifiers to disaplay
|
||||
type: array
|
||||
format:
|
||||
- comma-separated
|
||||
- /(?<user>[-a-z0-9]+)[/](?<repo>[-a-z0-9]+)[/]projects[/](?<id>[0-9]+)/
|
||||
default: ""
|
||||
|
||||
# Display projects descriptions
|
||||
plugin_projects_descriptions:
|
||||
description: Display projects descriptions
|
||||
type: boolean
|
||||
default: no
|
||||
17
source/plugins/projects/queries/repository.graphql
Normal file
17
source/plugins/projects/queries/repository.graphql
Normal file
@@ -0,0 +1,17 @@
|
||||
query ProjectsRepository {
|
||||
$account(login: "$user") {
|
||||
repository(name: "$repository") {
|
||||
project(number: $id) {
|
||||
name
|
||||
body
|
||||
updatedAt
|
||||
progress {
|
||||
doneCount
|
||||
inProgressCount
|
||||
todoCount
|
||||
enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
source/plugins/projects/queries/user.graphql
Normal file
18
source/plugins/projects/queries/user.graphql
Normal file
@@ -0,0 +1,18 @@
|
||||
query ProjectsUser {
|
||||
$account(login: "$login") {
|
||||
projects(last: $limit, states: OPEN, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||
totalCount
|
||||
nodes {
|
||||
name
|
||||
body
|
||||
updatedAt
|
||||
progress {
|
||||
doneCount
|
||||
inProgressCount
|
||||
todoCount
|
||||
enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user