feat: git hash on error (#9373)

This commit is contained in:
Tony
2022-03-23 17:10:47 +00:00
committed by GitHub
parent 6ba0cb246e
commit baeafb97a5
2 changed files with 9 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ const path = require('path');
const { RequestInProgressError } = require('@/errors'); const { RequestInProgressError } = require('@/errors');
let Sentry; let Sentry;
let gitHash;
if (config.sentry.dsn) { if (config.sentry.dsn) {
Sentry = Sentry || require('@sentry/node'); Sentry = Sentry || require('@sentry/node');
@@ -19,6 +20,12 @@ if (config.sentry.dsn) {
logger.info('Sentry inited.'); logger.info('Sentry inited.');
} }
try {
gitHash = require('git-rev-sync').short();
} catch (e) {
gitHash = (process.env.HEROKU_SLUG_COMMIT && process.env.HEROKU_SLUG_COMMIT.slice(0, 7)) || (process.env.VERCEL_GITHUB_COMMIT_SHA && process.env.VERCEL_GITHUB_COMMIT_SHA.slice(0, 7)) || 'unknown';
}
module.exports = async (ctx, next) => { module.exports = async (ctx, next) => {
try { try {
const time = +new Date(); const time = +new Date();
@@ -68,6 +75,7 @@ module.exports = async (ctx, next) => {
message, message,
errorPath: ctx.path, errorPath: ctx.path,
nodeVersion: process.version, nodeVersion: process.version,
gitHash,
}); });
} }

View File

@@ -43,6 +43,7 @@
Helpful Information to provide when opening issue: Helpful Information to provide when opening issue:
Path: {{@ errorPath }} Path: {{@ errorPath }}
Node version: {{@ nodeVersion}} Node version: {{@ nodeVersion}}
Git Hash: {{@ gitHash}}
</pre> </pre>
<pre class="message"> <pre class="message">
如果您认为 RSSHub 导致了该错误请在Github按照模版复制本页面信息进行<a href="https://github.com/DIYgod/RSSHub/issues/new?assignees=&labels=RSS+bug&template=bug_report_zh.yml" target="_blank">汇报</a> 如果您认为 RSSHub 导致了该错误请在Github按照模版复制本页面信息进行<a href="https://github.com/DIYgod/RSSHub/issues/new?assignees=&labels=RSS+bug&template=bug_report_zh.yml" target="_blank">汇报</a>