提交 bfa915d6 编写于 作者: R Rachel Macfarlane

Support 'workbench.action.openIssueReport' command in the web - directly open GitHub

上级 c2565c31
......@@ -35,7 +35,7 @@ import BaseHtml from 'vs/code/electron-browser/issue/issueReporterPage';
import { LoggerChannelClient, FollowerLogService } from 'vs/platform/log/common/logIpc';
import { ILogService, getLogLevel } from 'vs/platform/log/common/log';
import { CodiconLabel } from 'vs/base/browser/ui/codiconLabel/codiconLabel';
import { normalizeGitHubUrl } from 'vs/code/electron-browser/issue/issueReporterUtil';
import { normalizeGitHubUrl } from 'vs/code/common/issue/issueReporterUtil';
import { Button } from 'vs/base/browser/ui/button/button';
import { SystemInfo, isRemoteDiagnosticError } from 'vs/platform/diagnostics/common/diagnostics';
import { SpdLogService } from 'vs/platform/log/node/spdlogService';
......
......@@ -5,7 +5,7 @@
import * as assert from 'assert';
import { IssueReporterModel } from 'vs/code/electron-browser/issue/issueReporterModel';
import { normalizeGitHubUrl } from 'vs/code/electron-browser/issue/issueReporterUtil';
import { normalizeGitHubUrl } from 'vs/code/common/issue/issueReporterUtil';
import { IssueType } from 'vs/platform/issue/node/issue';
suite('IssueReporter', () => {
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { ICommandAction, MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { IProductService } from 'vs/platform/product/common/productService';
import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { IWebIssueService, WebIssueService } from 'vs/workbench/contrib/issue/browser/issueService';
class RegisterIssueContribution implements IWorkbenchContribution {
constructor(@IProductService readonly productService: IProductService) {
if (productService.reportIssueUrl) {
const helpCategory = { value: nls.localize('help', "Help"), original: 'Help' };
const OpenIssueReporterActionId = 'workbench.action.openIssueReporter';
const OpenIssueReporterActionLabel = nls.localize({ key: 'reportIssueInEnglish', comment: ['Translate this to "Report Issue in English" in all languages please!'] }, "Report Issue");
CommandsRegistry.registerCommand(OpenIssueReporterActionId, function (accessor, args?: [string]) {
let extensionId: string | undefined;
if (args && Array.isArray(args)) {
[extensionId] = args;
}
return accessor.get(IWebIssueService).openReporter({ extensionId });
});
const command: ICommandAction = {
id: OpenIssueReporterActionId,
title: { value: OpenIssueReporterActionLabel, original: 'Report Issue' },
category: helpCategory
};
MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command });
}
}
}
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(RegisterIssueContribution, LifecyclePhase.Starting);
registerSingleton(IWebIssueService, WebIssueService, true);
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { URI } from 'vs/base/common/uri';
import { normalizeGitHubUrl } from 'vs/code/common/issue/issueReporterUtil';
import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { ExtensionType } from 'vs/platform/extensions/common/extensions';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IProductService } from 'vs/platform/product/common/productService';
export const IWebIssueService = createDecorator<IWebIssueService>('webIssueService');
export interface IIssueReporterOptions {
extensionId?: string;
}
export interface IWebIssueService {
_serviceBrand: undefined;
openReporter(options?: IIssueReporterOptions): Promise<void>;
}
export class WebIssueService implements IWebIssueService {
_serviceBrand: undefined;
constructor(
@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
@IOpenerService private readonly openerService: IOpenerService,
@IProductService private readonly productService: IProductService
) { }
async openReporter(options: IIssueReporterOptions): Promise<void> {
let repositoryUrl = this.productService.reportIssueUrl;
if (options.extensionId) {
const extensionGitHubUrl = await this.getExtensionGitHubUrl(options.extensionId);
if (extensionGitHubUrl) {
repositoryUrl = extensionGitHubUrl + '/issues/new';
}
}
if (repositoryUrl) {
return this.openerService.open(URI.parse(repositoryUrl)).then(_ => { });
} else {
throw new Error(`Unable to find issue reporting url for ${options.extensionId}`);
}
}
private async getExtensionGitHubUrl(extensionId: string): Promise<string> {
let repositoryUrl = '';
const extensions = await this.extensionManagementService.getInstalled(ExtensionType.User);
const selectedExtension = extensions.filter(ext => ext.identifier.id === extensionId)[0];
const bugsUrl = selectedExtension?.manifest.bugs?.url;
const extensionUrl = selectedExtension?.manifest.repository?.url;
// If given, try to match the extension's bug url
if (bugsUrl && bugsUrl.match(/^https?:\/\/github\.com\/(.*)/)) {
repositoryUrl = normalizeGitHubUrl(bugsUrl);
} else if (extensionUrl && extensionUrl.match(/^https?:\/\/github\.com\/(.*)/)) {
repositoryUrl = normalizeGitHubUrl(extensionUrl);
}
return repositoryUrl;
}
}
......@@ -108,4 +108,7 @@ import 'vs/workbench/contrib/tasks/browser/taskService';
// Telemetry Opt Out
import 'vs/workbench/contrib/welcome/telemetryOptOut/browser/telemetryOptOut.contribution';
// Issues
import 'vs/workbench/contrib/issue/browser/issue.contribution';
//#endregion
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册