Skip to content

Commit

Permalink
The great refactor (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Jan 30, 2021
1 parent f8c6d19 commit 682e43e
Show file tree
Hide file tree
Showing 158 changed files with 6,656 additions and 4,940 deletions.
26 changes: 8 additions & 18 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,15 @@ assignees: ''
👋 Hi there!
Thanks for using metrics and helping us to improve!
Please check the following before filling a bug report:
- It does not duplicate another existing issue
- Retry at least once to confirm that it was not some random error
Please:
- Check you're not duplicating an existing issue
- Provide a clear and concise description
For visual issues, mispelled words, etc. ...
- Provide a description of what you expected to happen
- Optionally add screenshots or additional context
For workflows errors:
- Retry at least once to confirm that error is reproductible
- Paste an excerpt of your workflow step and error logs
For runtime errors...
impacting action version:
- Paste an excerpt of:
- workflow step
- error logs
- direct GitHub links to the above
impacting web instance version:
- Paste used url query
For other issues...
- Just write a clear and concise description of what the bug is
For web instance errors:
- Paste used url query
-->
14 changes: 4 additions & 10 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ assignees: ''
👋 Hi there!
Thanks for using metrics and helping us to improve!
Please check the following before filling a feature request:
- It does not duplicate another existing issue
Please:
- Check you're not duplicating an existing issue
- It is not mentioned in https://github.com/lowlighter/metrics/projects/1
For plugin requests...
- Add "plugin" label
- Optionally add screenshots or additional context
For other requests...
- Just write a clear and concise description about the feature request
- Optionally add screenshots or additional context
- Add correct labeling
- Provide a clear and concise description
-->
20 changes: 4 additions & 16 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,9 @@ assignees: ''
👋 Hi there!
Thanks for using metrics!
Before asking a question or for help, try to:
- Search for a similar already existing issue
- Check README.md documentation
- Note that most of documentation is collapsed by default, so be sure to open sections marked with "▶",
the solution to your problem may already be present!
For setup help...
- Be sure to create required secrets (METRICS_TOKEN and other plugins token when needed)
- Paste an excerpt of:
- workflow step
- error logs (if applicable)
- direct GitHub links to the above
- Optionally add screenshots or additional context
For other questions...
- Just write about what you want to talk!
Please:
- Search for similar issues
- Check documentation
- Provide a clear and concise description
-->
10 changes: 2 additions & 8 deletions .github/config/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ repository:
- .github/**
- .gitignore
- .gitattributes
- README.md
- SECURITY.md
- LICENSE
- CONTRIBUTING.md
Expand All @@ -15,22 +14,17 @@ docker:

# Metrics source code editions
core:
- source/app/metrics.mjs
- source/app/setup.mjs
- source/app/metrics/**
action:
- source/app/action/**
- action.yml
web:
- source/app/web/**
- settings.example.json
plugins:
- source/plugins/**
queries:
- source/queries/**
templates:
- source/templates/**
tests:
- source/app/mocks.mjs
- source/app/mocks/**
- tests/**
dependencies:
- package.json
Expand Down
53 changes: 53 additions & 0 deletions .github/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//Imports
import ejs from "ejs"
import fs from "fs/promises"
import paths from "path"
import url from "url"
import sgit from "simple-git"
import metadata from "../source/app/metrics/metadata.mjs"

//Mode
const [mode = "dryrun"] = process.argv.slice(2)
console.log(`Mode: ${mode}`)

//Paths
const __metrics = paths.join(paths.dirname(url.fileURLToPath(import.meta.url)), "..")
const __action = paths.join(__metrics, "source/app/action")
const __web = paths.join(__metrics, "source/app/web")
const __readme = paths.join(__metrics, ".github/readme")

//Git setup
const git = sgit(__metrics)
const staged = new Set()

//Load plugins metadata
const {plugins, templates} = await metadata({log:false})

//Update generated files
async function update({source, output, options = {}}) {
//Regenerate file
console.log(`Generating ${output}`)
const content = await ejs.renderFile(source, {plugins, templates}, {async:true, ...options})
//Save result
const file = paths.join(__metrics, output)
await fs.writeFile(file, content)
//Add to git
staged.add(file)
}

//Rendering
await update({source:paths.join(__readme, "README.md"), output:"README.md", options:{root:__readme}})
await update({source:paths.join(__readme, "partials/documentation/plugins.md"), output:"source/plugins/README.md"})
await update({source:paths.join(__readme, "partials/documentation/templates.md"), output:"source/templates/README.md"})
await update({source:paths.join(__action, "action.yml"), output:"action.yml"})
await update({source:paths.join(__web, "settings.example.json"), output:"settings.example.json"})

//Commit and push
if (mode === "publish") {
await git
.addConfig("user.name", "GitHub Action")
.addConfig("user.email", "<>")
.add(...staged)
.commit("Auto regenerate files - [Skip GitHub Action]")
.push("origin", "master")
}
38 changes: 5 additions & 33 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,10 @@
👋 Hi there!
Thanks for contributing to metrics and helping us to improve!
Please check the following before opening a pull request:
- It does not duplicate another existing pull request
- It is not mentioned in https://github.com/lowlighter/metrics/projects/1
- If it is, ensure that maintainers are aware that you're working on this subject
Then, explain briefly what your pull request is about and link any related issues (if applicable) to help us keeping track.
For documentation updates....
- Check spelling before asking for a review
- Respect current formatting (check that your editions blends well with current state)
- Static images must be saved in /.github/readme/imgs and must be of width 1260px
- UI should always be set in English in screenshots
For new plugins...
- Ensure that you created:
- a plugin entrypoint named index.mjs in /source/plugins
- tests in /tests/metrics.test.js
- mocked data if needed (required for all APIs which requires a token or limited in requests)
- Ensure you updated:
- /source/app/action/index.mjs to support new plugin options and use correct typing
- /source/web/statics/* to support new plugin options
- /settings.example.json with new plugin name
- README.md to explain new plugin features
- Include a screenshot in your pull request description
- You can use `&config.output=png` option in your web instance for it
For all code editions...
- Ensure retro-compatibility with previous versions (
- (unless for unreleased features, for which breaking changes are allowed)
- Respect current formatting
- Prefers using appropriate single words for variables and plugins names
- Avoid using uppercases letters, brackets and semicolons when possible to avoid visual pollution
- Comments should be added before each "code paragraph" and are considered indent worthy
Please:
- Read CONTRIBUTING.md first
- Check you're not duplicating another existing pull request
- Add correct labeling
- Provide a clear and concise description
-->
7 changes: 7 additions & 0 deletions .github/readme/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 📊 Metrics

![Build](https://github.com/lowlighter/metrics/workflows/Build/badge.svg)

<% for (const partial of ["introduction", "shared", "setup", "documentation", "references", "license"]) { -%>
<%- await include(`/partials/${partial}.md`) %>
<% } %>
5 changes: 5 additions & 0 deletions .github/readme/partials/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 📚 Documentation

<% for (const partial of ["compatibility", "templates", "plugins", "organizations", "contributing"]) { %>
<%- await include(`/partials/documentation/${partial}.md`) -%>
<% } %>
15 changes: 15 additions & 0 deletions .github/readme/partials/documentation/compatibility.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### 🧰 Template/plugin compatibily matrix

<table>
<tr>
<th nowrap="nowrap">Template\Plugin</th><%# -%>
<% for (const [plugin, {icon}] of Object.entries(plugins).filter(([key, value]) => (value)&&(!["core"].includes(key)))) { %>
<th nowrap="nowrap" align="center"><%= icon %></th><% } %>
</tr><%# -%>
<% for (const [template, {name, readme}] of Object.entries(templates).filter(([key, value]) => (value)&&(!["community"].includes(key)))) { %>
<tr>
<th nowrap="nowrap"><%= name %></th><%# -%>
<% for (const [plugin] of Object.entries(plugins).filter(([key, value]) => (value)&&(!["core"].includes(key)))) { %>
<th nowrap="nowrap" align="center" data-plugin="<%= plugin %>"><%= readme.compatibility[plugin] ? "✔️" : "❌" %></th><% } %>
</tr><% } %>
</table>
9 changes: 9 additions & 0 deletions .github/readme/partials/documentation/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 💪 Customizing and contributing

Metrics is built to be easily customizable.
Fork this repository, switch used action from `lowlighter/metrics@latest` to your fork and start coding!

To suggest a new feature, report a bug or ask for help, fill an [issue](https://github.com/lowlighter/metrics/issues) describing it.

If you want to contribute, submit a [pull request](https://github.com/lowlighter/metrics/pulls).
Be sure to read [CONTRIBUTING.md](CONTRIBUTING.md) for more information about this.
48 changes: 48 additions & 0 deletions .github/readme/partials/documentation/organizations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
### 🏦 Organizations metrics

While metrics targets mainly user accounts, it's possible to render metrics for organization accounts.

![Metrics (organization account)](https://github.com/lowlighter/lowlighter/blob/master/metrics.organization.svg)

<details>
<summary>💬 Metrics for organizations</summary>

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**.

![Add read:org scope to personal token](.github/readme/imgs/setup_token_org_read_scope.png)

You'll also need to set `user` option with your organization name.

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).

Most of plugins supported by user accounts will work with organization accounts, but note that rendering metrics for organizations consume way more APIs requests.

To support private repositories, add full `repo` scope to your personal token.

#### ℹ️ Example workflow

```yaml
- uses: lowlighter/metrics@latest
with:
# ... other options
token: ${{ secrets.METRICS_TOKEN }} # A personal token from an user account with read:org scope
committer_token: ${{ secrets.GITHUB_TOKEN }} # GitHub auto-generated token
user: organization-name # Organization name
```

</details>

<details>
<summary>💬 Organizations memberships for user accounts</summary>

Only public memberships can be displayed by metrics by default.
You can manage your membership visibility in the `People` tab of your organization:

![Publish organization membership](.github/readme/imgs/setup_public_membership_org.png)

For organization memberships, add `read:org` scope to your personal token.

![Add read:org scope to personal token](.github/readme/imgs/setup_token_org_read_scope.png)


</details>
7 changes: 7 additions & 0 deletions .github/readme/partials/documentation/plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 🧩 Plugins

Plugins are features which provide additional content and lets you customize your rendered metrics.
See their respective documentation for more informations about how to setup them:
<% for (const [plugin, {name}] of Object.entries(plugins).filter(([key, value]) => value)) { %>
* [<%= name %>](/source/plugins/<%= plugin %>/README.md)<%# -%>
<% } %>
7 changes: 7 additions & 0 deletions .github/readme/partials/documentation/templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 🖼️ Templates

Templates lets you change general appearance of rendered metrics.
See their respective documentation for more informations about how to setup them:
<% for (const [template, {name}] of Object.entries(templates).filter(([key, value]) => value)) { %>
* [<%= name %>](/source/templates/<%= template %>/README.md)<%# -%>
<% } %>
80 changes: 80 additions & 0 deletions .github/readme/partials/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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!

<table>
<tr>
<th align="center">For user accounts</th>
<th align="center">For organization accounts</th>
</tr>
<tr>
<%- plugins.base.readme.demo?.replace(/<img src=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/g, `<img alt="" width="400" src=`) %>
</tr>
</table>
<% {
let cell = 0
const elements = Object.entries(plugins).filter(([key, value]) => (value)&&(!["base", "core"].includes(key)))
if (elements.length%2)
elements.push(["", {}])
%>
<table>
<tr>
<th colspan="2" align="center">
<a href="source/plugins/README.md">🧩 <%= elements.length %> plugins</a>
</th>
</tr>
<% for (let i = 0; i < elements.length; i+=2) {
const cells = [["even", elements[i]], ["odd", elements[i+1]]]
for (const [cell, [plugin, {name, readme}]] of cells) {
if (cell === "even") {
-%>
<tr>
<% } %> <th><a href="source/plugins/<%= plugin %>/README.md"><%= name -%></a></th>
<% if (cell === "odd") {
-%> </tr>
<% }}
for (const [cell, [plugin, {name, readme}]] of cells) {
if (cell === "even") {
-%>
<tr>
<% } %> <%- readme.demo.replace(/<img src=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/g, `<img alt="" width="400" src=`)?.split("\n")?.map((x, i) => i ? ` ${x}` : x)?.join("\n") %>
<% if (cell === "odd") {
-%> </tr>
<% }}} -%>
<tr>
<th colspan="2" align="center">
<a href="https://github.com/lowlighter/metrics/projects/1">More to come soon!</a>
</th>
</tr>
</table>
<% } %>
<% {
let cell = 0
const elements = Object.entries(templates).filter(([key, value]) => value)
if (elements.length%2)
elements.push(["", {}])
%>
<table>
<tr>
<th colspan="2" align="center">
<a href="source/templates/README.md">🖼️ <%= elements.length-1 %> templates</a>
</th>
</tr>
<% for (let i = 0; i < elements.length; i+=2) {
const cells = [["even", elements[i]], ["odd", elements[i+1]]]
for (const [cell, [template, {name, readme}]] of cells) {
if (cell === "even") {
-%>
<tr>
<% } %> <th><a href="source/templates/<%= template %>/README.md"><%= name -%></a></th>
<% if (cell === "odd") {
-%> </tr>
<% }}
for (const [cell, [template, {name, readme}]] of cells) {
if (cell === "even") {
-%>
<tr>
<% } %> <%- readme.demo.replace(/<img src=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/g, `<img alt="" width="400" src=`)?.split("\n")?.map((x, i) => i ? ` ${x}` : x)?.join("\n") %>
<% if (cell === "odd") {
-%> </tr>
<% }}} -%>
</table>
<% } %>
Loading

0 comments on commit 682e43e

Please sign in to comment.