-
-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Owner addressable via RFC 2822 standard
- Loading branch information
Showing
3 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
10 changes: 7 additions & 3 deletions
10
allure-generator/src/main/javascript/plugins/testresult-owner/OwnerView.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
{{#if owner}} | ||
<h3 class="pane__section-title">{{t 'testResult.owner.name'}}</h3> | ||
<div>{{owner}}</div> | ||
{{/if}} | ||
{{t 'testResult.owner.name'}}: | ||
{{#if owner.url}} | ||
<a href="{{owner.url}}">{{owner.displayName}}</a> | ||
{{else}} | ||
{{owner.displayName}} | ||
{{/if}} | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
allure-generator/src/main/javascript/utils/parseAddress.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const RFC2822_ADDRESS = /^(.*) <(.*)>$/; | ||
const LOOKS_LIKE_EMAIL = /^[^@]+@[^@]+$/; | ||
|
||
/** | ||
* Parse a potentially RFC 2822 address into a display name and an address. | ||
* | ||
* @param {string | null | undefined} maybeAddress | ||
* @returns {{ displayName: string, url?: string } | null | ||
*/ | ||
export default function parseAddress(maybeAddress) { | ||
if (!maybeAddress) { | ||
return null; | ||
} | ||
|
||
const match = maybeAddress.match(RFC2822_ADDRESS); | ||
if (match) { | ||
return { | ||
displayName: match[1], | ||
url: toHref(match[2]), | ||
}; | ||
} | ||
|
||
return { | ||
displayName: maybeAddress, | ||
url: toHref(maybeAddress), | ||
}; | ||
} | ||
|
||
/** | ||
* If the address is a valid URL, returns the URL. | ||
* If the address resembles an email address, returns a mailto: URL. | ||
* Otherwise, returns undefined. | ||
* | ||
* @param {string} address | ||
* @returns {string | undefined} | ||
*/ | ||
function toHref(address) { | ||
if (isValidURL(address)) { | ||
return address; | ||
} | ||
|
||
if (LOOKS_LIKE_EMAIL.test(address)) { | ||
return `mailto:${address}`; | ||
} | ||
} | ||
|
||
/** | ||
* If the address is a valid URL, returns the URL. | ||
* | ||
* @param {string} maybeURL | ||
* @returns {boolean} | ||
*/ | ||
function isValidURL(maybeURL) { | ||
try { | ||
new URL(maybeURL); | ||
return true; | ||
} catch (_error) { | ||
return false; | ||
} | ||
} |