forked from lowlighter/metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/lowlighter/metrics
- Loading branch information
Showing
18 changed files
with
464 additions
and
1 deletion.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
source/app/mocks/api/github/graphql/discussions.categories.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/**Mocked data */ | ||
export default function({faker, query, login = faker.internet.userName()}) { | ||
console.debug("metrics/compute/mocks > mocking graphql api result > contributors/commit") | ||
return /after: "MOCKED_CURSOR"/m.test(query) | ||
? ({ | ||
user:{ | ||
repositoryDiscussions:{ | ||
edges:[], | ||
nodes:[], | ||
} | ||
} | ||
}) | ||
: ({ | ||
user:{ | ||
repositoryDiscussions:{ | ||
edges:new Array(100).fill(null).map(_ => ({cursor:"MOCKED_CURSOR"})), | ||
nodes:new Array(100).fill(null).map(_ => ({ | ||
category:{ | ||
emoji:faker.random.arrayElement([":chart_with_upwards_trend:", ":chart_with_downwards_trend:", ":bar_char:"]), | ||
name:faker.lorem.slug() | ||
} | ||
})) | ||
} | ||
} | ||
}) | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
source/app/mocks/api/github/graphql/discussions.statistics.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/**Mocked data */ | ||
export default function({faker, query, login = faker.internet.userName()}) { | ||
console.debug("metrics/compute/mocks > mocking graphql api result > contributors/commit") | ||
return ({ | ||
user:{ | ||
started:{totalCount:faker.datatype.number(1000)}, | ||
comments:{totalCount:faker.datatype.number(1000)}, | ||
answers:{totalCount:faker.datatype.number(1000)} | ||
} | ||
}) | ||
} |
29 changes: 29 additions & 0 deletions
29
source/app/mocks/api/github/graphql/repositories.repository.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/**Mocked data */ | ||
export default function({faker, query, login = faker.internet.userName()}) { | ||
console.debug("metrics/compute/mocks > mocking graphql api result > stars/default") | ||
return ({ | ||
repository:{ | ||
createdAt: faker.date.past(), | ||
description:"📊 An image generator with 20+ metrics about your GitHub account such as activity, community, repositories, coding habits, website performances, music played, starred topics, etc. that you can put on your profile or elsewhere !", | ||
forkCount:faker.datatype.number(100), | ||
isFork:false, | ||
issues:{ | ||
totalCount:faker.datatype.number(100), | ||
}, | ||
nameWithOwner:"lowlighter/metrics", | ||
openGraphImageUrl:"https://repository-images.githubusercontent.com/293860197/7fd72080-496d-11eb-8fe0-238b38a0746a", | ||
pullRequests:{ | ||
totalCount:faker.datatype.number(100), | ||
}, | ||
stargazerCount:faker.datatype.number(10000), | ||
licenseInfo:{ | ||
nickname:null, | ||
name:"MIT License", | ||
}, | ||
primaryLanguage:{ | ||
color:"#f1e05a", | ||
name:"JavaScript", | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
### 💬 Discussions | ||
|
||
The *discussions* plugin displays your GitHub discussions metrics. | ||
|
||
<table> | ||
<td align="center"> | ||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.discussions.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_discussions: yes | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//Setup | ||
export default async function({login, q, imports, graphql, queries, data, account}, {enabled = false} = {}) { | ||
//Plugin execution | ||
try { | ||
//Check if plugin is enabled and requirements are met | ||
if ((!enabled)||(!q.discussions)) | ||
return null | ||
|
||
//Load inputs | ||
imports.metadata.plugins.discussions.inputs({data, account, q}) | ||
const discussions = {categories:{}} | ||
|
||
//Fetch general statistics | ||
const stats = Object.fromEntries(Object.entries((await graphql(queries.discussions.statistics({login}))).user).map(([key, value]) => [key, value.totalCount])) | ||
Object.assign(discussions, stats) | ||
|
||
//Load started discussions | ||
{ | ||
const fetched = [] | ||
const categories = {} | ||
let cursor = null | ||
let pushed = 0 | ||
do { | ||
console.debug(`metrics/compute/${login}/discussions > retrieving discussions after ${cursor}`) | ||
const {user:{repositoryDiscussions:{edges = [], nodes = []} = {}}} = await graphql(queries.discussions.categories({login, after:cursor ? `after: "${cursor}"` : ""})) | ||
cursor = edges?.[edges?.length - 1]?.cursor | ||
fetched.push(...nodes) | ||
pushed = nodes.length | ||
console.debug(`metrics/compute/${login}/discussions > retrieved ${pushed} discussions after ${cursor}`) | ||
} while ((pushed) && (cursor)) | ||
|
||
//Compute favorite category | ||
for (const category of [...fetched.map(({category:{emoji, name}}) => `${imports.emoji.get(emoji)} ${name}`)]) | ||
categories[category] = (categories[category] ?? 0) + 1 | ||
discussions.categories.stats = categories | ||
discussions.categories.favorite = Object.entries(categories).sort((a, b) => b[1] - a[1]).map(([name]) => name).shift() ?? null | ||
} | ||
|
||
//Results | ||
return discussions | ||
} | ||
//Handle errors | ||
catch (error) { | ||
throw {error:{message:"An error occured", instance:error}} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: "💬 Discussions" | ||
cost: 1 GraphQL request + 1 GraphQL request per 100 discussions started | ||
category: github | ||
supports: | ||
- user | ||
inputs: | ||
|
||
# Enable or disable plugin | ||
plugin_discussions: | ||
description: GitHub discussions metrics | ||
type: boolean | ||
default: no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
query DiscussionsCategories { | ||
user(login: "$login") { | ||
repositoryDiscussions($after first: 100, orderBy: {field: CREATED_AT, direction: DESC}) { | ||
edges { | ||
cursor | ||
} | ||
nodes { | ||
category { | ||
emoji | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
query DiscussionsStatistics { | ||
user(login: "$login") { | ||
started: repositoryDiscussions { | ||
totalCount | ||
} | ||
comments: repositoryDiscussionComments { | ||
totalCount | ||
} | ||
answers: repositoryDiscussionComments(onlyAnswers: true) { | ||
totalCount | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- name: Discussions plugin (default) | ||
uses: lowlighter/metrics@latest | ||
with: | ||
token: MOCKED_TOKEN | ||
plugin_discussions: yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
### 📓 Repositories | ||
|
||
The *repositories* plugin can display a list of chosen featured repositories. | ||
|
||
<table> | ||
<td align="center"> | ||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.repositories.svg"> | ||
<img width="900" height="1" alt=""> | ||
</td> | ||
</table> | ||
|
||
It is mostly intended for external usage as [pinned repositories](https://www.google.com/search?client=firefox-b-d&q=github+pinned+repositories) is probably a better alternative if you want to embed them on your profile. | ||
|
||
Because of limitations of using SVG inside of `<img>` tags, people won't be able to click on it. | ||
|
||
#### ℹ️ Examples workflows | ||
|
||
[➡️ Available options for this plugin](metadata.yml) | ||
|
||
```yaml | ||
- uses: lowlighter/metrics@latest | ||
with: | ||
# ... other options | ||
plugin_repositories: yes | ||
plugin_repositories_list: lowlighter/metrics, denoland/deno # List of repositories you want to feature | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//Setup | ||
export default async function({login, q, imports, graphql, queries, data, account}, {enabled = false} = {}) { | ||
//Plugin execution | ||
try { | ||
//Check if plugin is enabled and requirements are met | ||
if ((!enabled)||(!q.repositories)) | ||
return null | ||
|
||
//Load inputs | ||
let {featured} = imports.metadata.plugins.repositories.inputs({data, account, q}) | ||
|
||
//Initialization | ||
const repositories = {list:[]} | ||
|
||
//Fetch repositories informations | ||
for (const repo of featured) { | ||
const {owner = login, name} = repo.match(/^(?:(?<owner>[\s\S]*)[/])?(?<name>[\s\S]+)$/)?.groups ?? {} | ||
const {repository} = await graphql(queries.repositories.repository({owner, name})) | ||
repositories.list.push(repository) | ||
|
||
//Format date | ||
const time = (Date.now() - new Date(repository.createdAt).getTime()) / (24 * 60 * 60 * 1000) | ||
let created = new Date(repository.createdAt).toDateString().substring(4) | ||
if (time < 1) | ||
created = `${Math.ceil(time * 24)} hour${Math.ceil(time * 24) >= 2 ? "s" : ""} ago` | ||
else if (time < 30) | ||
created = `${Math.floor(time)} day${time >= 2 ? "s" : ""} ago` | ||
repository.created = created | ||
} | ||
|
||
//Results | ||
return repositories | ||
} | ||
//Handle errors | ||
catch (error) { | ||
throw {error:{message:"An error occured", instance:error}} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: "📓 Repositories" | ||
cost: 1 GraphQL request per repository | ||
category: github | ||
supports: | ||
- user | ||
- organization | ||
inputs: | ||
|
||
# Enable or disable plugin | ||
plugin_repositories: | ||
description: Display chosen featured repositories | ||
type: boolean | ||
default: no | ||
|
||
# Featured repositories to display | ||
# If no owner is specified, it will implicitly use the current account login as owner | ||
plugin_repositories_featured: | ||
description: List of repositories to display | ||
type: array | ||
format: comma-separated | ||
default: "" | ||
example: lowlighter/metrics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
query RepositoriesRepository { | ||
repository(owner: "$owner", name: "$name") { | ||
createdAt | ||
description | ||
forkCount | ||
isFork | ||
issues { | ||
totalCount | ||
} | ||
nameWithOwner | ||
openGraphImageUrl | ||
licenseInfo { | ||
nickname | ||
spdxId | ||
name | ||
} | ||
pullRequests { | ||
totalCount | ||
} | ||
stargazerCount | ||
primaryLanguage { | ||
color | ||
name | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- name: Repositories plugin (default) | ||
uses: lowlighter/metrics@latest | ||
with: | ||
token: MOCKED_TOKEN | ||
plugin_repositories: yes | ||
plugin_repositories_list: metrics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.