Skip to content

Commit

Permalink
fix: upgraded TS interfaces according to TS 3.6 update
Browse files Browse the repository at this point in the history
  • Loading branch information
prokopsimek committed Oct 23, 2019
1 parent dd99c2e commit a5934a7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/reporters/CLIReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class CLIReporter implements IReporter {
lines.push('----------------------------');

for (const key in PracticeImpact) {
const impact = <PracticeImpact>PracticeImpact[key];
const impact = PracticeImpact[key as keyof typeof PracticeImpact];

const impactLine = this.emitImpactSegment(cwp.practicesAndComponents, impact);
impactLine && lines.push(impactLine);
Expand Down
1 change: 1 addition & 0 deletions src/services/git/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class Git implements IProjectFilesBrowserService {
let result = await this.getRepoContent(await this.followSymLinks(path));
if (result !== null && !isArray(result)) {
result = result as File;
if (!result.content) return '';
return Buffer.from(result.content, result.encoding).toString('utf-8');
} else {
throw ErrorFactory.newInternalError(`${path} is not a file`);
Expand Down
50 changes: 32 additions & 18 deletions src/services/git/GitHubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
PullCommits,
IssueComment,
Symlink,
RepoContentType,
} from './model';
import { ICVSService } from './ICVSService';
import { Paginated } from '../../inspectors/common/Paginated';
Expand All @@ -33,6 +34,7 @@ import { ArgumentsProvider } from '../../inversify.config';
import { ICache } from '../../scanner/cache/ICache';
import { InMemoryCache } from '../../scanner/cache/InMemoryCahce';
import { GitHubPullRequestState } from './IGitHubService';
import { ErrorFactory } from '../../lib/errors';
const debug = Debug('cli:services:git:github-service');

@injectable()
Expand Down Expand Up @@ -288,24 +290,36 @@ export class GitHubService implements ICVSService {
return null;
}

return isArray(response.data)
? response.data.map((item) => ({
name: item.name,
path: item.path,
sha: item.sha,
size: item.size,
type: item.type,
}))
: {
name: response.data.name,
path: response.data.path,
size: response.data.size,
sha: response.data.sha,
type: response.data.type,
content: response.data.content,
encoding: response.data.encoding,
target: response.data.target,
};
if (isArray(response.data)) {
return response.data.map((item) => ({
name: item.name,
path: item.path,
sha: item.sha,
size: item.size,
type: <RepoContentType>item.type,
}));
} else if (response.data.type === RepoContentType.file) {
return {
name: response.data.name,
path: response.data.path,
size: response.data.size,
sha: response.data.sha,
type: response.data.type,
content: response.data.content,
encoding: <BufferEncoding>response.data.encoding,
};
} else if (response.data.type === RepoContentType.symlink) {
return {
name: response.data.name,
path: response.data.path,
size: response.data.size,
sha: response.data.sha,
type: response.data.type,
target: `${response.data.target}`,
};
} else {
throw ErrorFactory.newInternalError('Unexpected response');
}
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Directory, File } from '../../model';
import { Directory, File, RepoContentType } from '../../model';

export const getRepoContentServiceResponseDir: Directory = [
{
name: 'mockFile.ts',
path: 'mockFolder/mockFile.ts',
size: 0,
sha: '980a0d5f19a64b4b30a87d4206aade58726b60e3',
type: 'file',
type: RepoContentType.file,
},
];

Expand All @@ -15,7 +15,7 @@ export const getRepoContentServiceResponseFile: File = {
path: 'README',
size: 13,
sha: '980a0d5f19a64b4b30a87d4206aade58726b60e3',
type: 'file',
type: RepoContentType.file,
content: 'SGVsbG8gV29ybGQhCg==',
encoding: 'base64',
};
16 changes: 11 additions & 5 deletions src/services/git/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,23 @@ export interface RepoContent {
path: string;
sha: string;
size: number;
type: 'dir' | 'file' | 'symlink';
type: RepoContentType;
}

export enum RepoContentType {
dir = 'dir',
file = 'file',
symlink = 'symlink',
}

export interface File extends RepoContent {
type: 'file';
content: string;
encoding: BufferEncoding;
type: RepoContentType.file;
content: string | undefined;
encoding: BufferEncoding | undefined;
}

export interface Symlink extends RepoContent {
type: 'symlink';
type: RepoContentType.symlink;
target: string;
}

Expand Down

0 comments on commit a5934a7

Please sign in to comment.