Add new option to contributors plugin (#146)
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
return this.commit.author
|
return this.commit.author
|
||||||
},
|
},
|
||||||
commit:{
|
commit:{
|
||||||
|
message:faker.lorem.sentence(),
|
||||||
author:{
|
author:{
|
||||||
name:owner,
|
name:owner,
|
||||||
login:faker.internet.userName(),
|
login:faker.internet.userName(),
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ It's especially useful to acknowledge contributors on release notes.
|
|||||||
<table>
|
<table>
|
||||||
<td align="center">
|
<td align="center">
|
||||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.contributors.svg">
|
<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="">
|
<img width="900" height="1" alt="">
|
||||||
</td>
|
</td>
|
||||||
</table>
|
</table>
|
||||||
@@ -22,4 +25,6 @@ It's especially useful to acknowledge contributors on release notes.
|
|||||||
plugin_contributors: yes
|
plugin_contributors: yes
|
||||||
plugin_contributors_base: "" # Base 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_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
|
return null
|
||||||
|
|
||||||
//Load inputs
|
//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}
|
const repo = {owner:data.repo.owner.login, repo:data.repo.name}
|
||||||
|
|
||||||
//Retrieve head and base commits
|
//Retrieve head and base commits
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
//Get commit activity
|
//Get commit activity
|
||||||
console.debug(`metrics/compute/${login}/plugins > contributors > querying api for commits between [${ref.base?.abbreviatedOid ?? null}] and [${ref.head?.abbreviatedOid ?? null}]`)
|
console.debug(`metrics/compute/${login}/plugins > contributors > querying api for commits between [${ref.base?.abbreviatedOid ?? null}] and [${ref.head?.abbreviatedOid ?? null}]`)
|
||||||
const commits = []
|
const commits = []
|
||||||
for (let page = 0; ; page++) {
|
for (let page = 1; ; page++) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > contributors > loading page ${page}`)
|
console.debug(`metrics/compute/${login}/plugins > contributors > loading page ${page}`)
|
||||||
try {
|
try {
|
||||||
const {data:loaded} = await rest.repos.listCommits({...repo, per_page:100, page})
|
const {data:loaded} = await rest.repos.listCommits({...repo, per_page:100, page})
|
||||||
@@ -49,18 +49,26 @@
|
|||||||
|
|
||||||
//Compute contributors and contributions
|
//Compute contributors and contributions
|
||||||
let contributors = {}
|
let contributors = {}
|
||||||
for (const {author:{login, avatar_url:avatar}} of commits) {
|
for (const {author:{login, avatar_url:avatar}, commit:{message = ""}} of commits) {
|
||||||
if (!login)
|
if ((!login)||(ignored.includes(login))) {
|
||||||
|
console.debug(`metrics/compute/${login}/plugins > contributors > ignored contributor "${login}"`)
|
||||||
continue
|
continue
|
||||||
if (!(login in contributors))
|
|
||||||
contributors[login] = {avatar:avatar ? await imports.imgb64(avatar) : "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg==", contributions:0}
|
|
||||||
else
|
|
||||||
contributors[login].contributions++
|
|
||||||
}
|
}
|
||||||
contributors = Object.fromEntries(Object.entries(contributors).sort((a, b) => b.contributions - a.contributions))
|
if (!(login in contributors))
|
||||||
|
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(([_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
|
//Results
|
||||||
return {head, base, ref, list:contributors}
|
return {head, base, ref, list:contributors, contributions}
|
||||||
}
|
}
|
||||||
//Handle errors
|
//Handle errors
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|||||||
@@ -22,3 +22,16 @@ inputs:
|
|||||||
description: Head reference
|
description: Head reference
|
||||||
type: string
|
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
|
token: MOCKED_TOKEN
|
||||||
plugin_contributors: yes
|
plugin_contributors: yes
|
||||||
|
|
||||||
- name: Contributors plugin (default)
|
- name: Contributors plugin (complete)
|
||||||
uses: lowlighter/metrics@latest
|
uses: lowlighter/metrics@latest
|
||||||
with:
|
with:
|
||||||
token: MOCKED_TOKEN
|
token: MOCKED_TOKEN
|
||||||
plugin_contributors: yes
|
plugin_contributors: yes
|
||||||
|
plugin_contributors_ignored: github-actions[bot]
|
||||||
|
plugin_contributors_contributions: yes
|
||||||
plugin_contributors_head: MOCKED_SHA
|
plugin_contributors_head: MOCKED_SHA
|
||||||
plugin_contributors_base: MOCKED_SHA
|
plugin_contributors_base: MOCKED_SHA
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
console.debug(`metrics/compute/${login}/plugins > habits > querying api`)
|
console.debug(`metrics/compute/${login}/plugins > habits > querying api`)
|
||||||
const events = []
|
const events = []
|
||||||
try {
|
try {
|
||||||
for (let page = 0; page < pages; page++) {
|
for (let page = 1; page < pages; page++) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > habits > loading page ${page}`)
|
console.debug(`metrics/compute/${login}/plugins > habits > loading page ${page}`)
|
||||||
events.push(...(await rest.activity.listEventsForAuthenticatedUser({username:login, per_page:100, page})).data)
|
events.push(...(await rest.activity.listEventsForAuthenticatedUser({username:login, per_page:100, page})).data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -700,6 +700,23 @@
|
|||||||
.contributors .label img {
|
.contributors .label img {
|
||||||
margin-left: 0;
|
margin-left: 0;
|
||||||
}
|
}
|
||||||
|
.contributors .contributions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
font-size: .7rem;
|
||||||
|
margin-left: 6px;
|
||||||
|
margin-right: -10px;
|
||||||
|
background-color: #DDEEFF;
|
||||||
|
padding: 0 7px;
|
||||||
|
border-top-right-radius: 32px;
|
||||||
|
border-bottom-right-radius: 32px;
|
||||||
|
}
|
||||||
|
.contributors .contributions svg {
|
||||||
|
fill: #0366D6;
|
||||||
|
margin-left: 4px;
|
||||||
|
width: .8rem;
|
||||||
|
height: .8rem;
|
||||||
|
}
|
||||||
|
|
||||||
/* Introduction */
|
/* Introduction */
|
||||||
.introduction {
|
.introduction {
|
||||||
|
|||||||
@@ -17,10 +17,13 @@
|
|||||||
<%= plugins.contributors.error.message %>
|
<%= plugins.contributors.error.message %>
|
||||||
</div>
|
</div>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<% for (const [login, {avatar}] of Object.entries(plugins.contributors.list)) { %>
|
<% for (const [login, {avatar, contributions}] of Object.entries(plugins.contributors.list)) { %>
|
||||||
<div class="label">
|
<div class="label">
|
||||||
<img class="avatar" src="data:image/png;base64,<%= avatar %>" width="22" height="22" alt="" />
|
<img class="avatar" src="data:image/png;base64,<%= avatar %>" width="22" height="22" alt="" />
|
||||||
<%= login %>
|
<%= login %>
|
||||||
|
<% if (plugins.contributors.contributions) { %>
|
||||||
|
<div class="contributions"><%= contributions %> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M10.5 7.75a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0zm1.43.75a4.002 4.002 0 01-7.86 0H.75a.75.75 0 110-1.5h3.32a4.001 4.001 0 017.86 0h3.32a.75.75 0 110 1.5h-3.32z"></path></svg></div>
|
||||||
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
//Get commit activity
|
//Get commit activity
|
||||||
console.debug(`metrics/compute/${login}/${repo} > querying api for commits`)
|
console.debug(`metrics/compute/${login}/${repo} > querying api for commits`)
|
||||||
const commits = []
|
const commits = []
|
||||||
for (let page = 0; page < 100; page++) {
|
for (let page = 1; page < 100; page++) {
|
||||||
console.debug(`metrics/compute/${login}/${repo} > loading page ${page}`)
|
console.debug(`metrics/compute/${login}/${repo} > loading page ${page}`)
|
||||||
try {
|
try {
|
||||||
const {data} = await rest.repos.listCommits({owner:login, repo, per_page:100, page})
|
const {data} = await rest.repos.listCommits({owner:login, repo, per_page:100, page})
|
||||||
|
|||||||
Reference in New Issue
Block a user