Skip to content

Commit

Permalink
fix: add email of an author
Browse files Browse the repository at this point in the history
  • Loading branch information
prokopsimek committed Nov 25, 2019
1 parent f108a3a commit ec651b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/services/bitbucket/BitbucketService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ 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 util from 'util';
import { getRepoCommits } from '../git/__MOCKS__/bitbucketServiceMockFolder/getRepoCommits';

describe('Bitbucket Service', () => {
Expand Down
19 changes: 13 additions & 6 deletions src/services/bitbucket/BitbucketService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class BitbucketService implements ICVSService {

let username: string;
let password: string | undefined;
if (argumentsProvider.auth && argumentsProvider.auth.includes(':')) {
if (argumentsProvider.auth?.includes(':')) {
username = argumentsProvider.auth.split(':')[0];
password = argumentsProvider.auth.split(':')[1];
} else {
Expand Down Expand Up @@ -142,7 +142,7 @@ export class BitbucketService implements ICVSService {
createdAt: response.data.created_on,
updatedAt: response.data.updated_on,
//TODO
closedAt: 'undefined',
closedAt: null,
//TODO
mergedAt: null,
state: response.data.state,
Expand Down Expand Up @@ -267,10 +267,10 @@ export class BitbucketService implements ICVSService {
url: val.user.links.html.href,
},
url: val.links.html.href,
body: val.content.raw ? val.content.raw : 'undefined',
body: val.content.raw,
createdAt: val.created_on,
updatedAt: val.updated_on ? val.updated_on : 'undefined',
authorAssociation: val.author_association ? val.author_association : 'undefined',
updatedAt: val.updated_on,
authorAssociation: val.author_association,
id: val.id,
}));
const pagination = this.getPagination(response.data);
Expand All @@ -295,7 +295,7 @@ export class BitbucketService implements ICVSService {
message: val.rendered.message.raw,
author: {
name: val.author.user.nickname,
email: 'undefined',
email: this.extractEmailFromString(val.author.raw) || '',
date: val.date,
},
tree: {
Expand Down Expand Up @@ -359,6 +359,13 @@ export class BitbucketService implements ICVSService {

return { totalCount, hasNextPage, hasPreviousPage, page, perPage };
}

private extractEmailFromString = (text: string): string | undefined => {
const emailRegex = /[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+/gim;
const email = text.match(emailRegex);
if (email) return email[0];
return undefined;
};
}

export interface BitbucketCommit {
Expand Down

0 comments on commit ec651b5

Please sign in to comment.