Add user follow-up section (#250)

This commit is contained in:
Simon Lecoq
2021-04-22 18:03:39 +02:00
committed by GitHub
parent 42753e1c44
commit a0c2b39c37
14 changed files with 180 additions and 69 deletions

View File

@@ -5,6 +5,9 @@ The *followup* plugin displays the ratio of open/closed issues and the ratio of
<table>
<td align="center">
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.followup.svg">
<details><summary>Created by user version</summary>
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.followup.user.svg">
</details>
<img width="900" height="1" alt="">
</td>
</table>
@@ -18,5 +21,6 @@ The *followup* plugin displays the ratio of open/closed issues and the ratio of
with:
# ... other options
plugin_followup: yes
plugin_followup_sections: repositories, user #
```

View File

@@ -1,5 +1,5 @@
//Setup
export default async function({data, computed, imports, q, account}, {enabled = false} = {}) {
export default async function({login, data, computed, imports, q, graphql, queries, account}, {enabled = false} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
@@ -7,10 +7,11 @@
return null
//Load inputs
imports.metadata.plugins.followup.inputs({data, account, q})
let {sections} = imports.metadata.plugins.followup.inputs({data, account, q})
//Define getters
const followup = {
sections,
issues:{
get count() {
return this.open + this.closed
@@ -24,17 +25,42 @@
},
pr:{
get count() {
return this.open + this.merged
return this.open + this.closed + this.merged
},
get open() {
return computed.repositories.pr_open
},
get closed() {
return computed.repositories.pr_closed
},
get merged() {
return computed.repositories.pr_merged
},
},
}
//Load user issues and pull requests
if (sections.includes("user")) {
const {user} = await graphql(queries.followup.user({login}))
followup.user = {
issues:{
get count() {
return this.open + this.closed
},
open:user.issues_open.totalCount,
closed:user.issues_closed.totalCount,
},
pr:{
get count() {
return this.open + this.closed + this.merged
},
open:user.pr_open.totalCount,
closed:user.pr_closed.totalCount,
merged:user.pr_merged.totalCount,
},
}
}
//Results
return followup
}

View File

@@ -1,5 +1,5 @@
name: "🎟️ Follow-up of issues and pull requests"
cost: 0 API request
cost: 0 API request (1 GraphQL request if "user" section is enabled)
categorie: github
index: 11
supports:
@@ -13,3 +13,13 @@ inputs:
description: Display follow-up of repositories issues and pull requests
type: boolean
default: no
# Sections to display
plugin_followup_sections:
description: Sections to display
type: array
format: comma-separated
default: repositories
values:
- repositories # Overall status of issues and pull requests on your repositories
- user # Overall status of issues and pull requests you have created on GitHub

View File

@@ -0,0 +1,19 @@
query FollowupUser {
user(login: "$login") {
issues_open:issues(states: OPEN) {
totalCount
}
issues_closed:issues(states: CLOSED) {
totalCount
}
pr_open:pullRequests(states: OPEN) {
totalCount
}
pr_closed:pullRequests(states: CLOSED) {
totalCount
}
pr_merged:pullRequests(states: MERGED) {
totalCount
}
}
}

View File

@@ -3,3 +3,10 @@
with:
token: MOCKED_TOKEN
plugin_followup: yes
- name: Follow-up plugin (complete)
uses: lowlighter/metrics@latest
with:
token: MOCKED_TOKEN
plugin_followup: yes
plugin_followup_sections: repositories, user