Fix unknown committers causing crash
This commit is contained in:
parent
50e7dcaac3
commit
cd97774fb2
3 changed files with 13 additions and 2 deletions
5
lib/hash.js
Normal file
5
lib/hash.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { createHash } from 'node:crypto'
|
||||||
|
|
||||||
|
export default function hash(string) {
|
||||||
|
return createHash('md5').update(string).digest().toString('hex')
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import { Eta } from 'eta'
|
||||||
import render, { renderHtml } from './lib/render.js'
|
import render, { renderHtml } from './lib/render.js'
|
||||||
import languageColors from './lib/languagecolors.js'
|
import languageColors from './lib/languagecolors.js'
|
||||||
import fetch from 'node-fetch'
|
import fetch from 'node-fetch'
|
||||||
|
import hash from './lib/hash.js'
|
||||||
// satori is using the native fetch api, causing a warning, so make node-fetch the default
|
// satori is using the native fetch api, causing a warning, so make node-fetch the default
|
||||||
globalThis.fetch = fetch
|
globalThis.fetch = fetch
|
||||||
|
|
||||||
|
@ -109,7 +110,12 @@ app.get('/:owner/:repo/commit/:hash', async function (req, res) {
|
||||||
repository: {
|
repository: {
|
||||||
full_name: `${req.params.owner}/${req.params.repo}`
|
full_name: `${req.params.owner}/${req.params.repo}`
|
||||||
},
|
},
|
||||||
committer: commit.committer,
|
committer: commit.committer ?? {
|
||||||
|
...commit.commit.author,
|
||||||
|
avatar_url: `${forgejoBaseUrl}/avatar/${hash(
|
||||||
|
commit.commit.author.email.toLowerCase()
|
||||||
|
)}`
|
||||||
|
},
|
||||||
stats: commit.stats,
|
stats: commit.stats,
|
||||||
created_at: commit.created
|
created_at: commit.created
|
||||||
},
|
},
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<%~ include('partials/commit-stats.eta', {stats: it.commit.stats}) %>
|
<%~ include('partials/commit-stats.eta', {stats: it.commit.stats}) %>
|
||||||
<div class="info-line">
|
<div class="info-line">
|
||||||
<img class="avatar" width="48" height="48" src="<%= it.commit.committer.avatar_url %>?size=48"></img>
|
<img class="avatar" width="48" height="48" src="<%= it.commit.committer.avatar_url %>?size=48"></img>
|
||||||
<p class="author"><%= it.commit.committer.full_name || it.commit.committer.login %></p>
|
<p class="author"><%= it.commit.committer.full_name || it.commit.committer.name || it.commit.committer.login %></p>
|
||||||
<p>committed <%= new Intl.DateTimeFormat('en-US', { dateStyle: 'long' }).format(new Date(it.commit.created_at)) %></p>
|
<p>committed <%= new Intl.DateTimeFormat('en-US', { dateStyle: 'long' }).format(new Date(it.commit.created_at)) %></p>
|
||||||
<%~ include('icons/code-commit.eta') %>
|
<%~ include('icons/code-commit.eta') %>
|
||||||
<p><%= it.commit.sha.slice(0, 7) %></p>
|
<p><%= it.commit.sha.slice(0, 7) %></p>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue