Skip to content

Commit

Permalink
Adds search by URL for GitHub Enterprise to the Launchpad
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeibbb committed Jan 17, 2025
1 parent c1e45f8 commit aac1101
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/git/models/pullRequest.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// To avoid this file has been created that can collect more simple functions which
// don't require Container and can be tested.

import type { HostingIntegrationId } from '../../constants.integrations';
import type { HostingIntegrationId, SelfHostedIntegrationId } from '../../constants.integrations';

export interface PullRequestUrlIdentity {
provider?: HostingIntegrationId;
provider?: SelfHostedIntegrationId | HostingIntegrationId;

ownerAndRepo?: string;
prNumber: string;
Expand Down
19 changes: 13 additions & 6 deletions src/plus/integrations/providers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import type {
IntegrationAuthenticationProviderDescriptor,
IntegrationAuthenticationService,
} from '../authentication/integrationAuthentication';
import type { RepositoryDescriptor, SupportedIntegrationIds } from '../integration';
import type { RepositoryDescriptor } from '../integration';
import { HostingIntegration } from '../integration';
import type { GitHubRelatedIntegrationIds } from './github/github.utils';
import { getGitHubPullRequestIdentityFromMaybeUrl } from './github/github.utils';
import { providersMetadata } from './models';
import type { ProvidersApi } from './providersApi';
Expand All @@ -44,7 +45,7 @@ const cloudEnterpriseAuthProvider: IntegrationAuthenticationProviderDescriptor =

export type GitHubRepositoryDescriptor = RepositoryDescriptor;

abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends HostingIntegration<
abstract class GitHubIntegrationBase<ID extends GitHubRelatedIntegrationIds> extends HostingIntegration<
ID,
GitHubRepositoryDescriptor
> {
Expand Down Expand Up @@ -266,6 +267,16 @@ abstract class GitHubIntegrationBase<ID extends SupportedIntegrationIds> extends
baseUrl: this.apiBaseUrl,
});
}

protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
const identity = getGitHubPullRequestIdentityFromMaybeUrl(search);
if (identity == null) return undefined;

return {
...identity,
provider: this.id,
};
}
}

export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationId.GitHub> {
Expand Down Expand Up @@ -300,10 +311,6 @@ export class GitHubIntegration extends GitHubIntegrationBase<HostingIntegrationI
super.refresh();
}
}

protected override getProviderPullRequestIdentityFromMaybeUrl(search: string): PullRequestUrlIdentity | undefined {
return getGitHubPullRequestIdentityFromMaybeUrl(search);
}
}

export class GitHubEnterpriseIntegration extends GitHubIntegrationBase<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ suite('Test GitHub PR URL parsing to identity: getPullRequestIdentityFromMaybeUr
: {
ownerAndRepo: ownerAndRepo,
prNumber: prNumber,
provider: 'github',
},
`Parse: ${message} (${JSON.stringify(query)})`,
);
Expand Down
14 changes: 8 additions & 6 deletions src/plus/integrations/providers/github/github.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
// That's why this file has been created that can collect more simple functions which
// don't require Container and can be tested.

import { HostingIntegrationId } from '../../../../constants.integrations';
import type { HostingIntegrationId, SelfHostedIntegrationId } from '../../../../constants.integrations';
import type { PullRequestUrlIdentity } from '../../../../git/models/pullRequest.utils';

export type GitHubRelatedIntegrationIds =
| HostingIntegrationId.GitHub
| SelfHostedIntegrationId.GitHubEnterprise
| SelfHostedIntegrationId.CloudGitHubEnterprise;

export function isMaybeGitHubPullRequestUrl(url: string): boolean {
if (url == null) return false;

return getGitHubPullRequestIdentityFromMaybeUrl(url) != null;
}

export function getGitHubPullRequestIdentityFromMaybeUrl(
search: string,
): (PullRequestUrlIdentity & { provider: HostingIntegrationId.GitHub }) | undefined {
): Omit<PullRequestUrlIdentity, 'provider'> | undefined {
let ownerAndRepo: string | undefined = undefined;
let prNumber: string | undefined = undefined;

Expand All @@ -30,7 +34,5 @@ export function getGitHubPullRequestIdentityFromMaybeUrl(
}
}

return prNumber != null
? { ownerAndRepo: ownerAndRepo, prNumber: prNumber, provider: HostingIntegrationId.GitHub }
: undefined;
return prNumber != null ? { ownerAndRepo: ownerAndRepo, prNumber: prNumber } : undefined;
}

0 comments on commit aac1101

Please sign in to comment.