Add introduction plugin (#127)
This commit is contained in:
26
source/plugins/introduction/README.md
Normal file
26
source/plugins/introduction/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
### 🙋 Introduction
|
||||
|
||||
The *introduction* plugin display your account bio or your organization/repository description.
|
||||
It is mostly intended for metrics used outside of GitHub, since these informations are already available on GitHub.
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.introduction.svg">
|
||||
<details><summary>Repository version</summary>
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.introduction.repository.svg">
|
||||
</details>
|
||||
<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_introduction: yes
|
||||
plugin_introduction_title: no # Hide section title
|
||||
```
|
||||
31
source/plugins/introduction/index.mjs
Normal file
31
source/plugins/introduction/index.mjs
Normal file
@@ -0,0 +1,31 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, graphql, queries, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.introduction))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {title} = imports.metadata.plugins.introduction.inputs({data, account, q})
|
||||
|
||||
//Context
|
||||
let context = {mode:account, login}
|
||||
if (q.repo) {
|
||||
console.debug(`metrics/compute/${login}/plugins > people > switched to repository mode`)
|
||||
const {owner, repo} = data.user.repositories.nodes.map(({name:repo, owner:{login:owner}}) => ({repo, owner})).shift()
|
||||
context = {...context, mode:"repository", owner, repo}
|
||||
}
|
||||
|
||||
//Querying API
|
||||
console.debug(`metrics/compute/${login}/plugins > introduction > querying api`)
|
||||
const text = (await graphql(queries.introduction[context.mode](context)))[context.mode][{user:"bio", organization:"description", repository:"description"}[context.mode]]
|
||||
|
||||
//Results
|
||||
return {mode:context.mode, title, text}
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error:{message:"An error occured", instance:error}}
|
||||
}
|
||||
}
|
||||
20
source/plugins/introduction/metadata.yml
Normal file
20
source/plugins/introduction/metadata.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
name: "🙋 Introduction"
|
||||
cost: 1 GraphQL request
|
||||
categorie: github
|
||||
supports:
|
||||
- user
|
||||
- organization
|
||||
- repository
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_introduction:
|
||||
description: Display account or repository introduction
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# Display introduction section title
|
||||
plugin_introduction_title:
|
||||
description: Display introduction section title
|
||||
type: boolean
|
||||
default: yes
|
||||
5
source/plugins/introduction/queries/organization.graphql
Normal file
5
source/plugins/introduction/queries/organization.graphql
Normal file
@@ -0,0 +1,5 @@
|
||||
query IntroductionOrganization {
|
||||
organization(login: "$login") {
|
||||
description
|
||||
}
|
||||
}
|
||||
5
source/plugins/introduction/queries/repository.graphql
Normal file
5
source/plugins/introduction/queries/repository.graphql
Normal file
@@ -0,0 +1,5 @@
|
||||
query IntroductionRepository {
|
||||
repository(name: "$repo", owner: "$owner") {
|
||||
description
|
||||
}
|
||||
}
|
||||
5
source/plugins/introduction/queries/user.graphql
Normal file
5
source/plugins/introduction/queries/user.graphql
Normal file
@@ -0,0 +1,5 @@
|
||||
query IntroductionUser {
|
||||
user(login: "$login") {
|
||||
bio
|
||||
}
|
||||
}
|
||||
12
source/plugins/introduction/tests.yml
Normal file
12
source/plugins/introduction/tests.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
- name: Introduction plugin (default)
|
||||
uses: lowlighter/metrics@latest
|
||||
with:
|
||||
token: MOCKED_TOKEN
|
||||
plugin_introduction: yes
|
||||
|
||||
- name: Introduction plugin (complete)
|
||||
uses: lowlighter/metrics@latest
|
||||
with:
|
||||
token: MOCKED_TOKEN
|
||||
plugin_introduction: yes
|
||||
plugin_introduction_title: no
|
||||
Reference in New Issue
Block a user