Add notable contributions plugin (#222)
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
/**Mocked data */
|
||||||
|
export default function({faker, query, login = faker.internet.userName()}) {
|
||||||
|
console.debug("metrics/compute/mocks > mocking graphql api result > notable/contributions")
|
||||||
|
return /after: "MOCKED_CURSOR"/m.test(query) ? ({
|
||||||
|
user:{
|
||||||
|
repositoriesContributedTo:{
|
||||||
|
edges:[],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}) : ({
|
||||||
|
user:{
|
||||||
|
repositoriesContributedTo:{
|
||||||
|
edges:[
|
||||||
|
{
|
||||||
|
cursor:"MOCKED_CURSOR",
|
||||||
|
node:{
|
||||||
|
isInOrganization:true,
|
||||||
|
owner:{
|
||||||
|
login:faker.internet.userName(),
|
||||||
|
avatarUrl:null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/**Mocked data */
|
||||||
|
export default function({faker, query, login = faker.internet.userName()}) {
|
||||||
|
console.debug("metrics/compute/mocks > mocking graphql api result > notable/organizations")
|
||||||
|
return ({
|
||||||
|
user:{
|
||||||
|
organizations:{
|
||||||
|
nodes:[{
|
||||||
|
login:faker.internet.userName(),
|
||||||
|
avatarUrl:null,
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -165,6 +165,12 @@
|
|||||||
pr:{get count() { return this.open + this.merged }, open:faker.datatype.number(1000), merged:faker.datatype.number(1000)},
|
pr:{get count() { return this.open + this.merged }, open:faker.datatype.number(1000), merged:faker.datatype.number(1000)},
|
||||||
}
|
}
|
||||||
}) : null),
|
}) : null),
|
||||||
|
//Notable
|
||||||
|
...(set.plugins.enabled.notable ? ({
|
||||||
|
notable:{
|
||||||
|
contributions:new Array(2+faker.datatype.number(2)).fill(null).map(_ => ({name:faker.lorem.slug(), avatar:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg=="})),
|
||||||
|
}
|
||||||
|
}) : null),
|
||||||
//Gists
|
//Gists
|
||||||
...(set.plugins.enabled.gists ? ({
|
...(set.plugins.enabled.gists ? ({
|
||||||
gists:{
|
gists:{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: "🗃️ Base content"
|
name: "🗃️ Base content"
|
||||||
cost: 1 GraphQL request
|
cost: 2 GraphQL requests + 1 GraphQL request per 100 repositories fetched
|
||||||
categorie: core
|
categorie: core
|
||||||
supports:
|
supports:
|
||||||
- user
|
- user
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ query BaseUser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
repositoriesContributedTo {
|
repositoriesContributedTo(includeUserRepositories: true) {
|
||||||
totalCount
|
totalCount
|
||||||
}
|
}
|
||||||
followers {
|
followers {
|
||||||
|
|||||||
21
source/plugins/notable/README.md
Normal file
21
source/plugins/notable/README.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
### 🎩 Notable contributions
|
||||||
|
|
||||||
|
The *notable* plugin displays badges of organization where you commited at least once on main branch.
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<td align="center">
|
||||||
|
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.notable.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_notable: yes
|
||||||
|
```
|
||||||
48
source/plugins/notable/index.mjs
Normal file
48
source/plugins/notable/index.mjs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
//Setup
|
||||||
|
export default async function({login, q, imports, graphql, data, account, queries}, {enabled = false} = {}) {
|
||||||
|
//Plugin execution
|
||||||
|
try {
|
||||||
|
//Check if plugin is enabled and requirements are met
|
||||||
|
if ((!enabled)||(!q.notable))
|
||||||
|
return null
|
||||||
|
|
||||||
|
//Load inputs
|
||||||
|
imports.metadata.plugins.notable.inputs({data, account, q})
|
||||||
|
|
||||||
|
//Initialization
|
||||||
|
const organizations = new Map()
|
||||||
|
|
||||||
|
//Load organization memberships
|
||||||
|
try {
|
||||||
|
const {user:{organizations:{nodes}}} = await graphql(queries.notable.organizations({login}))
|
||||||
|
nodes.map(({login, avatarUrl}) => organizations.set(login, avatarUrl))
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.debug(`metrics/compute/${login}/plugins > notable > failed to load organizations memberships: ${error}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
//Iterate through contributed repositories from organizations
|
||||||
|
{
|
||||||
|
let cursor = null
|
||||||
|
let pushed = 0
|
||||||
|
do {
|
||||||
|
console.debug(`metrics/compute/${login}/plugins > notable > retrieving contributed repositories after ${cursor}`)
|
||||||
|
const {user:{repositoriesContributedTo:{edges}}} = await graphql(queries.notable.contributions({login, after:cursor ? `after: "${cursor}"` : "", repositories:100}))
|
||||||
|
cursor = edges?.[edges?.length-1]?.cursor
|
||||||
|
edges.map(({node}) => node.isInOrganization ? organizations.set(node.owner.login, node.owner.avatarUrl) : null)
|
||||||
|
pushed = edges.length
|
||||||
|
} while ((pushed)&&(cursor))
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set contributions
|
||||||
|
const contributions = (await Promise.all([...organizations.entries()].map(async([name, avatarUrl]) => ({name, avatar:await imports.imgb64(avatarUrl)})))).sort((a, b) => a.name.localeCompare(b.name))
|
||||||
|
console.debug(`metrics/compute/${login}/plugins > notable > found contributions to ${organizations.length} organizations`)
|
||||||
|
|
||||||
|
//Results
|
||||||
|
return {contributions}
|
||||||
|
}
|
||||||
|
//Handle errors
|
||||||
|
catch (error) {
|
||||||
|
throw {error:{message:"An error occured", instance:error}}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
source/plugins/notable/metadata.yml
Normal file
13
source/plugins/notable/metadata.yml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
name: "🎩 Notable contributions"
|
||||||
|
cost: 1 GraphQL request per 100 repositories fetched
|
||||||
|
categorie: github
|
||||||
|
index: 18
|
||||||
|
supports:
|
||||||
|
- user
|
||||||
|
inputs:
|
||||||
|
|
||||||
|
# Enable or disable plugin
|
||||||
|
plugin_notable:
|
||||||
|
description: Display notable contributions in organizations
|
||||||
|
type: boolean
|
||||||
|
default: no
|
||||||
16
source/plugins/notable/queries/contributions.graphql
Normal file
16
source/plugins/notable/queries/contributions.graphql
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
query NotableContributions {
|
||||||
|
user(login: "$login") {
|
||||||
|
repositoriesContributedTo($after first: $repositories, contributionTypes: COMMIT) {
|
||||||
|
edges {
|
||||||
|
cursor
|
||||||
|
node {
|
||||||
|
isInOrganization
|
||||||
|
owner {
|
||||||
|
login
|
||||||
|
avatarUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
source/plugins/notable/queries/organizations.graphql
Normal file
11
source/plugins/notable/queries/organizations.graphql
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
query NotableOrganizations {
|
||||||
|
user(login: "$login") {
|
||||||
|
organizations(first: 100) {
|
||||||
|
nodes {
|
||||||
|
login
|
||||||
|
avatarUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
5
source/plugins/notable/tests.yml
Normal file
5
source/plugins/notable/tests.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
- name: Notable plugin (default)
|
||||||
|
uses: lowlighter/metrics@latest
|
||||||
|
with:
|
||||||
|
token: MOCKED_TOKEN
|
||||||
|
plugin_notable: yes
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
name: "🌇 GitHub Skyline 3D calendar"
|
name: "🌇 GitHub Skyline 3D calendar"
|
||||||
cost: N/A
|
cost: N/A
|
||||||
categorie: github
|
categorie: github
|
||||||
index: 18
|
index: 19
|
||||||
supports:
|
supports:
|
||||||
- user
|
- user
|
||||||
inputs:
|
inputs:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"base.repositories",
|
"base.repositories",
|
||||||
"followup",
|
"followup",
|
||||||
"languages",
|
"languages",
|
||||||
|
"notable",
|
||||||
"projects",
|
"projects",
|
||||||
"gists",
|
"gists",
|
||||||
"pagespeed",
|
"pagespeed",
|
||||||
|
|||||||
27
source/templates/classic/partials/notable.ejs
Normal file
27
source/templates/classic/partials/notable.ejs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<% if (plugins.notable) { %>
|
||||||
|
<section>
|
||||||
|
<h2 class="field">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M1 2.5A2.5 2.5 0 013.5 0h8.75a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0V1.5h-8a1 1 0 00-1 1v6.708A2.492 2.492 0 013.5 9h3.25a.75.75 0 010 1.5H3.5a1 1 0 100 2h5.75a.75.75 0 010 1.5H3.5A2.5 2.5 0 011 11.5v-9zm13.23 7.79a.75.75 0 001.06-1.06l-2.505-2.505a.75.75 0 00-1.06 0L9.22 9.229a.75.75 0 001.06 1.061l1.225-1.224v6.184a.75.75 0 001.5 0V9.066l1.224 1.224z"></path></svg>
|
||||||
|
Notable contributions
|
||||||
|
</h2>
|
||||||
|
<% if (plugins.notable.error) { %>
|
||||||
|
<div class="row">
|
||||||
|
<section>
|
||||||
|
<div class="field error">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2.343 13.657A8 8 0 1113.657 2.343 8 8 0 012.343 13.657zM6.03 4.97a.75.75 0 00-1.06 1.06L6.94 8 4.97 9.97a.75.75 0 101.06 1.06L8 9.06l1.97 1.97a.75.75 0 101.06-1.06L9.06 8l1.97-1.97a.75.75 0 10-1.06-1.06L8 6.94 6.03 4.97z"></path></svg>
|
||||||
|
<%= plugins.notable.error.message %>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
<% } else { %>
|
||||||
|
<div class="row organization contributions">
|
||||||
|
<% for (const {name, avatar} of plugins.notable.contributions) { %>
|
||||||
|
<div class="organization contribution">
|
||||||
|
<img class="organization avatar" src="<%= avatar %>" width="16" height="16" />
|
||||||
|
<span class="organization name">@<%= name %></span>
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
|
</section>
|
||||||
|
<% } %>
|
||||||
@@ -92,10 +92,34 @@
|
|||||||
margin: 0 6px;
|
margin: 0 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.avatar.organization {
|
.organization.avatar {
|
||||||
border-radius: 15%;
|
border-radius: 15%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.organization.name {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.organization.contributions {
|
||||||
|
margin: 0 8px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contribution.organization {
|
||||||
|
display: flex;
|
||||||
|
border: 1px solid #959da5;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 2px 6px;
|
||||||
|
padding-left: 0;
|
||||||
|
margin: 2px;
|
||||||
|
font-size: 12px;
|
||||||
|
background-color: #959da520;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contribution.organization .avatar {
|
||||||
|
margin: 0 4px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Commit calendar */
|
/* Commit calendar */
|
||||||
.calendar.field {
|
.calendar.field {
|
||||||
margin: 4px 0;
|
margin: 4px 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user