Skip to content

Commit 682e43e

Browse files
authored
The great refactor (lowlighter#82)
1 parent f8c6d19 commit 682e43e

File tree

158 files changed

+6656
-4940
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+6656
-4940
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+8-18
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,15 @@ assignees: ''
1212
👋 Hi there!
1313
Thanks for using metrics and helping us to improve!
1414
15-
Please check the following before filling a bug report:
16-
- It does not duplicate another existing issue
17-
- Retry at least once to confirm that it was not some random error
15+
Please:
16+
- Check you're not duplicating an existing issue
17+
- Provide a clear and concise description
1818
19-
For visual issues, mispelled words, etc. ...
20-
- Provide a description of what you expected to happen
21-
- Optionally add screenshots or additional context
19+
For workflows errors:
20+
- Retry at least once to confirm that error is reproductible
21+
- Paste an excerpt of your workflow step and error logs
2222
23-
For runtime errors...
24-
impacting action version:
25-
- Paste an excerpt of:
26-
- workflow step
27-
- error logs
28-
- direct GitHub links to the above
29-
30-
impacting web instance version:
31-
- Paste used url query
32-
33-
For other issues...
34-
- Just write a clear and concise description of what the bug is
23+
For web instance errors:
24+
- Paste used url query
3525
3626
-->

.github/ISSUE_TEMPLATE/feature_request.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@ assignees: ''
1212
👋 Hi there!
1313
Thanks for using metrics and helping us to improve!
1414
15-
Please check the following before filling a feature request:
16-
- It does not duplicate another existing issue
15+
Please:
16+
- Check you're not duplicating an existing issue
1717
- It is not mentioned in https://github.com/lowlighter/metrics/projects/1
18-
19-
For plugin requests...
20-
- Add "plugin" label
21-
- Optionally add screenshots or additional context
22-
23-
For other requests...
24-
- Just write a clear and concise description about the feature request
25-
- Optionally add screenshots or additional context
18+
- Add correct labeling
19+
- Provide a clear and concise description
2620
2721
-->

.github/ISSUE_TEMPLATE/question.md

+4-16
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,9 @@ assignees: ''
1212
👋 Hi there!
1313
Thanks for using metrics!
1414
15-
Before asking a question or for help, try to:
16-
- Search for a similar already existing issue
17-
- Check README.md documentation
18-
- Note that most of documentation is collapsed by default, so be sure to open sections marked with "▶",
19-
the solution to your problem may already be present!
20-
21-
For setup help...
22-
- Be sure to create required secrets (METRICS_TOKEN and other plugins token when needed)
23-
- Paste an excerpt of:
24-
- workflow step
25-
- error logs (if applicable)
26-
- direct GitHub links to the above
27-
- Optionally add screenshots or additional context
28-
29-
For other questions...
30-
- Just write about what you want to talk!
15+
Please:
16+
- Search for similar issues
17+
- Check documentation
18+
- Provide a clear and concise description
3119
3220
-->

.github/config/label.yml

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ repository:
33
- .github/**
44
- .gitignore
55
- .gitattributes
6-
- README.md
76
- SECURITY.md
87
- LICENSE
98
- CONTRIBUTING.md
@@ -15,22 +14,17 @@ docker:
1514

1615
# Metrics source code editions
1716
core:
18-
- source/app/metrics.mjs
19-
- source/app/setup.mjs
17+
- source/app/metrics/**
2018
action:
2119
- source/app/action/**
22-
- action.yml
2320
web:
2421
- source/app/web/**
25-
- settings.example.json
2622
plugins:
2723
- source/plugins/**
28-
queries:
29-
- source/queries/**
3024
templates:
3125
- source/templates/**
3226
tests:
33-
- source/app/mocks.mjs
27+
- source/app/mocks/**
3428
- tests/**
3529
dependencies:
3630
- package.json

.github/index.mjs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//Imports
2+
import ejs from "ejs"
3+
import fs from "fs/promises"
4+
import paths from "path"
5+
import url from "url"
6+
import sgit from "simple-git"
7+
import metadata from "../source/app/metrics/metadata.mjs"
8+
9+
//Mode
10+
const [mode = "dryrun"] = process.argv.slice(2)
11+
console.log(`Mode: ${mode}`)
12+
13+
//Paths
14+
const __metrics = paths.join(paths.dirname(url.fileURLToPath(import.meta.url)), "..")
15+
const __action = paths.join(__metrics, "source/app/action")
16+
const __web = paths.join(__metrics, "source/app/web")
17+
const __readme = paths.join(__metrics, ".github/readme")
18+
19+
//Git setup
20+
const git = sgit(__metrics)
21+
const staged = new Set()
22+
23+
//Load plugins metadata
24+
const {plugins, templates} = await metadata({log:false})
25+
26+
//Update generated files
27+
async function update({source, output, options = {}}) {
28+
//Regenerate file
29+
console.log(`Generating ${output}`)
30+
const content = await ejs.renderFile(source, {plugins, templates}, {async:true, ...options})
31+
//Save result
32+
const file = paths.join(__metrics, output)
33+
await fs.writeFile(file, content)
34+
//Add to git
35+
staged.add(file)
36+
}
37+
38+
//Rendering
39+
await update({source:paths.join(__readme, "README.md"), output:"README.md", options:{root:__readme}})
40+
await update({source:paths.join(__readme, "partials/documentation/plugins.md"), output:"source/plugins/README.md"})
41+
await update({source:paths.join(__readme, "partials/documentation/templates.md"), output:"source/templates/README.md"})
42+
await update({source:paths.join(__action, "action.yml"), output:"action.yml"})
43+
await update({source:paths.join(__web, "settings.example.json"), output:"settings.example.json"})
44+
45+
//Commit and push
46+
if (mode === "publish") {
47+
await git
48+
.addConfig("user.name", "GitHub Action")
49+
.addConfig("user.email", "<>")
50+
.add(...staged)
51+
.commit("Auto regenerate files - [Skip GitHub Action]")
52+
.push("origin", "master")
53+
}

.github/pull_request_template.md

+5-33
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,10 @@
33
👋 Hi there!
44
Thanks for contributing to metrics and helping us to improve!
55
6-
Please check the following before opening a pull request:
7-
- It does not duplicate another existing pull request
8-
- It is not mentioned in https://github.com/lowlighter/metrics/projects/1
9-
- If it is, ensure that maintainers are aware that you're working on this subject
10-
11-
Then, explain briefly what your pull request is about and link any related issues (if applicable) to help us keeping track.
12-
13-
For documentation updates....
14-
- Check spelling before asking for a review
15-
- Respect current formatting (check that your editions blends well with current state)
16-
- Static images must be saved in /.github/readme/imgs and must be of width 1260px
17-
- UI should always be set in English in screenshots
18-
19-
For new plugins...
20-
- Ensure that you created:
21-
- a plugin entrypoint named index.mjs in /source/plugins
22-
- tests in /tests/metrics.test.js
23-
- mocked data if needed (required for all APIs which requires a token or limited in requests)
24-
- Ensure you updated:
25-
- /source/app/action/index.mjs to support new plugin options and use correct typing
26-
- /source/web/statics/* to support new plugin options
27-
- /settings.example.json with new plugin name
28-
- README.md to explain new plugin features
29-
- Include a screenshot in your pull request description
30-
- You can use `&config.output=png` option in your web instance for it
31-
32-
For all code editions...
33-
- Ensure retro-compatibility with previous versions (
34-
- (unless for unreleased features, for which breaking changes are allowed)
35-
- Respect current formatting
36-
- Prefers using appropriate single words for variables and plugins names
37-
- Avoid using uppercases letters, brackets and semicolons when possible to avoid visual pollution
38-
- Comments should be added before each "code paragraph" and are considered indent worthy
6+
Please:
7+
- Read CONTRIBUTING.md first
8+
- Check you're not duplicating another existing pull request
9+
- Add correct labeling
10+
- Provide a clear and concise description
3911
4012
-->

.github/readme/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 📊 Metrics
2+
3+
![Build](https://github.com/lowlighter/metrics/workflows/Build/badge.svg)
4+
5+
<% for (const partial of ["introduction", "shared", "setup", "documentation", "references", "license"]) { -%>
6+
<%- await include(`/partials/${partial}.md`) %>
7+
<% } %>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 📚 Documentation
2+
3+
<% for (const partial of ["compatibility", "templates", "plugins", "organizations", "contributing"]) { %>
4+
<%- await include(`/partials/documentation/${partial}.md`) -%>
5+
<% } %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
### 🧰 Template/plugin compatibily matrix
2+
3+
<table>
4+
<tr>
5+
<th nowrap="nowrap">Template\Plugin</th><%# -%>
6+
<% for (const [plugin, {icon}] of Object.entries(plugins).filter(([key, value]) => (value)&&(!["core"].includes(key)))) { %>
7+
<th nowrap="nowrap" align="center"><%= icon %></th><% } %>
8+
</tr><%# -%>
9+
<% for (const [template, {name, readme}] of Object.entries(templates).filter(([key, value]) => (value)&&(!["community"].includes(key)))) { %>
10+
<tr>
11+
<th nowrap="nowrap"><%= name %></th><%# -%>
12+
<% for (const [plugin] of Object.entries(plugins).filter(([key, value]) => (value)&&(!["core"].includes(key)))) { %>
13+
<th nowrap="nowrap" align="center" data-plugin="<%= plugin %>"><%= readme.compatibility[plugin] ? "✔️" : "❌" %></th><% } %>
14+
</tr><% } %>
15+
</table>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## 💪 Customizing and contributing
2+
3+
Metrics is built to be easily customizable.
4+
Fork this repository, switch used action from `lowlighter/metrics@latest` to your fork and start coding!
5+
6+
To suggest a new feature, report a bug or ask for help, fill an [issue](https://github.com/lowlighter/metrics/issues) describing it.
7+
8+
If you want to contribute, submit a [pull request](https://github.com/lowlighter/metrics/pulls).
9+
Be sure to read [CONTRIBUTING.md](CONTRIBUTING.md) for more information about this.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
### 🏦 Organizations metrics
2+
3+
While metrics targets mainly user accounts, it's possible to render metrics for organization accounts.
4+
5+
![Metrics (organization account)](https://github.com/lowlighter/lowlighter/blob/master/metrics.organization.svg)
6+
7+
<details>
8+
<summary>💬 Metrics for organizations</summary>
9+
10+
Setup is the same as for user accounts, though you'll need to add `read:org` scope, **whether you're member of target organization or not**.
11+
12+
![Add read:org scope to personal token](.github/readme/imgs/setup_token_org_read_scope.png)
13+
14+
You'll also need to set `user` option with your organization name.
15+
16+
If you're encounting errors and your organization is using single sign-on, try to [authorize your personal token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on).
17+
18+
Most of plugins supported by user accounts will work with organization accounts, but note that rendering metrics for organizations consume way more APIs requests.
19+
20+
To support private repositories, add full `repo` scope to your personal token.
21+
22+
#### ℹ️ Example workflow
23+
24+
```yaml
25+
- uses: lowlighter/metrics@latest
26+
with:
27+
# ... other options
28+
token: ${{ secrets.METRICS_TOKEN }} # A personal token from an user account with read:org scope
29+
committer_token: ${{ secrets.GITHUB_TOKEN }} # GitHub auto-generated token
30+
user: organization-name # Organization name
31+
```
32+
33+
</details>
34+
35+
<details>
36+
<summary>💬 Organizations memberships for user accounts</summary>
37+
38+
Only public memberships can be displayed by metrics by default.
39+
You can manage your membership visibility in the `People` tab of your organization:
40+
41+
![Publish organization membership](.github/readme/imgs/setup_public_membership_org.png)
42+
43+
For organization memberships, add `read:org` scope to your personal token.
44+
45+
![Add read:org scope to personal token](.github/readme/imgs/setup_token_org_read_scope.png)
46+
47+
48+
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## 🧩 Plugins
2+
3+
Plugins are features which provide additional content and lets you customize your rendered metrics.
4+
See their respective documentation for more informations about how to setup them:
5+
<% for (const [plugin, {name}] of Object.entries(plugins).filter(([key, value]) => value)) { %>
6+
* [<%= name %>](/source/plugins/<%= plugin %>/README.md)<%# -%>
7+
<% } %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## 🖼️ Templates
2+
3+
Templates lets you change general appearance of rendered metrics.
4+
See their respective documentation for more informations about how to setup them:
5+
<% for (const [template, {name}] of Object.entries(templates).filter(([key, value]) => value)) { %>
6+
* [<%= name %>](/source/templates/<%= template %>/README.md)<%# -%>
7+
<% } %>
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
Generate your metrics that you can embed everywhere, including your GitHub profile readme! It works for both user and organization accounts, and even for repositories!
2+
3+
<table>
4+
<tr>
5+
<th align="center">For user accounts</th>
6+
<th align="center">For organization accounts</th>
7+
</tr>
8+
<tr>
9+
<%- plugins.base.readme.demo?.replace(/<img src=/g, `<img alt="" width="400" src=`) %>
10+
</tr>
11+
</table>
12+
<% {
13+
let cell = 0
14+
const elements = Object.entries(plugins).filter(([key, value]) => (value)&&(!["base", "core"].includes(key)))
15+
if (elements.length%2)
16+
elements.push(["", {}])
17+
%>
18+
<table>
19+
<tr>
20+
<th colspan="2" align="center">
21+
<a href="source/plugins/README.md">🧩 <%= elements.length %> plugins</a>
22+
</th>
23+
</tr>
24+
<% for (let i = 0; i < elements.length; i+=2) {
25+
const cells = [["even", elements[i]], ["odd", elements[i+1]]]
26+
for (const [cell, [plugin, {name, readme}]] of cells) {
27+
if (cell === "even") {
28+
-%>
29+
<tr>
30+
<% } %> <th><a href="source/plugins/<%= plugin %>/README.md"><%= name -%></a></th>
31+
<% if (cell === "odd") {
32+
-%> </tr>
33+
<% }}
34+
for (const [cell, [plugin, {name, readme}]] of cells) {
35+
if (cell === "even") {
36+
-%>
37+
<tr>
38+
<% } %> <%- readme.demo.replace(/<img src=/g, `<img alt="" width="400" src=`)?.split("\n")?.map((x, i) => i ? ` ${x}` : x)?.join("\n") %>
39+
<% if (cell === "odd") {
40+
-%> </tr>
41+
<% }}} -%>
42+
<tr>
43+
<th colspan="2" align="center">
44+
<a href="https://github.com/lowlighter/metrics/projects/1">More to come soon!</a>
45+
</th>
46+
</tr>
47+
</table>
48+
<% } %>
49+
<% {
50+
let cell = 0
51+
const elements = Object.entries(templates).filter(([key, value]) => value)
52+
if (elements.length%2)
53+
elements.push(["", {}])
54+
%>
55+
<table>
56+
<tr>
57+
<th colspan="2" align="center">
58+
<a href="source/templates/README.md">🖼️ <%= elements.length-1 %> templates</a>
59+
</th>
60+
</tr>
61+
<% for (let i = 0; i < elements.length; i+=2) {
62+
const cells = [["even", elements[i]], ["odd", elements[i+1]]]
63+
for (const [cell, [template, {name, readme}]] of cells) {
64+
if (cell === "even") {
65+
-%>
66+
<tr>
67+
<% } %> <th><a href="source/templates/<%= template %>/README.md"><%= name -%></a></th>
68+
<% if (cell === "odd") {
69+
-%> </tr>
70+
<% }}
71+
for (const [cell, [template, {name, readme}]] of cells) {
72+
if (cell === "even") {
73+
-%>
74+
<tr>
75+
<% } %> <%- readme.demo.replace(/<img src=/g, `<img alt="" width="400" src=`)?.split("\n")?.map((x, i) => i ? ` ${x}` : x)?.join("\n") %>
76+
<% if (cell === "odd") {
77+
-%> </tr>
78+
<% }}} -%>
79+
</table>
80+
<% } %>

0 commit comments

Comments
 (0)