Skip to content

Commit

Permalink
Shows GitLab issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeibbb committed Nov 21, 2024
1 parent e72be11 commit 4c249da
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
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

0 comments on commit 4c249da

Please sign in to comment.