Skip to content

Commit 3e26d37

Browse files
authored
Web instances: Add flags to enable unsafe extra features (lowlighter#438)
1 parent 9e77a1b commit 3e26d37

File tree

8 files changed

+30
-21
lines changed

8 files changed

+30
-21
lines changed

source/app/web/settings.example.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/plugins/core/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default async function({login, q}, {conf, data, rest, graphql, plugins, q
4747
pending.push((async () => {
4848
try {
4949
console.debug(`metrics/compute/${login}/plugins > ${name} > started`)
50-
data.plugins[name] = await imports.plugins[name]({login, q, imports, data, computed, rest, graphql, queries, account}, plugins[name])
50+
data.plugins[name] = await imports.plugins[name]({login, q, imports, data, computed, rest, graphql, queries, account}, {...plugins[name], extras:conf.settings?.extras?.features ?? conf.settings?.extras?.default ?? false})
5151
console.debug(`metrics/compute/${login}/plugins > ${name} > completed`)
5252
}
5353
catch (error) {

source/plugins/habits/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Use a full `repo` scope token to access **private** events.
2121

2222
By default, dates use Greenwich meridian (GMT/UTC). Be sure to set your timezone (see [here](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) for a list of supported timezones) for accurate metrics.
2323

24+
> 🔣 On web instances, *recent languages activity* is an extra feature and must be enabled globally in `settings.json`
25+
2426
#### ℹ️ Examples workflows
2527

2628
[➡️ Available options for this plugin](metadata.yml)

source/plugins/habits/index.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { recent as recent_analyzer } from "./../languages/analyzers.mjs"
33

44
//Setup
5-
export default async function({login, data, rest, imports, q, account}, {enabled = false, ...defaults} = {}) {
5+
export default async function({login, data, rest, imports, q, account}, {enabled = false, extras = false, ...defaults} = {}) {
66
//Plugin execution
77
try {
88
//Check if plugin is enabled and requirements are met
@@ -97,7 +97,7 @@ export default async function({login, data, rest, imports, q, account}, {enabled
9797
}
9898

9999
//Linguist
100-
if (charts) {
100+
if ((extras)&&(charts)) {
101101
//Check if linguist exists
102102
console.debug(`metrics/compute/${login}/plugins > habits > searching recently used languages using linguist`)
103103
if (patches.length) {
@@ -109,7 +109,6 @@ export default async function({login, data, rest, imports, q, account}, {enabled
109109
}
110110
else
111111
console.debug(`metrics/compute/${login}/plugins > habits > linguist not available`)
112-
113112
}
114113

115114
//Results

source/plugins/languages/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ If you work a lot with other people, these numbers may be less representative of
3030

3131
The `plugin_languages_indepth` option lets you get more accurate metrics by cloning each repository you contributed to, running [github/linguist](https://github.com/github/linguist) on it and then iterating over patches matching your username from `git log`. This method is slower than the first one.
3232

33-
> ⚠️ Although *metrics* does not send any code to external sources, you must understand that when using this option repositories are cloned locally temporarly on the GitHub Action runner. If you work with sensitive data or company code, it is advised to keep this option disabled. *Metrics* cannot be held responsible for any eventual code leaks, use at your own risk.
33+
> ⚠️ Although *metrics* does not send any code to external sources, you must understand that when using this option repositories are cloned locally temporarly on the GitHub Action runner. If you work with sensitive data or company code, it is advised to keep this option disabled. *Metrics* and its authors cannot be held responsible for any eventual code leaks, use at your own risk.
3434
> Source code is available for auditing at [analyzers.mjs](/source/plugins/languages/analyzers.mjs)
3535
36+
> 🔣 On web instances, `indepth` is an extra feature and must be enabled globally in `settings.json`
37+
3638
#### `commits_authoring` option
3739

3840
Since Git lets you use any email and name for commits, metrics may not be able to detect whether you own a commit or not. By default, it'll check whether it matches your GitHub login.

source/plugins/languages/index.mjs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { indepth as indepth_analyzer, recent as recent_analyzer } from "./analyzers.mjs"
33

44
//Setup
5-
export default async function({login, data, imports, q, rest, account}, {enabled = false} = {}) {
5+
export default async function({login, data, imports, q, rest, account}, {enabled = false, extras = false} = {}) {
66
//Plugin execution
77
try {
88
//Check if plugin is enabled and requirements are met
@@ -52,17 +52,20 @@ export default async function({login, data, imports, q, rest, account}, {enabled
5252
}
5353
}
5454

55-
//Recently used languages
56-
if ((sections.includes("recently-used"))&&(context.mode === "user")) {
57-
console.debug(`metrics/compute/${login}/plugins > languages > using recent analyzer`)
58-
languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped, days:_recent_days, load:_recent_load})
59-
}
55+
//Extras features
56+
if (extras) {
57+
//Recently used languages
58+
if ((sections.includes("recently-used"))&&(context.mode === "user")) {
59+
console.debug(`metrics/compute/${login}/plugins > languages > using recent analyzer`)
60+
languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped, days:_recent_days, load:_recent_load})
61+
}
6062

61-
//Indepth mode
62-
if (indepth) {
63-
console.debug(`metrics/compute/${login}/plugins > languages > switching to indepth mode (this may take some time)`)
64-
Object.assign(languages, await indepth_analyzer({login, data, imports, repositories}, {skipped}))
65-
console.debug(`metrics/compute/${login}/plugins > languages > indepth analysis missed ${languages.missed} commits`)
63+
//Indepth mode
64+
if (indepth) {
65+
console.debug(`metrics/compute/${login}/plugins > languages > switching to indepth mode (this may take some time)`)
66+
Object.assign(languages, await indepth_analyzer({login, data, imports, repositories}, {skipped}))
67+
console.debug(`metrics/compute/${login}/plugins > languages > indepth analysis missed ${languages.missed} commits`)
68+
}
6669
}
6770

6871
//Compute languages stats

source/plugins/licenses/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
### 📜 Repository licenses
22

33
> ⚠️ This is **NOT** legal advice, use at your own risk
4-
>
5-
> 💣 Do **NOT** enable this plugin on public web instances (plugin allows raw commands injection)
4+
5+
> 🔣 On web instances, this plugin is an extra feature and must be enabled globally in `settings.json`
6+
> 💣 Note that this plugin allows raw commands injection and is **NOT** advised to be enabled on them
7+
> This could result in compromised server!
68
79
The *licenses* plugin lets you display license informations like permissions, limitations and conditions along with additional metrics about dependencies.
810

source/plugins/licenses/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//Setup
2-
export default async function({login, q, imports, data, graphql, queries, account}, {enabled = false} = {}) {
2+
export default async function({login, q, imports, data, graphql, queries, account}, {enabled = false, extras = false} = {}) {
33
//Plugin execution
44
try {
55
//Check if plugin is enabled and requirements are met
6-
if ((!enabled) || (!q.licenses))
6+
if ((!enabled) || (!extras) || (!q.licenses))
77
return null
88

99
//Load inputs

0 commit comments

Comments
 (0)