The great refactor (#82)
This commit is contained in:
21
source/plugins/lines/README.md
Normal file
21
source/plugins/lines/README.md
Normal 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
|
||||
```
|
||||
@@ -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
|
||||
}
|
||||
|
||||
13
source/plugins/lines/metadata.yml
Normal file
13
source/plugins/lines/metadata.yml
Normal 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
|
||||
Reference in New Issue
Block a user