Skip to content

Commit f212731

Browse files
authored
Version 1.9 (#6)
1 parent 047d863 commit f212731

File tree

23 files changed

+454
-860
lines changed

23 files changed

+454
-860
lines changed

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ jobs:
8787
# Name of SVG image output
8888
filename: github-metrics.svg
8989

90+
# Template to use (see src/templates to get a list of supported templates)
91+
template: classic
92+
9093
# Enable Google PageSpeed metrics for account attached website
9194
# See https://developers.google.com/speed/docs/insights/v5/get-started for more informations
9295
plugin_pagespeed: no
@@ -230,6 +233,14 @@ Open and edit `settings.json` to configure your instance using a text editor of
230233
//Intended for easier development and disabled by default
231234
"debug":false,
232235
236+
//Template configuration
237+
"templates":{
238+
//Default template
239+
"default":"classic",
240+
//Enabled template. Leave empty to enable all defined templates
241+
"enabled":[],
242+
},
243+
233244
//Plugins configuration
234245
"plugins":{
235246
//Google PageSpeed plugin
@@ -322,6 +333,7 @@ systemctl status github_metrics
322333
<summary>⚠️ HTTP errors code</summary>
323334

324335
The following errors code can be encountered if on a server instance :
336+
* `400 Bad request` : Query is invalid (e.g. unsupported template)
325337
* `403 Forbidden` : User is not allowed in `restricted` users list
326338
* `404 Not found` : GitHub API did not found the requested user
327339
* `429 Too many requests` : Thrown when rate limiter is trigerred
@@ -514,10 +526,13 @@ Add the following to your workflow :
514526

515527
#### Metrics generator
516528

529+
* `src/setup.mjs` contains the configuration setup
517530
* `src/metrics.mjs` contains the metrics renderer
518-
* `src/query.graphql` is the GraphQL query sent to GitHub GraphQL API
519-
* `src/style.css` contains the style used by the generated SVG image
520-
* `src/template.svg` contains the template used by the generated SVG image
531+
* `src/templates/*` contains templates files
532+
* `src/templates/*/image.svg` contains the template used by the generated SVG image
533+
* `src/templates/*/query.graphql` is the GraphQL query sent to GitHub GraphQL API
534+
* `src/templates/*/style.css` contains the style used by the generated SVG image
535+
* `src/templates/*/template.mjs` contains the code which prepares data for rendering
521536
* `src/plugins/*` contains the source code of metrics plugins
522537

523538
#### Metrics server instance
@@ -527,6 +542,7 @@ Add the following to your workflow :
527542

528543
#### GitHub action
529544

545+
* `action.yml` contains the GitHub action descriptor
530546
* `action/index.mjs` contains the GitHub action code
531547
* `action/dist/index.js` contains compiled the GitHub action code
532548
* `utils/build.mjs` contains the GitHub action builder
@@ -541,18 +557,18 @@ Read the few sections below to get started with project structure.
541557

542558
#### Adding new metrics through GraphQL API, REST API or Third-Party service
543559

544-
To use [GitHub GraphQL API](https://docs.github.com/en/graphql), update the GraphQL query from `src/query.graphql`.
545-
Raw queried data should be exposed in `data.user` whereas computed data should be in `data.computed`, and code should be updated through `src/metrics.mjs`.
560+
To use [GitHub GraphQL API](https://docs.github.com/en/graphql), update the GraphQL query from `templates/*/query.graphql`.
561+
Raw queried data should be exposed in `data.user` whereas computed data should be in `data.computed`, and code should be updated through `templates/*/template.mjs`.
546562

547563
To use [GitHub Rest API](https://docs.github.com/en/rest) or a third-party service instead, create a new plugin in `src/plugins`.
548-
Plugins should be self-sufficient and re-exported from [src/plugins/index.mjs](https://github.com/lowlighter/metrics/blob/master/src/plugins/index.mjs), to be later included in the `//Plugins` section of `src/metrics.mjs`.
564+
Plugins should be self-sufficient and re-exported from [src/plugins/index.mjs](https://github.com/lowlighter/metrics/blob/master/src/plugins/index.mjs), to be later included in the `//Plugins` section of `templates/*/template.mjs`.
549565
Data generated should be exposed in `data.computed.plugins[plugin]` where `plugin` is your plugin's name.
550566

551567
#### Updating the SVG template
552568

553-
The SVG template is located in `src/template.svg` and include the CSS from `src/style.css`.
569+
The SVG template is located in `templates/*/image.svg` and include the CSS from `templates/*/style.css`.
554570

555-
It's actually a long JavaScript template string, so you can actually include variables (e.g. `` `${data.user.name}` ``) and execute inline code, like ternary conditions (e.g. `` `${computed.plugins.plugin ? `<div>${computed.plugins.plugin.data}</div>` : ""}` ``) which are useful for conditional statements.
571+
It is rendered with [EJS](https://github.com/mde/ejs) so you can actually include variables (e.g. `<%= user.name %>`) and execute simple code, like control statements.
556572

557573
#### Metrics server and GitHub action
558574

@@ -584,6 +600,8 @@ This way you'll be able to rapidly test SVG renders with your browser.
584600
* To apply rate limiting on server and avoid spams and hitting GitHub API's own rate limit
585601
* [octokit/graphql.js](https://github.com/octokit/graphql.js/) and [octokit/rest.js](https://github.com/octokit/rest.js)
586602
* To perform request to GitHub GraphQL API and GitHub REST API
603+
* [mde/ejs](https://github.com/mde/ejs)
604+
* To render SVG images
587605
* [ptarjan/node-cache](https://github.com/ptarjan/node-cache)
588606
* To cache generated content
589607
* [renanbastos93/image-to-base64](https://github.com/renanbastos93/image-to-base64)

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ inputs:
1717
filename:
1818
description: Name of SVG image output
1919
default: github-metrics.svg
20+
template:
21+
description: Template to use
22+
default: classic
2023
optimize:
2124
description: Optimize SVG image
2225
default: yes

0 commit comments

Comments
 (0)