feat(plugins/projects): add support for GitHub projects beta (#1178)
This commit is contained in:
@@ -15,7 +15,10 @@ export default async function({login, data, imports, graphql, q, queries, accoun
|
||||
|
||||
//Retrieve user owned projects from graphql api
|
||||
console.debug(`metrics/compute/${login}/plugins > projects > querying api`)
|
||||
const {[account]: {projects}} = await graphql(queries.projects.user({login, limit, account}))
|
||||
const {[account]: {projects}} = await graphql(queries.projects["user.legacy"]({login, limit, account}))
|
||||
const {[account]: {projectsV2}} = await graphql(queries.projects.user({login, limit, account}))
|
||||
projects.nodes.unshift(...projectsV2.nodes)
|
||||
projects.totalCount += projectsV2.totalCount
|
||||
|
||||
//Retrieve repositories projects from graphql api
|
||||
for (const identifier of repositories) {
|
||||
@@ -24,11 +27,21 @@ export default async function({login, data, imports, graphql, q, queries, accoun
|
||||
const {user, repository, id} = identifier.match(/(?<user>[-\w]+)[/](?<repository>[-\w]+)[/]projects[/](?<id>\d+)/)?.groups ?? {}
|
||||
let project = null
|
||||
for (const account of ["user", "organization"]) {
|
||||
//Try projects beta
|
||||
try {
|
||||
;({project} = (await graphql(queries.projects.repository({user, repository, id, account})))[account].repository)
|
||||
project = (await graphql(queries.projects.repository({user, repository, id, account})))[account].repository.projectV2
|
||||
break
|
||||
}
|
||||
catch (error) {
|
||||
//Try projects classic
|
||||
console.debug(error)
|
||||
try {
|
||||
;({project} = (await graphql(queries.projects["repository.legacy"]({user, repository, id, account})))[account].repository)
|
||||
break
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!project)
|
||||
@@ -52,9 +65,16 @@ export default async function({login, data, imports, graphql, q, queries, accoun
|
||||
else if (time < 30)
|
||||
updated = `${Math.floor(time)} day${time >= 2 ? "s" : ""} ago`
|
||||
//Format progress
|
||||
const {enabled, todoCount: todo, inProgressCount: doing, doneCount: done} = project.progress
|
||||
const {enabled = false, todoCount: todo = NaN, inProgressCount: doing = NaN, doneCount: done = NaN} = project.progress ?? {}
|
||||
let total = todo + doing + done
|
||||
//Format items (v2)
|
||||
const items = []
|
||||
if (project.items) {
|
||||
items.push(...project.items.nodes.map(({type, fieldValues:{nodes:fields}}) => ({type, text:fields.filter(field => field.text).shift()?.text ?? ""})))
|
||||
total = project.items.totalCount
|
||||
}
|
||||
//Append
|
||||
list.push({name: project.name, updated, description: project.body, progress: {enabled, todo, doing, done, total: todo + doing + done}})
|
||||
list.push({name: project.name, updated, description: project.body, progress: {enabled, todo, doing, done, total}, items})
|
||||
}
|
||||
|
||||
//Limit
|
||||
|
||||
@@ -2,8 +2,6 @@ name: 🗂️ GitHub projects
|
||||
category: github
|
||||
description: |
|
||||
This plugin displays progress of profile and repository projects.
|
||||
notes: |
|
||||
> ℹ️ This plugin currently only supports [GitHub projects boards](https://docs.github.com/en/issues/organizing-your-work-with-project-boards/managing-project-boards/about-project-boards) and not [GitHub projects (beta)](https://docs.github.com/en/issues/trying-out-the-new-projects-experience/about-projects)
|
||||
examples:
|
||||
default: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.projects.svg
|
||||
index: 25
|
||||
@@ -14,6 +12,7 @@ supports:
|
||||
scopes:
|
||||
- public_access
|
||||
- public_repo
|
||||
- read:project
|
||||
inputs:
|
||||
|
||||
plugin_projects:
|
||||
@@ -37,6 +36,8 @@ inputs:
|
||||
Featured repositories projects
|
||||
|
||||
Use the following syntax for each project `:user/:repo/projects/:project_id`
|
||||
|
||||
> ℹ️ [GitHub projects (beta)](https://docs.github.com/en/issues/trying-out-the-new-projects-experience/about-projects) needs to use the same syntax as above and repository must specified repository must be linked to given project.
|
||||
type: array
|
||||
example: username/repo/projects/1, username/repo/projects/2, ...
|
||||
format: comma-separated
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
query ProjectsRepository {
|
||||
$account(login: "$user") {
|
||||
repository(name: "$repository") {
|
||||
project(number: $id) {
|
||||
name
|
||||
body
|
||||
projectV2(number: $id) {
|
||||
name: title
|
||||
body: shortDescription
|
||||
updatedAt
|
||||
progress {
|
||||
doneCount
|
||||
inProgressCount
|
||||
todoCount
|
||||
enabled
|
||||
items(first: 4, orderBy: {field: POSITION, direction: ASC}) {
|
||||
totalCount
|
||||
nodes {
|
||||
type
|
||||
isArchived
|
||||
fieldValues(last: 100) {
|
||||
nodes {
|
||||
... on ProjectV2ItemFieldTextValue {
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
source/plugins/projects/queries/repository.legacy.graphql
Normal file
17
source/plugins/projects/queries/repository.legacy.graphql
Normal file
@@ -0,0 +1,17 @@
|
||||
query ProjectsRepositoryLegacy {
|
||||
$account(login: "$user") {
|
||||
repository(name: "$repository") {
|
||||
project(number: $id) {
|
||||
name
|
||||
body
|
||||
updatedAt
|
||||
progress {
|
||||
doneCount
|
||||
inProgressCount
|
||||
todoCount
|
||||
enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,24 @@
|
||||
query ProjectsUser {
|
||||
$account(login: "$login") {
|
||||
projects(last: $limit, states: OPEN, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||
projectsV2(last: $limit, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||
totalCount
|
||||
nodes {
|
||||
name
|
||||
body
|
||||
name: title
|
||||
body: shortDescription
|
||||
updatedAt
|
||||
progress {
|
||||
doneCount
|
||||
inProgressCount
|
||||
todoCount
|
||||
enabled
|
||||
items(first: 4, orderBy: {field: POSITION, direction: ASC}) {
|
||||
totalCount
|
||||
nodes {
|
||||
type
|
||||
isArchived
|
||||
fieldValues(last: 100) {
|
||||
nodes {
|
||||
... on ProjectV2ItemFieldTextValue {
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
source/plugins/projects/queries/user.legacy.graphql
Normal file
18
source/plugins/projects/queries/user.legacy.graphql
Normal file
@@ -0,0 +1,18 @@
|
||||
query ProjectsUserLegacy {
|
||||
$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