From ec651b534298210ed9596319aa9414fec450601a Mon Sep 17 00:00:00 2001 From: Prokop Simek Date: Mon, 25 Nov 2019 15:32:44 +0100 Subject: [PATCH] fix: add email of an author --- .../bitbucket/BitbucketService.spec.ts | 1 - src/services/bitbucket/BitbucketService.ts | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/services/bitbucket/BitbucketService.spec.ts b/src/services/bitbucket/BitbucketService.spec.ts index 9b15efd0e..9fd4e6705 100644 --- a/src/services/bitbucket/BitbucketService.spec.ts +++ b/src/services/bitbucket/BitbucketService.spec.ts @@ -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', () => { diff --git a/src/services/bitbucket/BitbucketService.ts b/src/services/bitbucket/BitbucketService.ts index 82d6d87a0..ef30e6b3a 100644 --- a/src/services/bitbucket/BitbucketService.ts +++ b/src/services/bitbucket/BitbucketService.ts @@ -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 { @@ -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, @@ -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); @@ -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: { @@ -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 {