feat(plugins/code): improvements (#891) [skip ci]
This commit is contained in:
@@ -15,7 +15,9 @@ export default async function({login, q, imports, data, rest, account}, {enabled
|
||||
}
|
||||
|
||||
//Load inputs
|
||||
let {load, lines, visibility, languages, skipped} = imports.metadata.plugins.code.inputs({data, q, account})
|
||||
let {load, days, lines, visibility, languages, skipped} = imports.metadata.plugins.code.inputs({data, q, account})
|
||||
if (!days)
|
||||
days = Infinity
|
||||
skipped.push(...data.shared["repositories.skipped"])
|
||||
const pages = Math.ceil(load / 100)
|
||||
|
||||
@@ -35,7 +37,8 @@ export default async function({login, q, imports, data, rest, account}, {enabled
|
||||
.filter(({actor}) => account === "organization" ? true : actor.login?.toLocaleLowerCase() === login.toLocaleLowerCase())
|
||||
.filter(({repo:{name:repo}}) => !((skipped.includes(repo.split("/").pop())) || (skipped.includes(repo))))
|
||||
.filter(event => visibility === "public" ? event.public : true)
|
||||
.flatMap(({payload}) => Promise.all(payload.commits.map(async commit => (await rest.request(commit.url)).data))),
|
||||
.filter(({created_at}) => Number.isFinite(days) ? new Date(created_at) > new Date(Date.now() - days * 24 * 60 * 60 * 1000) : true)
|
||||
.flatMap(({created_at:created, payload}) => Promise.all(payload.commits.map(async commit => ({created:new Date(created), ...(await rest.request(commit.url)).data})))),
|
||||
]),
|
||||
]
|
||||
.flat()
|
||||
@@ -51,7 +54,7 @@ export default async function({login, q, imports, data, rest, account}, {enabled
|
||||
|
||||
//Search for a random snippet
|
||||
let files = events
|
||||
.flatMap(({sha, commit:{message, url}, files}) => files.map(({filename, status, additions, deletions, patch}) => ({sha, message, filename, status, additions, deletions, patch, repo:url.match(/repos[/](?<repo>[\s\S]+)[/]git[/]commits/)?.groups?.repo})))
|
||||
.flatMap(({created, sha, commit:{message, url}, files}) => files.map(({filename, status, additions, deletions, patch}) => ({created, sha, message, filename, status, additions, deletions, patch, repo:url.match(/repos[/](?<repo>[\s\S]+)[/]git[/]commits/)?.groups?.repo})))
|
||||
.filter(({patch}) => (patch ? (patch.match(/\n/mg)?.length ?? 1) : Infinity) < lines)
|
||||
for (const file of files)
|
||||
file.language = await imports.language({...file, prefix:login}).catch(() => "unknown")
|
||||
@@ -60,12 +63,15 @@ export default async function({login, q, imports, data, rest, account}, {enabled
|
||||
if (snippet) {
|
||||
//Trim common indent from content and change line feed
|
||||
if (!snippet.patch.split("\n").shift().endsWith("@@"))
|
||||
snippet.patch = snippet.patch.replace(/^(?<coord>@@.*?@@)/, "$<coord>\n")
|
||||
const indent = Math.min(...(snippet.patch.match(/^[+-]? +/mg)?.map(indent => (indent.length ?? Infinity) - indent.startsWith("+") - indent.startsWith("-")) ?? [])) || 0
|
||||
const content = imports.htmlescape(snippet.patch.replace(/\r\n/mg, "\n").replace(new RegExp(`^([+-]?)${" ".repeat(indent)}`, "mg"), "$1"))
|
||||
snippet.patch = snippet.patch.replace(/^(?<coord>@@.*?@@).*/, "$<coord>")
|
||||
const indent = Math.min(...(snippet.patch.match(/^.\s+/mg) ?? [0]).map(line => line.length-1)) || 0
|
||||
const content = imports.htmlescape(snippet.patch.replace(new RegExp(`^(.)\\s{0,${indent}}`, "mg"), "$1"))
|
||||
|
||||
//Format patch
|
||||
snippet.patch = imports.htmlunescape((await imports.highlight(content, "diff")).trim()).replace(/\n/g, "<br/>")
|
||||
snippet.patch = imports.htmlunescape(await imports.highlight(content, "diff"))
|
||||
.trim()
|
||||
.replace(/\r?\n/g, "<br/>")
|
||||
.replace(/<span class="token prefix unchanged"> <\/span>/g, '<span class="token prefix unchanged">·</span>')
|
||||
}
|
||||
|
||||
//Results
|
||||
|
||||
@@ -33,6 +33,14 @@ inputs:
|
||||
min: 100
|
||||
max: 1000
|
||||
|
||||
plugin_activity_days:
|
||||
description: Events maximum age
|
||||
type: number
|
||||
default: 3
|
||||
min: 0
|
||||
max: 365
|
||||
zero: disable
|
||||
|
||||
plugin_code_visibility:
|
||||
description: |
|
||||
Events visibility
|
||||
@@ -53,7 +61,6 @@ inputs:
|
||||
inherits: repositories_skipped
|
||||
|
||||
plugin_code_languages:
|
||||
extras: yes
|
||||
description: Restrict display to specific languages
|
||||
type: array
|
||||
format: comma-separated
|
||||
|
||||
@@ -21,6 +21,16 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2 2.5A2.5 2.5 0 014.5 0h8.75a.75.75 0 01.75.75v12.5a.75.75 0 01-.75.75h-2.5a.75.75 0 110-1.5h1.75v-2h-8a1 1 0 00-.714 1.7.75.75 0 01-1.072 1.05A2.495 2.495 0 012 11.5v-9zm10.5-1V9h-8c-.356 0-.694.074-1 .208V2.5a1 1 0 011-1h8zM5 12.25v3.25a.25.25 0 00.4.2l1.45-1.087a.25.25 0 01.3 0L8.6 15.7a.25.25 0 00.4-.2v-3.25a.25.25 0 00-.25-.25h-3.5a.25.25 0 00-.25.25z"></path></svg>
|
||||
From <span class="blue space"><%= plugins.code.snippet.repo %></span>
|
||||
</div>
|
||||
</section>
|
||||
<section class="largeable-column-fields">
|
||||
<div class="field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0zM8 0a8 8 0 100 16A8 8 0 008 0zm.5 4.75a.75.75 0 00-1.5 0v3.5a.75.75 0 00.471.696l2.5 1a.75.75 0 00.557-1.392L8.5 7.742V4.75z"></path></svg>
|
||||
On <%= f.date(plugins.code.snippet.created, {time:true, date:true, timeZone:config.timezone?.name}) %>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div class="row">
|
||||
<section class="largeable-column-fields">
|
||||
<div class="field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M10.5 7.75a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0zm1.43.75a4.002 4.002 0 01-7.86 0H.75a.75.75 0 110-1.5h3.32a4.001 4.001 0 017.86 0h3.32a.75.75 0 110 1.5h-3.32z"></path></svg>
|
||||
<%= plugins.code.snippet.message %>
|
||||
|
||||
@@ -1254,12 +1254,18 @@
|
||||
.snippet .body {
|
||||
padding-left: 12px;
|
||||
}
|
||||
.snippet .language-diff {
|
||||
font-size: 77%;
|
||||
}
|
||||
.snippet.additions {
|
||||
color: #336543;
|
||||
}
|
||||
.snippet.deletions {
|
||||
color: #9A5256;
|
||||
}
|
||||
.snippet .token.prefix.unchanged {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
/* Markdown and syntax highlighting */
|
||||
.markdown b, .markdown i {
|
||||
|
||||
Reference in New Issue
Block a user