Skip to content

Commit

Permalink
Merge branch 'master' into fix/local-repo-wo-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
vlasy committed Jan 6, 2020
2 parents 8b93653 + 0d01768 commit a1cb9f4
Show file tree
Hide file tree
Showing 96 changed files with 2,526 additions and 818 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.13.0
12.13.1
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
"language": "typescriptreact",
"autoFix": true
}
]
],
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.preferences.importModuleSpecifier": "relative"
}
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignore-engines true
235 changes: 235 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ if (dev) {
require('ts-node').register({ project });
}

require(`../${dev ? 'src' : 'lib/src'}`)
require(`../${dev ? 'src' : 'lib'}`)
.run()
.catch(require('@oclif/errors/handle'));
58 changes: 33 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dx-scanner",
"description": "Scan your project for possible DX recommendations.",
"version": "1.21.1",
"version": "1.27.0",
"author": "DX Heroes LTD <info@dxheroes.io> (https://dxheroes.io)",
"homepage": "https://github.com/dxheroes/dx-scanner",
"repository": "ssh://git@github.com/dxheroes/dx-scanner.git",
Expand All @@ -10,7 +10,7 @@
"scripts": {
"build": "rimraf lib && tsc -b",
"build:watch": "yarn build -w",
"lint": "eslint --ext .ts 'src' 'test' 'typings'",
"lint": "eslint --ext .ts 'src' 'types'",
"lint:fix": "yarn lint --fix",
"prepack": "yarn build",
"start": "./bin/run",
Expand All @@ -27,70 +27,78 @@
"dependencies": {
"@oclif/command": "1.5.19",
"@oclif/config": "1.13.3",
"@oclif/plugin-help": "2.2.1",
"@octokit/rest": "16.35.0",
"@oclif/plugin-help": "2.2.3",
"@octokit/rest": "16.35.2",
"@types/eslint": "6.1.3",
"@types/js-yaml": "3.12.1",
"@types/table": "4.0.7",
"@types/qs": "6.9.0",
"@types/yaml": "1.2.0",
"axios": "0.19.0",
"bitbucket": "1.15.2",
"bitbucket": "1.17.0",
"colors": "1.4.0",
"cross-env": "6.0.3",
"debug": "4.1.1",
"eslint": "6.6.0",
"eslint": "6.7.2",
"eslint-plugin-eslint-plugin": "2.1.0",
"git-url-parse": "11.1.2",
"glob": "7.1.6",
"gradle-to-js": "2.0.0",
"inversify": "5.0.1",
"js-yaml": "3.13.1",
"lodash": "4.17.15",
"memfs": "2.16.1",
"moment": "2.24.0",
"memfs": "3.0.1",
"node-filter-async": "1.1.3",
"npm-check-updates": "3.2.1",
"oclif": "1.14.2",
"npm-check-updates": "3.2.2",
"oclif": "1.15.1",
"parse-commit-message": "3.2.3",
"qs": "6.9.1",
"reflect-metadata": "0.1.13",
"semver": "6.3.0",
"simple-git": "1.126.0",
"semver": "7.0.0",
"simple-git": "1.129.0",
"table": "5.4.6",
"toposort": "2.0.2",
"ts-node": "8.5.2",
"ts-node": "8.5.4",
"tslib": "1.10.0",
"typescript": "3.7.2",
"update-notifier": "3.0.1",
"xml2js": "0.4.22"
"typescript": "3.7.3",
"update-notifier": "4.0.0",
"xml2js": "0.4.22",
"yaml": "1.7.2"
},
"devDependencies": {
"@semantic-release/changelog": "3.0.5",
"@semantic-release/changelog": "3.0.6",
"@semantic-release/git": "7.0.18",
"@types/debug": "4.1.5",
"@types/git-url-parse": "9.0.0",
"@types/glob": "7.1.1",
"@types/jest": "24.0.23",
"@types/lodash": "4.14.148",
"@types/node": "12.12.8",
"@types/lodash": "4.14.149",
"@types/node": "12.12.17",
"@types/rimraf": "2.0.3",
"@types/semver": "6.2.0",
"@types/toposort": "2.0.3",
"@types/update-notifier": "2.5.0",
"@types/xml2js": "0.4.5",
"@typescript-eslint/eslint-plugin": "2.7.0",
"@typescript-eslint/parser": "2.7.0",
"@typescript-eslint/eslint-plugin": "2.11.0",
"@typescript-eslint/parser": "2.11.0",
"codecov": "3.6.1",
"eslint-config-prettier": "6.6.0",
"eslint-plugin-prettier": "3.1.1",
"eslint-config-prettier": "6.7.0",
"eslint-plugin-prettier": "3.1.2",
"jest": "24.9.0",
"nock": "11.7.0",
"prettier": "1.19.1",
"rimraf": "3.0.0",
"semantic-release": "15.13.31",
"semantic-release-slack-bot": "1.3.5",
"ts-jest": "24.1.0"
"semantic-release-slack-bot": "1.3.6",
"ts-jest": "24.2.0"
},
"engineStrict": true,
"engines": {
"node": "^12",
"yarn": "^1"
},
"main": "lib/src/index.js",
"main": "lib/index.js",
"bin": {
"dx-scanner": "./bin/run",
"dxscanner": "./bin/run",
Expand Down
14 changes: 14 additions & 0 deletions src/contexts/language/languageContextBinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { bindProjectComponentContext } from '../projectComponent/projectComponen
import { JavaPackageInspector } from '../../inspectors/package/JavaPackageInspector';
import { JavaComponentDetector } from '../../detectors/Java/JavaComponentDetector';
import { LanguageContext } from './LanguageContext';
import { CollaborationInspector } from '../../inspectors/CollaborationInspector';
import { IssueTrackingInspector } from '../../inspectors/IssueTrackingInspector';

export const bindLanguageContext = (container: Container) => {
container.bind(Types.LanguageContextFactory).toFactory(
Expand All @@ -29,6 +31,7 @@ const createLanguageContainer = (languageAtPath: LanguageAtPath, rootContainer:
bindComponentDetectors(container);
bindProjectComponentContext(container);
bindPackageInspectors(languageAtPath, container);
bindCollaborationInspectors(container);

container.bind(LanguageContext).toSelf();
return container;
Expand Down Expand Up @@ -90,6 +93,17 @@ const bindComponentDetectors = (container: Container) => {
});
};

const bindCollaborationInspectors = (container: Container) => {
container
.bind(Types.ICollaborationInspector)
.to(CollaborationInspector)
.inSingletonScope();
container
.bind(Types.IIssueTrackingInspector)
.to(IssueTrackingInspector)
.inSingletonScope();
};

export const DETECT_LANGUAGE_TAG = 'language';
/**
* Language tag for Project Component Detector. Determines which language this detector supports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const createProjectComponentContainer = (projectComponent: ProjectComponent, roo
projectComponent: projectComponent,
packageInspector: ctx.container.get(Types.IPackageInspector),
gitInspector,
issueTrackingInspector: undefined,
collaborationInspector: undefined,
issueTrackingInspector: ctx.container.get(Types.IIssueTrackingInspector),
collaborationInspector: ctx.container.get(Types.ICollaborationInspector),
fileInspector: ctx.container.get(Types.IFileInspector),
root: {
fileInspector: ctx.container.get(Types.IRootFileInspector),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JavaScriptComponentDetector } from './JavaScriptComponentDetector';
import { ProgrammingLanguage, ProjectComponentPlatform } from '../../model';
import { JavaScriptPackageInspector } from '../../inspectors/package/JavaScriptPackageInspector';
import { mockPackage } from '../../../test/helpers/mockPackage';
import { mockPackage } from '../../test/helpers/mockPackage';
jest.mock('../../inspectors/package/JavaScriptPackageInspector');

describe('JavaScriptComponentDetector', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/ScanningStrategyDetector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ServiceType, AccessType } from './ScanningStrategyDetector';
import git from 'simple-git/promise';
import nock from 'nock';
import { createTestContainer } from '../inversify.config';
import { GitHubNock } from '../../test/helpers/gitHubNock';
import { GitHubNock } from '../test/helpers/gitHubNock';
jest.mock('simple-git/promise');

describe('ScanningStrategyDetector', () => {
Expand Down
4 changes: 0 additions & 4 deletions src/detectors/__MOCKS__/index.ts

This file was deleted.

11 changes: 11 additions & 0 deletions src/detectors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export * from './Cpp/CppLanguageDetector';
export * from './Golang/GolangLanguageDetector';
export * from './Java/JavaComponentDetector';
export * from './Java/JavaLanguageDetector';
export * from './JavaScript/JavaScriptComponentDetector';
export * from './JavaScript/JavaScriptLanguageDetector';
export * from './PHP/PHPLanguageDetector';
export * from './Python/PythonLanguageDetector';
export * from './Ruby/RubyLanguageDetector';
export * from './utils/ScanningStrategyDetectorUtils';
export * from './ScanningStrategyDetector';
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class DXScannerCommand extends Command {
const container = createRootContainer({ uri: scanPath, auth: authorization, json, fail, recursive: flags.recursive });
const scanner = container.get(Scanner);

if (flags.init) {
await scanner.init();
process.exit(0);
}

let scanResult: ScanResult;
scanResult = await scanner.scan();
if (scanResult.needsAuth) {
Expand Down
24 changes: 14 additions & 10 deletions src/inspectors/CollaborationInspector.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { CollaborationInspector } from './CollaborationInspector';
import { getPullsServiceResponse } from '../services/git/__MOCKS__/gitHubServiceMockFolder/getPullsServiceResponse.mock';
import { getPullServiceResponse } from '../services/git/__MOCKS__/gitHubServiceMockFolder/getPullServiceResponse.mock';
import { getPullsFilesResponse } from '../services/git/__MOCKS__/gitHubServiceMockFolder/getPullsFiles.mock';
import { getPullsFilesServiceResponse } from '../services/git/__MOCKS__/gitHubServiceMockFolder/getPullFilesServiceResponse.mock';
import { getPullCommitsResponse } from '../services/git/__MOCKS__/gitHubServiceMockFolder/getPullsCommitsResponse.mock';
import { getPullCommitsServiceResponse } from '../services/git/__MOCKS__/gitHubServiceMockFolder/getPullCommitsServiceResponse.mock';
import nock from 'nock';
import { TestContainerContext } from '../inversify.config';
import { createTestContainer } from '../inversify.config';
import { GitHubNock } from '../../test/helpers/gitHubNock';
import { GitHubNock } from '../test/helpers/gitHubNock';
import {
getPullsServiceResponse,
getPullServiceResponse,
getPullsFilesResponse,
getPullsFilesServiceResponse,
getPullCommitsResponse,
getPullCommitsServiceResponse,
} from '../services/git/__MOCKS__/gitHubServiceMockFolder';

describe('Collaboration Inspector', () => {
let inspector: CollaborationInspector;
Expand All @@ -24,9 +26,11 @@ describe('Collaboration Inspector', () => {
});

it('returns paginated pull requests', async () => {
new GitHubNock('1', 'octocat', 1296269, 'Hello-World').getPulls([
{ number: 1347, state: 'open', title: 'new-feature', body: 'Please pull these awesome changes', head: 'new-topic', base: 'master' },
]);
new GitHubNock('1', 'octocat', 1296269, 'Hello-World').getPulls({
pulls: [
{ number: 1347, state: 'open', title: 'new-feature', body: 'Please pull these awesome changes', head: 'new-topic', base: 'master' },
],
});

const response = await inspector.getPullRequests('octocat', 'Hello-World');
expect(response).toMatchObject(getPullsServiceResponse);
Expand Down
31 changes: 22 additions & 9 deletions src/inspectors/CollaborationInspector.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { injectable, inject } from 'inversify';
import { ProjectIssueBrowserService as ContentRepositoryBrowserService } from '../model';
import { inject, injectable } from 'inversify';
import { Types } from '../types';
import { ICollaborationInspector } from './ICollaborationInspector';
import { ListGetterOptions } from './common/ListGetterOptions';
import { ICollaborationInspector, PullRequestState } from './ICollaborationInspector';
import { VCSService } from '../model';

@injectable()
export class CollaborationInspector implements ICollaborationInspector {
private service: ContentRepositoryBrowserService;
private service: VCSService;

constructor(@inject(Types.IContentRepositoryBrowser) service: ContentRepositoryBrowserService) {
constructor(@inject(Types.IContentRepositoryBrowser) service: VCSService) {
this.service = service;
}

async getPullRequests(owner: string, repo: string) {
return this.service.getPullRequests(owner, repo);
async getPullRequests(
owner: string,
repo: string,
options?: { withDiffStat?: boolean } & ListGetterOptions<{ state?: PullRequestState }>,
) {
return this.service.getPullRequests(owner, repo, options);
}

async getPullRequest(owner: string, repo: string, prNumber: number) {
return this.service.getPullRequest(owner, repo, prNumber);
async getPullRequest(owner: string, repo: string, prNumber: number, withDiffStat?: boolean) {
return this.service.getPullRequest(owner, repo, prNumber, withDiffStat);
}

async getPullRequestFiles(owner: string, repo: string, prNumber: number) {
Expand All @@ -26,4 +31,12 @@ export class CollaborationInspector implements ICollaborationInspector {
async getPullCommits(owner: string, repo: string, prNumber: number) {
return this.service.getPullCommits(owner, repo, prNumber);
}

async getRepoCommits(owner: string, repo: string, sha?: string) {
return this.service.getRepoCommits(owner, repo, sha);
}

async getPullsDiffStat(owner: string, repo: string, prNumber: string) {
return this.service.getPullsDiffStat(owner, repo, prNumber);
}
}
13 changes: 10 additions & 3 deletions src/inspectors/ICollaborationInspector.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Paginated } from './common/Paginated';
import { PullCommits, PullFiles, PullRequest } from '../services/git/model';
import { PullCommits, PullFiles, PullRequest, Commit, Lines } from '../services/git/model';
import { ListGetterOptions } from './common/ListGetterOptions';

export interface ICollaborationInspector {
getPullRequests(owner: string, repo: string): Promise<Paginated<PullRequest>>;
getPullRequest(owner: string, repo: string, prNumber: number): Promise<PullRequest>;
getPullRequests(
owner: string,
repo: string,
options?: { withDiffStat?: boolean } & ListGetterOptions<{ state?: PullRequestState }>,
): Promise<Paginated<PullRequest>>;
getPullRequest(owner: string, repo: string, prNumber: number, withDiffStat?: boolean): Promise<PullRequest>;
getPullCommits(owner: string, repo: string, prNumber: number): Promise<Paginated<PullCommits>>;
getPullRequestFiles(owner: string, repo: string, prNumber: number): Promise<Paginated<PullFiles>>;
getRepoCommits(owner: string, repo: string, sha?: string): Promise<Paginated<Commit>>;
getPullsDiffStat(owner: string, repo: string, prNumber: string): Promise<Lines>;
}

export enum PullRequestState {
Expand Down
8 changes: 8 additions & 0 deletions src/inspectors/IIssueTrackingInspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ export enum IssueState {
all = 'all',
}

export enum BitbucketIssueState {
new = 'new',
closed = 'closed',
duplicate = 'duplicate',
resolved = 'resolved',
invalid = 'invalid',
}

export interface IIssueTrackingInspector {
getIssues(owner: string, repo: string): Promise<Paginated<Issue>>;
getIssue(owner: string, repo: string, id: number): Promise<Issue>;
Expand Down
16 changes: 9 additions & 7 deletions src/inspectors/IssueTrackingInspector.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { IssueTrackingInspector } from './IssueTrackingInspector';
import { getIssuesResponse } from '../services/git/__MOCKS__/gitHubServiceMockFolder/getIssuesResponse.mock';
import { getIssuesServiceResponse } from '../services/git/__MOCKS__/gitHubServiceMockFolder/getIssuesServiceResponse.mock';
import { getIssueCommentsServiceResponse } from '../services/git/__MOCKS__/gitHubServiceMockFolder/getIssueCommentsServiceResponse.mock';
import { getIssueCommentsResponse } from '../services/git/__MOCKS__/gitHubServiceMockFolder/getIssueCommentsResponse.mock';
import { getIssueResponse } from '../services/git/__MOCKS__/gitHubServiceMockFolder/getIssueResponse.mock';
import { getIssueServiceResponse } from '../services/git/__MOCKS__/gitHubServiceMockFolder/getIssueServiceResponse.mock';
import nock from 'nock';
import { TestContainerContext, createTestContainer } from '../inversify.config';
import { GitHubNock } from '../../test/helpers/gitHubNock';
import { GitHubNock } from '../test/helpers/gitHubNock';
import {
getIssuesResponse,
getIssuesServiceResponse,
getIssueCommentsResponse,
getIssueCommentsServiceResponse,
getIssueResponse,
getIssueServiceResponse,
} from '../services/git/__MOCKS__/gitHubServiceMockFolder';

describe('Issue Tracking Inspector', () => {
let inspector: IssueTrackingInspector;
Expand Down
Loading

0 comments on commit a1cb9f4

Please sign in to comment.