Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bitbucket filter #164

Merged
merged 36 commits into from Dec 6, 2019
Merged
Changes from 7 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1f35259
fix: auth is possibly undefined
adelkahomolova Nov 19, 2019
572371b
feat: add options for filtering in CollaborationInspector
adelkahomolova Nov 19, 2019
7d2ecb5
fix: use different interfaces for GitHub PR and Bitbucket PR
adelkahomolova Nov 19, 2019
98999f7
test: add test when the state is provided
adelkahomolova Nov 19, 2019
74fe662
fix: add BitbucketPullRequestState because of CollaborationInspector …
adelkahomolova Nov 19, 2019
90b995b
fix: add filtering to the getPullRequests()
adelkahomolova Nov 19, 2019
fa2d21d
Merge branch 'master' of https://github.com/DXHeroes/dx-scanner into …
adelkahomolova Nov 19, 2019
2b67091
fix: use own definition of PR -> implement getPRState() to get the st…
adelkahomolova Nov 22, 2019
f54425d
fix: get the info about user only once as it is always the same
adelkahomolova Nov 22, 2019
30e2908
Merge branch 'master' of https://github.com/DXHeroes/dx-scanner into …
adelkahomolova Nov 22, 2019
2ddd585
fix: stringify undefined value
adelkahomolova Nov 25, 2019
0988936
Update src/model.ts
adelkahomolova Nov 25, 2019
0b28ccb
Update src/services/bitbucket/BitbucketService.ts
adelkahomolova Nov 25, 2019
25511e2
Update src/services/bitbucket/BitbucketService.ts
adelkahomolova Nov 25, 2019
388734f
Update src/services/git/CSVServicesUtils.ts
adelkahomolova Nov 25, 2019
ca12e17
Update src/services/git/CSVServicesUtils.ts
adelkahomolova Nov 25, 2019
aaeec66
Merge branch 'master' of https://github.com/DXHeroes/dx-scanner into …
adelkahomolova Nov 25, 2019
c8c2f09
fix: rename CVS to VCS
adelkahomolova Nov 25, 2019
1769b52
fix: retype return type from getPRState()
adelkahomolova Nov 25, 2019
4a2d83d
fix: rename files
adelkahomolova Nov 25, 2019
42a10e5
fix: use qs library
adelkahomolova Nov 25, 2019
7f19213
fix: return array of states
adelkahomolova Nov 25, 2019
ab592ce
WIP: fix listing all PRs
adelkahomolova Nov 25, 2019
c86e979
Merge branch 'master' of https://github.com/DXHeroes/dx-scanner into …
adelkahomolova Dec 2, 2019
6022e9e
fix: add qs
adelkahomolova Dec 2, 2019
03eafcf
fix: use axios because bitbucket client can't allow to get all pullre…
adelkahomolova Dec 4, 2019
0ff0093
fix: rename interfaces - add mock to the end of the name
adelkahomolova Dec 4, 2019
3904444
Update src/services/bitbucket/BitbucketService.ts
adelkahomolova Dec 4, 2019
6145355
refactor: use DRY
adelkahomolova Dec 4, 2019
fa0d129
fix: data of owner
adelkahomolova Dec 6, 2019
905fd11
feat: add mockBitbucketPullRequestResponse()
adelkahomolova Dec 6, 2019
1b6be4a
fix: fix tests and use mockBitbucketPullRequestResponse()
adelkahomolova Dec 6, 2019
c3c5ab2
fix: values of owner
adelkahomolova Dec 6, 2019
952bb79
fix: delete unnecessary mock file
adelkahomolova Dec 6, 2019
08e270a
Merge branch 'master' of https://github.com/DXHeroes/dx-scanner into …
adelkahomolova Dec 6, 2019
0815844
fix: typo
adelkahomolova Dec 6, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,7 +1,10 @@
import { injectable, inject } from 'inversify';
import { inject, injectable } from 'inversify';
import { ProjectIssueBrowserService as ContentRepositoryBrowserService } from '../model';
import { GitHubPullRequestState } from '../services/git/IGitHubService';
import { Types } from '../types';
import { ListGetterOptions } from './common/ListGetterOptions';
import { ICollaborationInspector } from './ICollaborationInspector';
import { BitbucketPullRequestState } from '../services/git/ICVSService';

