The great refactor (#82)

This commit is contained in:
Simon Lecoq
2021-01-30 12:31:09 +01:00
committed by GitHub
parent f8c6d19a4e
commit 682e43e10b
158 changed files with 6738 additions and 5022 deletions

View File

@@ -0,0 +1,21 @@
### 👨‍💻 Lines of code changed
The *lines* of code plugin displays the number of lines of code you have added and removed across all of your repositories.
<table>
<td align="center">
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.lines.svg">
<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_lines: yes
```

View File

@@ -1,11 +1,14 @@
//Setup
export default async function ({login, data, rest, q}, {enabled = false} = {}) {
export default async function ({login, data, imports, rest, q, account}, {enabled = false} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
if ((!enabled)||(!q.lines))
return null
//Load inputs
imports.metadata.plugins.lines.inputs({data, account, q})
//Context
let context = {mode:"user"}
if (q.repo) {
@@ -15,10 +18,12 @@
//Repositories
const repositories = data.user.repositories.nodes.map(({name:repo, owner:{login:owner}}) => ({repo, owner})) ?? []
//Get contributors stats from repositories
console.debug(`metrics/compute/${login}/plugins > lines > querying api`)
const lines = {added:0, deleted:0}
const response = await Promise.all(repositories.map(async ({repo, owner}) => await rest.repos.getContributorsStats({owner, repo})))
//Compute changed lines
console.debug(`metrics/compute/${login}/plugins > lines > computing total diff`)
response.map(({data:repository}) => {
@@ -31,6 +36,7 @@
if (contributor)
contributor.weeks.forEach(({a, d}) => (lines.added += a, lines.deleted += d))
})
//Results
return lines
}

View File

@@ -0,0 +1,13 @@
name: "👨‍💻 Lines of code changed"
cost: 1 REST request per repository
supports:
- user
- organization
- repository
inputs:
# Enable or disable plugin
plugin_lines:
description: Display lines of code metrics
type: boolean
default: no