Skip to content

Commit 19bb1b3

Browse files
authoredApr 9, 2021
Add notable contributions plugin (#222)
1 parent e63dee0 commit 19bb1b3

File tree

15 files changed

+218
-4
lines changed

15 files changed

+218
-4
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**Mocked data */
2+
export default function({faker, query, login = faker.internet.userName()}) {
3+
console.debug("metrics/compute/mocks > mocking graphql api result > notable/contributions")
4+
return /after: "MOCKED_CURSOR"/m.test(query) ? ({
5+
user:{
6+
repositoriesContributedTo:{
7+
edges:[],
8+
},
9+
},
10+
}) : ({
11+
user:{
12+
repositoriesContributedTo:{
13+
edges:[
14+
{
15+
cursor:"MOCKED_CURSOR",
16+
node:{
17+
isInOrganization:true,
18+
owner:{
19+
login:faker.internet.userName(),
20+
avatarUrl:null,
21+
},
22+
},
23+
},
24+
],
25+
},
26+
},
27+
})
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**Mocked data */
2+
export default function({faker, query, login = faker.internet.userName()}) {
3+
console.debug("metrics/compute/mocks > mocking graphql api result > notable/organizations")
4+
return ({
5+
user:{
6+
organizations:{
7+
nodes:[{
8+
login:faker.internet.userName(),
9+
avatarUrl:null,
10+
}],
11+
},
12+
},
13+
})
14+
}

‎source/app/web/statics/app.placeholder.js

+6
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@
165165
pr:{get count() { return this.open + this.merged }, open:faker.datatype.number(1000), merged:faker.datatype.number(1000)},
166166
}
167167
}) : null),
168+
//Notable
169+
...(set.plugins.enabled.notable ? ({
170+
notable:{
171+
contributions:new Array(2+faker.datatype.number(2)).fill(null).map(_ => ({name:faker.lorem.slug(), avatar:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg=="})),
172+
}
173+
}) : null),
168174
//Gists
169175
...(set.plugins.enabled.gists ? ({
170176
gists:{

‎source/plugins/base/metadata.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "🗃️ Base content"
2-
cost: 1 GraphQL request
2+
cost: 2 GraphQL requests + 1 GraphQL request per 100 repositories fetched
33
categorie: core
44
supports:
55
- user

‎source/plugins/base/queries/user.graphql

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ query BaseUser {
4848
}
4949
}
5050
}
51-
repositoriesContributedTo {
51+
repositoriesContributedTo(includeUserRepositories: true) {
5252
totalCount
5353
}
5454
followers {

‎source/plugins/notable/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### 🎩 Notable contributions
2+
3+
The *notable* plugin displays badges of organization where you commited at least once on main branch.
4+
5+
<table>
6+
<td align="center">
7+
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.notable.svg">
8+
<img width="900" height="1" alt="">
9+
</td>
10+
</table>
11+
12+
#### ℹ️ Examples workflows
13+
14+
[➡️ Available options for this plugin](metadata.yml)
15+
16+
```yaml
17+
- uses: lowlighter/metrics@latest
18+
with:
19+
# ... other options
20+
plugin_notable: yes
21+
```

‎source/plugins/notable/index.mjs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//Setup
2+
export default async function({login, q, imports, graphql, data, account, queries}, {enabled = false} = {}) {
3+
//Plugin execution
4+
try {
5+
//Check if plugin is enabled and requirements are met
6+
if ((!enabled)||(!q.notable))
7+
return null
8+
9+
//Load inputs
10+
imports.metadata.plugins.notable.inputs({data, account, q})
11+
12+
//Initialization
13+
const organizations = new Map()
14+
15+
//Load organization memberships
16+
try {
17+
const {user:{organizations:{nodes}}} = await graphql(queries.notable.organizations({login}))
18+
nodes.map(({login, avatarUrl}) => organizations.set(login, avatarUrl))
19+
}
20+
catch (error) {
21+
console.debug(`metrics/compute/${login}/plugins > notable > failed to load organizations memberships: ${error}`)
22+
}
23+
24+
//Iterate through contributed repositories from organizations
25+
{
26+
let cursor = null
27+
let pushed = 0
28+
do {
29+
console.debug(`metrics/compute/${login}/plugins > notable > retrieving contributed repositories after ${cursor}`)
30+
const {user:{repositoriesContributedTo:{edges}}} = await graphql(queries.notable.contributions({login, after:cursor ? `after: "${cursor}"` : "", repositories:100}))
31+
cursor = edges?.[edges?.length-1]?.cursor
32+
edges.map(({node}) => node.isInOrganization ? organizations.set(node.owner.login, node.owner.avatarUrl) : null)
33+
pushed = edges.length
34+
} while ((pushed)&&(cursor))
35+
}
36+
37+
//Set contributions
38+
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))
39+
console.debug(`metrics/compute/${login}/plugins > notable > found contributions to ${organizations.length} organizations`)
40+
41+
//Results
42+
return {contributions}
43+
}
44+
//Handle errors
45+
catch (error) {
46+
throw {error:{message:"An error occured", instance:error}}
47+
}
48+
}

‎source/plugins/notable/metadata.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: "🎩 Notable contributions"
2+
cost: 1 GraphQL request per 100 repositories fetched
3+
categorie: github
4+
index: 18
5+
supports:
6+
- user
7+
inputs:
8+
9+
# Enable or disable plugin
10+
plugin_notable:
11+
description: Display notable contributions in organizations
12+
type: boolean
13+
default: no
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
query NotableContributions {
2+
user(login: "$login") {
3+
repositoriesContributedTo($after first: $repositories, contributionTypes: COMMIT) {
4+
edges {
5+
cursor
6+
node {
7+
isInOrganization
8+
owner {
9+
login
10+
avatarUrl
11+
}
12+
}
13+
}
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
query NotableOrganizations {
2+
user(login: "$login") {
3+
organizations(first: 100) {
4+
nodes {
5+
login
6+
avatarUrl
7+
}
8+
}
9+
}
10+
}
11+

‎source/plugins/notable/tests.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- name: Notable plugin (default)
2+
uses: lowlighter/metrics@latest
3+
with:
4+
token: MOCKED_TOKEN
5+
plugin_notable: yes

‎source/plugins/skyline/metadata.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: "🌇 GitHub Skyline 3D calendar"
22
cost: N/A
33
categorie: github
4-
index: 18
4+
index: 19
55
supports:
66
- user
77
inputs:

‎source/templates/classic/partials/_.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"base.repositories",
66
"followup",
77
"languages",
8+
"notable",
89
"projects",
910
"gists",
1011
"pagespeed",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<% if (plugins.notable) { %>
2+
<section>
3+
<h2 class="field">
4+
<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>
5+
Notable contributions
6+
</h2>
7+
<% if (plugins.notable.error) { %>
8+
<div class="row">
9+
<section>
10+
<div class="field error">
11+
<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>
12+
<%= plugins.notable.error.message %>
13+
</div>
14+
</section>
15+
</div>
16+
<% } else { %>
17+
<div class="row organization contributions">
18+
<% for (const {name, avatar} of plugins.notable.contributions) { %>
19+
<div class="organization contribution">
20+
<img class="organization avatar" src="<%= avatar %>" width="16" height="16" />
21+
<span class="organization name">@<%= name %></span>
22+
</div>
23+
<% } %>
24+
</div>
25+
<% } %>
26+
</section>
27+
<% } %>

‎source/templates/classic/style.css

+25-1
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,34 @@
9292
margin: 0 6px;
9393
}
9494

95-
.avatar.organization {
95+
.organization.avatar {
9696
border-radius: 15%;
9797
}
9898

99+
.organization.name {
100+
white-space: nowrap;
101+
}
102+
103+
.organization.contributions {
104+
margin: 0 8px;
105+
flex-wrap: wrap;
106+
}
107+
108+
.contribution.organization {
109+
display: flex;
110+
border: 1px solid #959da5;
111+
border-radius: 6px;
112+
padding: 2px 6px;
113+
padding-left: 0;
114+
margin: 2px;
115+
font-size: 12px;
116+
background-color: #959da520;
117+
}
118+
119+
.contribution.organization .avatar {
120+
margin: 0 4px;
121+
}
122+
99123
/* Commit calendar */
100124
.calendar.field {
101125
margin: 4px 0;

0 commit comments

Comments
 (0)
Failed to load comments.