From fdb1e2150878bc7268137751bec0b3e96b665667 Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 8 Mar 2023 03:28:49 -1100 Subject: [PATCH] fix(route): github comments on ghost (#12065) --- lib/v2/github/comments.js | 29 ++++++++++++++--------------- lib/v2/github/maintainer.js | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/v2/github/comments.js b/lib/v2/github/comments.js index 0e6e634cd..41e9a2485 100644 --- a/lib/v2/github/comments.js +++ b/lib/v2/github/comments.js @@ -43,7 +43,7 @@ module.exports = async (ctx) => { }); const timeline = timelineResponse.data; - let items = [ + const items = [ { title: `${issue.user.login} created ${user}/${repo}: ${typeDict[type].title} #${issue.number}`, description: issue.body ? md.render(issue.body) : null, @@ -54,39 +54,40 @@ module.exports = async (ctx) => { ]; timeline.forEach((item) => { + const actor = item.actor?.login ?? item.user?.login ?? 'ghost'; switch (item.event) { case 'closed': items.push({ - title: `${item.actor.login} ${item.event} ${user}/${repo}: ${typeDict[type].title} #${issue.number}`, - author: item.actor.login, + title: `${actor} ${item.event} ${user}/${repo}: ${typeDict[type].title} #${issue.number}`, + author: actor, pubDate: parseDate(item.created_at), link: item.url, }); break; case 'commented': items.push({ - title: `${item.actor.login} ${item.event} on ${user}/${repo}: ${typeDict[type].title} #${issue.number}`, + title: `${actor} ${item.event} on ${user}/${repo}: ${typeDict[type].title} #${issue.number}`, description: md.render(item.body), - author: item.actor.login, + author: actor, pubDate: parseDate(item.created_at), link: item.html_url, }); break; case 'cross-referenced': items.push({ - title: `${item.actor.login} ${item.event} on ${user}/${repo}: ${typeDict[type].title} #${issue.number}`, - description: `${item.actor.login} mentioned this issue in ${item.source.issue.title} #${item.source.issue.number}`, - author: item.actor.login, + title: `${actor} ${item.event} on ${user}/${repo}: ${typeDict[type].title} #${issue.number}`, + description: `${actor} mentioned this issue in ${item.source.issue.title} #${item.source.issue.number}`, + author: actor, pubDate: parseDate(item.created_at), - guid: `${item.actor.login} ${item.event} on ${user}/${repo}: ${typeDict[type].title} #${issue.number} on ${item.created_at}`, - link: `${item.actor.login} ${item.event} on ${user}/${repo}: ${typeDict[type].title} #${issue.number} on ${item.created_at}`, + guid: `${actor} ${item.event} on ${user}/${repo}: ${typeDict[type].title} #${issue.number} on ${item.created_at}`, + link: `${actor} ${item.event} on ${user}/${repo}: ${typeDict[type].title} #${issue.number} on ${item.created_at}`, }); break; case 'renamed': items.push({ - title: `${item.actor.login} ${item.event} on ${user}/${repo}: ${typeDict[type].title} #${issue.number}`, - description: `${item.actor.login} changed the title ${item.rename.from} ${item.rename.to}`, - author: item.actor.login, + title: `${actor} ${item.event} on ${user}/${repo}: ${typeDict[type].title} #${issue.number}`, + description: `${actor} changed the title ${item.rename.from} ${item.rename.to}`, + author: actor, pubDate: parseDate(item.created_at), link: item.url, }); @@ -105,8 +106,6 @@ module.exports = async (ctx) => { } }); - items = await Promise.all(items.map((item) => ctx.cache.tryGet(item.link, () => item))); - ctx.state.data = { title: `${user}/${repo}: ${typeDict[type].title} #${number} - ${issue.title}`, link: issue.html_url, diff --git a/lib/v2/github/maintainer.js b/lib/v2/github/maintainer.js index 0a0806672..0996afa32 100644 --- a/lib/v2/github/maintainer.js +++ b/lib/v2/github/maintainer.js @@ -1,6 +1,6 @@ module.exports = { '/branches/:user/:repo': ['max-arnold'], - '/comments/:user/:repo/:type/:number': ['TonyRL'], + '/comments/:user/:repo/:number': ['TonyRL'], '/contributors/:user/:repo/:order?/:anon?': ['zoenglinghou'], '/file/:user/:repo/:branch/:filepath+': ['zengxs'], '/issue/:user/:repo/:state?/:labels?': ['HenryQW', 'AndreyMZ'],