Add new option to contributors plugin (#146)
This commit is contained in:
@@ -7,6 +7,9 @@ It's especially useful to acknowledge contributors on release notes.
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.contributors.svg">
|
||||
<details open><summary>With number of contributions</summary>
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.contributors.contributions.svg">
|
||||
</details>
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</table>
|
||||
@@ -20,6 +23,8 @@ It's especially useful to acknowledge contributors on release notes.
|
||||
with:
|
||||
# ... other options
|
||||
plugin_contributors: yes
|
||||
plugin_contributors_base: "" # Base reference (commit, tag, branch, etc.)
|
||||
plugin_contributors_head: master # Head reference (commit, tag, branch, etc.)
|
||||
plugin_contributors_base: "" # Base reference (commit, tag, branch, etc.)
|
||||
plugin_contributors_head: master # Head reference (commit, tag, branch, etc.)
|
||||
plugin_contributors_ignored: bot # Ignore "bot" user
|
||||
plugin_contributors_contributions: yes # Display number of contributions for each contributor
|
||||
```
|
||||
@@ -7,7 +7,7 @@
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {head, base} = imports.metadata.plugins.contributors.inputs({data, account, q})
|
||||
let {head, base, ignored, contributions} = imports.metadata.plugins.contributors.inputs({data, account, q})
|
||||
const repo = {owner:data.repo.owner.login, repo:data.repo.name}
|
||||
|
||||
//Retrieve head and base commits
|
||||
@@ -20,7 +20,7 @@
|
||||
//Get commit activity
|
||||
console.debug(`metrics/compute/${login}/plugins > contributors > querying api for commits between [${ref.base?.abbreviatedOid ?? null}] and [${ref.head?.abbreviatedOid ?? null}]`)
|
||||
const commits = []
|
||||
for (let page = 0; ; page++) {
|
||||
for (let page = 1; ; page++) {
|
||||
console.debug(`metrics/compute/${login}/plugins > contributors > loading page ${page}`)
|
||||
try {
|
||||
const {data:loaded} = await rest.repos.listCommits({...repo, per_page:100, page})
|
||||
@@ -49,18 +49,26 @@
|
||||
|
||||
//Compute contributors and contributions
|
||||
let contributors = {}
|
||||
for (const {author:{login, avatar_url:avatar}} of commits) {
|
||||
if (!login)
|
||||
for (const {author:{login, avatar_url:avatar}, commit:{message = ""}} of commits) {
|
||||
if ((!login)||(ignored.includes(login))) {
|
||||
console.debug(`metrics/compute/${login}/plugins > contributors > ignored contributor "${login}"`)
|
||||
continue
|
||||
}
|
||||
if (!(login in contributors))
|
||||
contributors[login] = {avatar:avatar ? await imports.imgb64(avatar) : "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg==", contributions:0}
|
||||
else
|
||||
contributors[login] = {avatar:avatar ? await imports.imgb64(avatar) : "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg==", contributions:1, pr:[]}
|
||||
else {
|
||||
contributors[login].contributions++
|
||||
contributors[login].pr.push(...(message.match(/(?<=[(])#\d+(?=[)])/g) ?? []))
|
||||
}
|
||||
}
|
||||
contributors = Object.fromEntries(Object.entries(contributors).sort((a, b) => b.contributions - a.contributions))
|
||||
contributors = Object.fromEntries(Object.entries(contributors).sort(([_an, a], [_bn, b]) => b.contributions - a.contributions))
|
||||
|
||||
//Filter pull requests
|
||||
for (const contributor of Object.values(contributors))
|
||||
contributor.pr = [...new Set(contributor.pr)]
|
||||
|
||||
//Results
|
||||
return {head, base, ref, list:contributors}
|
||||
return {head, base, ref, list:contributors, contributions}
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
|
||||
@@ -21,4 +21,17 @@ inputs:
|
||||
plugin_contributors_head:
|
||||
description: Head reference
|
||||
type: string
|
||||
default: master
|
||||
default: master
|
||||
|
||||
# Ignored contributors (useful to ignore bots users)
|
||||
plugin_contributors_ignored:
|
||||
description: Contributors to ignore
|
||||
type: array
|
||||
format: comma-separated
|
||||
default: github-actions[bot]
|
||||
|
||||
# Display total contributions for each contributor
|
||||
plugin_contributors_contributions:
|
||||
description: Display contributions
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
token: MOCKED_TOKEN
|
||||
plugin_contributors: yes
|
||||
|
||||
- name: Contributors plugin (default)
|
||||
- name: Contributors plugin (complete)
|
||||
uses: lowlighter/metrics@latest
|
||||
with:
|
||||
token: MOCKED_TOKEN
|
||||
plugin_contributors: yes
|
||||
plugin_contributors_ignored: github-actions[bot]
|
||||
plugin_contributors_contributions: yes
|
||||
plugin_contributors_head: MOCKED_SHA
|
||||
plugin_contributors_base: MOCKED_SHA
|
||||
|
||||
Reference in New Issue
Block a user