Skip to content

Commit

Permalink
Supports Jira issues in Start Work flow
Browse files Browse the repository at this point in the history
  • Loading branch information
chivorotkiv authored and sergeibbb committed Nov 12, 2024
1 parent 73a6946 commit 7596cfd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/plus/integrations/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ export class IntegrationService implements Disposable {
args: { 0: integrationIds => (integrationIds?.length ? integrationIds.join(',') : '<undefined>'), 1: false },
})
async getMyIssues(
integrationIds?: HostingIntegrationId[],
integrationIds?: (SupportedHostingIntegrationIds | SupportedIssueIntegrationIds)[],
cancellation?: CancellationToken,
): Promise<SearchedIssue[] | undefined> {
const integrations: Map<Integration, ResourceDescriptor[] | undefined> = new Map();
Expand Down
38 changes: 28 additions & 10 deletions src/plus/startWork/startWork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import { OpenOnGitHubQuickInputButton } from '../../commands/quickCommand.button
import { getSteps } from '../../commands/quickWizard.utils';
import { proBadge } from '../../constants';
import type { IntegrationId } from '../../constants.integrations';
import { HostingIntegrationId } from '../../constants.integrations';
import { HostingIntegrationId, IssueIntegrationId } from '../../constants.integrations';
import type { Source, Sources, StartWorkTelemetryContext } from '../../constants.telemetry';
import type { Container } from '../../container';
import type { SearchedIssue } from '../../git/models/issue';
import type { Issue, IssueShape, SearchedIssue } from '../../git/models/issue';
import { getOrOpenIssueRepository } from '../../git/models/issue';
import type { Repository } from '../../git/models/repository';
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
import { createQuickPickItemOfT } from '../../quickpicks/items/common';
import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive';
Expand All @@ -46,7 +47,7 @@ interface Context {
result: StartWorkResult;
title: string;
telemetryContext: StartWorkTelemetryContext | undefined;
connectedIntegrations: Map<IntegrationId, boolean>;
connectedIntegrations: Map<SupportedStartWorkIntegrationIds, boolean>;
}

interface State {
Expand All @@ -62,7 +63,8 @@ export interface StartWorkCommandArgs {
source?: Sources;
}

export const supportedStartWorkIntegrations = [HostingIntegrationId.GitHub];
export const supportedStartWorkIntegrations = [HostingIntegrationId.GitHub, IssueIntegrationId.Jira];
export type SupportedStartWorkIntegrationIds = (typeof supportedStartWorkIntegrations)[number];
const instanceCounter = getScopedCounter();

export class StartWorkCommand extends QuickCommand<State> {
Expand Down Expand Up @@ -142,7 +144,7 @@ export class StartWorkCommand extends QuickCommand<State> {
}

const issue = state.item?.item?.issue;
const repo = issue && (await getOrOpenIssueRepository(this.container, issue));
const repo = issue && (await this.getIssueRepositoryIfExists(issue));

if (typeof state.action === 'string') {
switch (state.action) {
Expand All @@ -154,7 +156,9 @@ export class StartWorkCommand extends QuickCommand<State> {
state: {
subcommand: 'create',
repo: repo,
name: issue ? slug(`${issue.id}-${issue.title}`) : undefined,
name: issue
? `${slug(issue.id, { lower: false })}-${slug(issue.title)}`
: undefined,
suggestNameOnly: true,
suggestRepoOnly: true,
flags: state.inWorktree ? ['--worktree'] : ['--switch'],
Expand Down Expand Up @@ -196,6 +200,14 @@ export class StartWorkCommand extends QuickCommand<State> {
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResultBreak;
}

private async getIssueRepositoryIfExists(issue: IssueShape | Issue): Promise<Repository | undefined> {
try {
return await getOrOpenIssueRepository(this.container, issue);
} catch {
return undefined;
}
}

private async *confirmLocalIntegrationConnectStep(
state: StepState<State>,
context: Context,
Expand Down Expand Up @@ -411,12 +423,14 @@ export class StartWorkCommand extends QuickCommand<State> {
void openUrl(item.item.issue.url);
}

private async getConnectedIntegrations(): Promise<Map<IntegrationId, boolean>> {
const connected = new Map<IntegrationId, boolean>();
private async getConnectedIntegrations(): Promise<Map<SupportedStartWorkIntegrationIds, boolean>> {
const connected = new Map<SupportedStartWorkIntegrationIds, boolean>();
await Promise.allSettled(
supportedStartWorkIntegrations.map(async integrationId => {
const integration = await this.container.integrations.get(integrationId);
connected.set(integrationId, integration.maybeConnected ?? (await integration.isConnected()));
const isConnected = integration.maybeConnected ?? (await integration.isConnected());
const hasAccess = isConnected && (await integration.access());
connected.set(integrationId, hasAccess);
}),
);

Expand All @@ -425,9 +439,13 @@ export class StartWorkCommand extends QuickCommand<State> {
}

async function updateContextItems(container: Container, context: Context) {
const connectedIntegrationsMap = context.connectedIntegrations;
const connectedIntegrations = [...connectedIntegrationsMap.keys()].filter(integrationId =>
Boolean(connectedIntegrationsMap.get(integrationId)),
);
context.result = {
items:
(await container.integrations.getMyIssues([HostingIntegrationId.GitHub]))?.map(i => ({
(await container.integrations.getMyIssues(connectedIntegrations))?.map(i => ({
item: i,
})) ?? [],
};
Expand Down

0 comments on commit 7596cfd

Please sign in to comment.