Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shows GitLab issues in Start Work #3787

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/plus/integrations/providers/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
import { HostingIntegration } from '../integration';
import { fromGitLabMergeRequestProvidersApi } from './gitlab/models';
import type { ProviderPullRequest } from './models';
import { ProviderPullRequestReviewState, providersMetadata } from './models';
import { ProviderPullRequestReviewState, providersMetadata, toSearchedIssue } from './models';
import type { ProvidersApi } from './providersApi';

const metadata = providersMetadata[HostingIntegrationId.GitLab];
Expand Down Expand Up @@ -243,11 +243,33 @@ abstract class GitLabIntegrationBase<
return results;
}

protected override searchProviderMyIssues(
_session: AuthenticationSession,
_repos?: GitLabRepositoryDescriptor[],
protected override async searchProviderMyIssues(
{ accessToken }: AuthenticationSession,
repos?: GitLabRepositoryDescriptor[],
): Promise<SearchedIssue[] | undefined> {
return Promise.resolve(undefined);
const api = await this.container.gitlab;
const providerApi = await this.getProvidersApi();

if (!api || !repos) {
return undefined;
}

const repoIdsResult = await Promise.allSettled(
repos.map(
(r: GitLabRepositoryDescriptor): Promise<string | undefined> =>
api.getProjectId(this, accessToken, r.owner, r.name, this.apiBaseUrl, undefined),
) ?? [],
);
const repoInput = repoIdsResult
.map(result => (result.status === 'fulfilled' ? result.value : undefined))
.filter((r): r is string => r != null);
const apiResult = await providerApi.getIssuesForRepos(this.id, repoInput, {
accessToken: accessToken,
});

return apiResult.values
.map(issue => toSearchedIssue(issue, this))
.filter((result): result is SearchedIssue => result != null);
}

protected override async mergeProviderPullRequest(
Expand Down
2 changes: 1 addition & 1 deletion src/plus/integrations/providers/gitlab/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ $search: String!
}
}

private getProjectId(
public getProjectId(
provider: Provider,
token: string,
group: string,
Expand Down
1 change: 1 addition & 0 deletions src/plus/integrations/providers/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ export function toSearchedIssue(
labels: issue.labels.map(label => ({ color: label.color ?? undefined, name: label.name })),
commentsCount: issue.commentCount ?? undefined,
thumbsUpCount: issue.upvoteCount ?? undefined,
body: issue.description ?? undefined,
},
};
}
Expand Down
15 changes: 13 additions & 2 deletions src/plus/startWork/startWork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
QuickCommand,
StepResultBreak,
} from '../../commands/quickCommand';
import { OpenOnGitHubQuickInputButton, OpenOnJiraQuickInputButton } from '../../commands/quickCommand.buttons';
import {
OpenOnGitHubQuickInputButton,
OpenOnGitLabQuickInputButton,
OpenOnJiraQuickInputButton,
} from '../../commands/quickCommand.buttons';
import { getSteps } from '../../commands/quickWizard.utils';
import { proBadge } from '../../constants';
import type { IntegrationId } from '../../constants.integrations';
Expand Down Expand Up @@ -68,7 +72,11 @@ export interface StartWorkCommandArgs {
source?: Sources;
}

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

Expand Down Expand Up @@ -500,6 +508,7 @@ export class StartWorkCommand extends QuickCommand<State> {

switch (button) {
case OpenOnGitHubQuickInputButton:
case OpenOnGitLabQuickInputButton:
case OpenOnJiraQuickInputButton:
this.sendItemActionTelemetry('soft-open', item, state, context);
this.open(item);
Expand Down Expand Up @@ -615,6 +624,8 @@ function getOpenOnWebQuickInputButton(integrationId: string): QuickInputButton |
switch (integrationId) {
case HostingIntegrationId.GitHub:
return OpenOnGitHubQuickInputButton;
case HostingIntegrationId.GitLab:
return OpenOnGitLabQuickInputButton;
case IssueIntegrationId.Jira:
return OpenOnJiraQuickInputButton;
default:
Expand Down
Loading