2023-12-25 10:06:22 +01:00
|
|
|
import { withQuery } from 'ufo';
|
|
|
|
|
|
|
|
export async function getGhIssueUrl(options: {
|
|
|
|
lang: string;
|
|
|
|
repoUrl: string;
|
2023-12-26 07:46:36 +01:00
|
|
|
additionalInfo?: Record<string, string>;
|
2023-12-25 10:06:22 +01:00
|
|
|
}) {
|
|
|
|
// Issue Templateのプレフィル
|
2023-12-26 07:46:36 +01:00
|
|
|
let environmentArr: string[] = [
|
|
|
|
'* Model and OS of the device(s):',
|
|
|
|
'* Browser:',
|
|
|
|
];
|
2023-12-25 10:06:22 +01:00
|
|
|
let template = '02_visitor-bug-report-en.yml';
|
|
|
|
|
|
|
|
if (options.lang === 'ja') {
|
|
|
|
template = '01_visitor-bug-report-ja.yml';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.client) {
|
|
|
|
//@ts-ignore
|
|
|
|
if ('userAgentData' in navigator && 'getHighEntropyValues' in navigator.userAgentData) {
|
|
|
|
//@ts-ignore
|
|
|
|
const uaData = await navigator.userAgentData.getHighEntropyValues([
|
|
|
|
"fullVersionList",
|
|
|
|
"platformVersion",
|
|
|
|
]);
|
2023-12-25 10:37:43 +01:00
|
|
|
|
2023-12-25 10:06:22 +01:00
|
|
|
let osVersion = 'v' + uaData.platformVersion;
|
|
|
|
if (uaData.platform === 'Windows') {
|
|
|
|
// https://learn.microsoft.com/ja-jp/microsoft-edge/web-platform/how-to-detect-win11
|
|
|
|
const majorPlatformVersion = parseInt(uaData.platformVersion.split('.')[0]);
|
|
|
|
if (majorPlatformVersion >= 13) {
|
|
|
|
osVersion = '11 or later';
|
|
|
|
}
|
|
|
|
else if (majorPlatformVersion > 0) {
|
|
|
|
osVersion = '10';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
osVersion = '8.1 or before';
|
|
|
|
}
|
|
|
|
}
|
2023-12-25 10:37:43 +01:00
|
|
|
|
2023-12-25 10:06:22 +01:00
|
|
|
const browserData = uaData.fullVersionList.find((item: any) => item.brand.toLowerCase() !== 'not_a brand');
|
2023-12-26 07:46:36 +01:00
|
|
|
|
|
|
|
environmentArr = [
|
2023-12-25 10:06:22 +01:00
|
|
|
`* Model and OS of the device(s): ${uaData.platform} ${osVersion}`,
|
|
|
|
`* Browser: ${browserData.brand} ${browserData.version}`,
|
|
|
|
`* Viewport Size: ${window.innerWidth}x${window.innerHeight}`,
|
|
|
|
`* (UA Detected Using getHighEntropyValues)`,
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
const UAParser = (await import('ua-parser-js')).default;
|
|
|
|
const ua = new UAParser();
|
|
|
|
const uaRes = ua.getResult();
|
2023-12-26 07:46:36 +01:00
|
|
|
|
|
|
|
environmentArr = [
|
2023-12-25 10:06:22 +01:00
|
|
|
`* Model and OS of the device(s): ${uaRes.os.name} v${uaRes.os.version}`,
|
|
|
|
`* Browser: ${uaRes.browser.name} (${uaRes.engine.name}) v${uaRes.browser.version}`,
|
|
|
|
`* Viewport Size: ${window.innerWidth}x${window.innerHeight}`,
|
|
|
|
`* Raw User Agent: ${uaRes.ua}`,
|
|
|
|
];
|
2023-12-26 07:46:36 +01:00
|
|
|
}
|
|
|
|
if (options.additionalInfo) {
|
|
|
|
environmentArr.push(...Object.entries(options.additionalInfo).map((v) => `* ${v[0]}: ${v[1]}`));
|
|
|
|
}
|
|
|
|
environmentArr.push((options.lang === 'ja') ? '* 【自動入力済】追記は不要です' : '* [Auto-filled] No need to write additional information.');
|
|
|
|
} else {
|
|
|
|
if (options.additionalInfo) {
|
|
|
|
environmentArr.push(...Object.entries(options.additionalInfo).map((v) => `* ${v[0]}: ${v[1]}`));
|
2023-12-25 10:06:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return withQuery(`${options.repoUrl}/issues/new`, {
|
|
|
|
template,
|
2023-12-26 07:46:36 +01:00
|
|
|
environment: environmentArr.join('\n'),
|
2023-12-25 10:06:22 +01:00
|
|
|
labels: 'maybe non-developer,bug?',
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|