Skip to content

Commit

Permalink
fix(link): support new repo association types
Browse files Browse the repository at this point in the history
  • Loading branch information
imhoffd committed Aug 15, 2018
1 parent 1357c5c commit 1c1e1f1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
24 changes: 18 additions & 6 deletions packages/@ionic/cli-utils/src/definitions.ts
Expand Up @@ -123,21 +123,33 @@ export interface GithubBranch {
}

export interface AppAssociation {
repository: GithubRepoAssociation;
repository: RepoAssociation;
}

export interface RepoAssociation {
export interface RepoAssociationBase {
html_url: string;
clone_url: string;
full_name: string;
}

export interface GithubRepoAssociation extends RepoAssociation {
type: 'github';
id: number;
export interface GithubRepoAssociation extends RepoAssociationBase {
type: 'github';
id: number;
}

export interface BitbucketCloudRepoAssociation extends RepoAssociationBase {
type: 'bitbucket_cloud';
id: string;
}

export type AssociationType = 'github';
export interface BitbucketServerRepoAssociation extends RepoAssociationBase {
type: 'bitbucket_server';
id: number;
}

export type RepoAssociation = GithubRepoAssociation | BitbucketCloudRepoAssociation | BitbucketServerRepoAssociation;

export type AssociationType = 'github' | 'bitbucket_cloud' | 'bitbucket_server';

export interface App {
id: string;
Expand Down
31 changes: 27 additions & 4 deletions packages/@ionic/cli-utils/src/guards.ts
Expand Up @@ -4,6 +4,8 @@ import {
APIResponseSuccess,
App,
AppAssociation,
BitbucketCloudRepoAssociation,
BitbucketServerRepoAssociation,
CommandPreRun,
CordovaPackageJson,
ExitCodeException,
Expand Down Expand Up @@ -118,10 +120,17 @@ export function isGithubBranchListResponse(r: APIResponse): r is Response<Github

export function isAppAssociation(a: object): a is AppAssociation {
const association = a as AppAssociation;
return association
&& typeof association.repository === 'object'
&& typeof association.repository.html_url === 'string'
&& isGithubRepoAssociation(association.repository);

return (
association &&
typeof association.repository === 'object' &&
typeof association.repository.html_url === 'string' &&
(
isGithubRepoAssociation(association.repository) ||
isBitbucketCloudRepoAssociation(association.repository) ||
isBitbucketServerRepoAssociation(association.repository)
)
);
}

export function isAppAssociationResponse(r: APIResponse): r is Response<AppAssociation> {
Expand All @@ -137,6 +146,20 @@ export function isGithubRepoAssociation(a: object): a is GithubRepoAssociation {
&& typeof repo.id === 'number';
}

export function isBitbucketCloudRepoAssociation(a: object): a is BitbucketCloudRepoAssociation {
const repo = a as BitbucketCloudRepoAssociation;
return repo
&& repo.type === 'bitbucket_cloud'
&& typeof repo.id === 'string';
}

export function isBitbucketServerRepoAssociation(a: object): a is BitbucketServerRepoAssociation {
const repo = a as BitbucketServerRepoAssociation;
return repo
&& repo.type === 'bitbucket_server'
&& typeof repo.id === 'number';
}

export function isApp(d: object): d is App {
const details = d as App;
return details
Expand Down

0 comments on commit 1c1e1f1

Please sign in to comment.