@injectable()
export class CollaborationInspector implements ICollaborationInspector {
@@ -11,8 +14,12 @@ export class CollaborationInspector implements ICollaborationInspector {
this.service = service;
}

async getPullRequests(owner: string, repo: string) {
return this.service.getPullRequests(owner, repo);
async getPullRequests(
owner: string,
repo: string,
options?: ListGetterOptions<{ state?: GitHubPullRequestState | BitbucketPullRequestState }>,
This conversation was marked as resolved by prokopsimek

This comment has been minimized.

Copy link
@prokopsimek

prokopsimek Nov 20, 2019

Member

use our own PullRequestState

) {
return this.service.getPullRequests(owner, repo, options);
}

async getPullRequest(owner: string, repo: string, prNumber: number) {
@@ -1,8 +1,15 @@
import { Paginated } from './common/Paginated';
import { PullCommits, PullFiles, PullRequest } from '../services/git/model';
import { ListGetterOptions } from './common/ListGetterOptions';
import { Paginated } from './common/Paginated';
import { GitHubPullRequestState } from '../services/git/IGitHubService';
import { BitbucketPullRequestState } from '../services/git/ICVSService';

export interface ICollaborationInspector {
getPullRequests(owner: string, repo: string): Promise<Paginated<PullRequest>>;
getPullRequests(
owner: string,
repo: string,
options?: ListGetterOptions<{ state?: GitHubPullRequestState | BitbucketPullRequestState }>,
): Promise<Paginated<PullRequest>>;
getPullRequest(owner: string, repo: string, prNumber: number): Promise<PullRequest>;
getPullCommits(owner: string, repo: string, prNumber: number): Promise<Paginated<PullCommits>>;
getPullRequestFiles(owner: string, repo: string, prNumber: number): Promise<Paginated<PullFiles>>;
@@ -7,6 +7,9 @@ import { getPullCommits } from '../git/__MOCKS__/bitbucketServiceMockFolder/getP
import { getIssuesResponse } from '../git/__MOCKS__/bitbucketServiceMockFolder/getIssuesResponse';
import { getIssueResponse } from '../git/__MOCKS__/bitbucketServiceMockFolder/getIssueResponse';
import { getIssueCommentsResponse } from '../git/__MOCKS__/bitbucketServiceMockFolder/getIssueCommentsResponse';
import { GitHubPullRequestState } from '../git/IGitHubService';
import { BitbucketPullRequestState } from '../git/ICVSService';
import { ListGetterOptions } from '../../inspectors/common/ListGetterOptions';

describe('Bitbucket Service', () => {
let service: BitbucketService;
@@ -62,4 +65,20 @@ describe('Bitbucket Service', () => {
const response = await service.getIssueComments('pypy', 'pypy', 3086);
expect(response).toMatchObject(getIssueCommentsResponse);
});

it('returns declined pull requests in own interface', async () => {
const state: ListGetterOptions<{ state?: BitbucketPullRequestState }> = {
filter: {
state: BitbucketPullRequestState.declined,
},
};

nock(bitbucketNock.url)
.get('/users/pypy')
.reply(200);
bitbucketNock.getApiResponse('pullrequests', undefined, undefined, state.filter!.state);

const response = await service.getPullRequests('pypy', 'pypy', state);
expect(response).toMatchObject(getPullRequestsResponse);
});
});
@@ -25,7 +25,9 @@ import {
Directory,
File,
} from '../git/model';
import { ICVSService } from '../git/ICVSService';
import { ICVSService, BitbucketPullRequestState } from '../git/ICVSService';
import { ListGetterOptions } from '../../inspectors/common/ListGetterOptions';
import { PullRequestState } from '../../inspectors/ICollaborationInspector';
const debug = Debug('cli:services:git:bitbucket-service');

@injectable()
@@ -45,7 +47,7 @@ export class BitbucketService implements ICVSService {

let username: string;
let password: string | undefined;
if (argumentsProvider.auth?.includes(':')) {
if (argumentsProvider.auth && argumentsProvider.auth.includes(':')) {
username = argumentsProvider.auth.split(':')[0];
password = argumentsProvider.auth.split(':')[1];
} else {
@@ -73,46 +75,59 @@ export class BitbucketService implements ICVSService {
return this.unwrap(this.client.repositories.get(params));
}

async getPullRequests(owner: string, repo: string): Promise<Paginated<PullRequest>> {
async getPullRequests(
owner: string,
repo: string,
options?: ListGetterOptions<{ state?: BitbucketPullRequestState }>,
): Promise<Paginated<PullRequest>> {
const params: Bitbucket.Params.PullrequestsList = {
repo_slug: repo,
username: owner,
};

let state;
if (options !== undefined && options.filter !== undefined && options.filter.state !== undefined) {
This conversation was marked as resolved by adelkahomolova

This comment has been minimized.

Copy link
@prokopsimek

prokopsimek Nov 25, 2019

Member
Suggested change
if (options !== undefined && options.filter !== undefined && options.filter.state !== undefined) {
if (options?.filter?.state) {
state = options.filter.state;
Object.assign(params, { state: state });
This conversation was marked as resolved by adelkahomolova

This comment has been minimized.

Copy link
@prokopsimek

prokopsimek Nov 25, 2019

Member
Suggested change
Object.assign(params, { state: state });
params = { ...params, state }
}

const response = <DeepRequired<Bitbucket.Response<Bitbucket.Schema.PaginatedPullrequests>>>await this.client.pullrequests.list(params);
const url = 'www.bitbucket.org';

const values = response.data.values.map(async (val) => ({
user: {
id: val.author.uuid,
login: val.author.nickname,
url: val.author.links.html.href,
},
url: val.links.html.href,
body: val.description,
createdAt: val.created_on,
updatedAt: val.updated_on,
//TODO
closedAt: null,
//TODO
mergedAt: null,
state: val.state,
id: val.id,
base: {
repo: {
url: val.destination.repository.links.html.href,
name: val.destination.repository.name,
id: val.destination.repository.uuid,
owner: {
login: <string>val.destination.repository.full_name.split('/').shift(),
id: <string>(await this.client.users.get({ username: `${val.destination.repository.full_name.split('/').shift()}` })).data.uuid
? <string>(await this.client.users.get({ username: `${val.destination.repository.full_name.split('/').shift()}` })).data.uuid
: 'undefined',
url: url.concat(`/${val.destination.repository.full_name.split('/').shift()}`),
const values = response.data.values.map(async (val) => {
const ownerId = <string>(
(await this.client.users.get({ username: `${val.destination.repository.full_name.split('/').shift()}` })).data.uuid
This conversation was marked as resolved by prokopsimek

This comment has been minimized.

Copy link
@prokopsimek

prokopsimek Nov 20, 2019

Member

don't call it in a map

);
return {
user: {
id: val.author.uuid,
login: val.author.nickname,
url: val.author.links.html.href,
},
url: val.links.html.href,
body: val.description,
createdAt: val.created_on,
updatedAt: val.updated_on,
//TODO
closedAt: null,
//TODO
mergedAt: null,
state: val.state,
id: val.id,
base: {
repo: {
url: val.destination.repository.links.html.href,
name: val.destination.repository.name,
id: val.destination.repository.uuid,
owner: {
login: <string>val.destination.repository.full_name.split('/').shift(),
id: ownerId ? ownerId : 'undefined',
url: url.concat(`/${val.destination.repository.full_name.split('/').shift()}`),
},
},
},
},
}));
};
});

const pagination = this.getPagination(response.data);

@@ -1,40 +1,39 @@
import { injectable, inject } from 'inversify';
import {
PullRequest,
Contributor,
PullRequestReview,
Commit,
ContributorStats,
Directory,
File,
Issue,
PullFiles,
PullCommits,
IssueComment,
Symlink,
RepoContentType,
} from './model';
import { ICVSService } from './ICVSService';
import { Paginated } from '../../inspectors/common/Paginated';
import {
import Octokit, {
IssuesListForRepoResponseItem,
PullsListResponseItem,
PullsListReviewsResponseItem,
ReposGetContributorsStatsResponseItem,
} from '@octokit/rest';
import { isArray } from 'util';
import { ListGetterOptions } from '../../inspectors/common/ListGetterOptions';
import Octokit from '@octokit/rest';
import { grey } from 'colors';
import { inspect } from 'util';
import Debug from 'debug';
import { delay } from '../../lib/delay';
import { Types } from '../../types';
import { inject, injectable } from 'inversify';
import { inspect, isArray } from 'util';
import { ListGetterOptions } from '../../inspectors/common/ListGetterOptions';
import { Paginated } from '../../inspectors/common/Paginated';
import { PullRequestState } from '../../inspectors/ICollaborationInspector';
import { ArgumentsProvider } from '../../inversify.config';
import { delay } from '../../lib/delay';
import { ErrorFactory } from '../../lib/errors';
import { ICache } from '../../scanner/cache/ICache';
import { InMemoryCache } from '../../scanner/cache/InMemoryCache';
import { Types } from '../../types';
import { ICVSService, BitbucketPullRequestState } from './ICVSService';
import {
Commit,
Contributor,
ContributorStats,
Directory,
File,
Issue,
IssueComment,
PullCommits,
PullFiles,
PullRequest,
PullRequestReview,
RepoContentType,
Symlink,
} from './model';
import { GitHubPullRequestState } from './IGitHubService';
import { ErrorFactory } from '../../lib/errors';
const debug = Debug('cli:services:git:github-service');

@injectable()
@@ -71,7 +70,7 @@ export class GitHubService implements ICVSService {
async getPullRequests(
owner: string,
repo: string,
options?: ListGetterOptions<{ state?: GitHubPullRequestState }>,
options?: ListGetterOptions<{ state?: GitHubPullRequestState | BitbucketPullRequestState }>,
This conversation was marked as resolved by prokopsimek

This comment has been minimized.

Copy link
@prokopsimek

prokopsimek Nov 20, 2019

Member
  • BitbucketPullRequestState
): Promise<Paginated<PullRequest>> {
let url = 'GET /repos/:owner/:repo/pulls';
if (options !== undefined && options.filter !== undefined && options.filter.state !== undefined) {
@@ -1,13 +1,13 @@
import { ListGetterOptions } from '../../inspectors/common/ListGetterOptions';
import { PullRequest, PullRequestReview, Commit, Contributor, ContributorStats, Issue, Directory, File, Symlink, PullFiles } from './model';
import { Paginated } from '../../inspectors/common/Paginated';
import { GitHubPullRequestState } from './IGitHubService';
import { Commit, Contributor, ContributorStats, Directory, File, Issue, PullFiles, PullRequest, PullRequestReview, Symlink } from './model';

export interface ICVSService {
getPullRequests(
owner: string,
repo: string,
options?: ListGetterOptions<{ state?: GitHubPullRequestState }>,
options?: ListGetterOptions<{ state?: GitHubPullRequestState | BitbucketPullRequestState }>,
This conversation was marked as resolved by prokopsimek

This comment has been minimized.

Copy link
@prokopsimek

prokopsimek Nov 20, 2019

Member

PullRequestState

): Promise<Paginated<PullRequest>>;
getPullRequestReviews(owner: string, repo: string, prNumber: number): Promise<Paginated<PullRequestReview>>;
getPullRequestFiles(owner: string, repo: string, prNumber: number): Promise<Paginated<PullFiles>>;
@@ -19,3 +19,10 @@ export interface ICVSService {
getIssue(owner: string, repo: string, issueNumber: number): Promise<Issue>;
getRepoContent(owner: string, repo: string, path: string): Promise<File | Symlink | Directory | null>;
}

export enum BitbucketPullRequestState {
open = 'OPEN',
closed = 'MERGED',
declined = 'DECLINED',
superseded = 'SUPERSEDED',
}
@@ -11,10 +11,13 @@ export class BitbucketNock {
this.url = 'https://api.bitbucket.org/2.0';
}

getApiResponse(resource: string, id?: number, value?: string): nock.Scope {
getApiResponse(resource: string, id?: number, value?: string, state?: string): nock.Scope {
let url = `${this.url}/repositories/${this.user}/${this.repoName}/${resource}`;
let response;

let params = {};
const persist = true;
This conversation was marked as resolved by prokopsimek

This comment has been minimized.

Copy link
@prokopsimek

prokopsimek Nov 25, 2019

Member

unused var? use linter

This comment has been minimized.

Copy link
@adelkahomolova

adelkahomolova Nov 25, 2019

Author Member

See line 41 for the params and 59 for the persist. Actually I don' change the persist but when I will, I can do it easily.

This comment has been minimized.

Copy link
@prokopsimek

prokopsimek Dec 4, 2019

Member

Ok, thanks :)


if (value !== undefined) {
switch (value) {
case 'comments':
@@ -34,6 +37,9 @@ export class BitbucketNock {
response = new PullRequest().pullRequest;
} else {
response = new PullRequests().pullrequests;
if (state) {
params = { state: state };
}
}
break;
case 'issues':
@@ -50,9 +56,6 @@ export class BitbucketNock {
}
}

const params = {};
const persist = true;

return BitbucketNock.get(url, params, persist).reply(200, response);
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.