Add plugin projects (#13)

* Add plugin projects

* Add images for readme
This commit is contained in:
Simon Lecoq
2020-12-08 19:13:36 +01:00
committed by GitHub
parent 4a312482eb
commit 1d11145c98
11 changed files with 165 additions and 24 deletions

View File

@@ -0,0 +1,58 @@
//Setup
export default async function ({login, graphql, q}, {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} = q
//Limit
limit = Math.max(1, Math.min(100, Number(limit)))
//Retrieve contribution calendar from graphql api
const {user:{projects}} = await graphql(`
query Projects {
user(login: "${login}") {
projects(last: ${limit}, states: OPEN, orderBy: {field: UPDATED_AT, direction: DESC}) {
totalCount
nodes {
name
updatedAt
progress {
doneCount
inProgressCount
todoCount
enabled
}
}
}
}
}
`
)
//Iterate through projects and format them
const list = []
for (const project of projects.nodes) {
//Format date
const time = (Date.now()-new Date(project.updatedAt).getTime())/(24*60*60*1000)
let updated = project.updatedAt
if (time < 1)
updated = "less than 1 day ago"
else if (time < 30)
updated = `${Math.floor(time)} day${time >= 2 ? "s" : ""} ago`
else
updated = new Date(project.updatedAt).toDateString().substring(4)
//Format progress
const {enabled, todoCount:todo, inProgressCount:doing, doneCount:done} = project.progress
//Append
list.push({name:project.name, updated, progress:{enabled, todo, doing, done, total:todo+doing+done}})
}
//Results
return {list, totalCount:projects.totalCount}
}
//Handle errors
catch (error) {
console.debug(error)
throw {error:{message:`An error occured`}}
}
}