Add a helper function for checking if an email is attributable

This commit is contained in:
Markus Olsson 2022-02-15 11:56:47 +01:00
parent ab48d526da
commit 382eab0ddd

View file

@ -2,6 +2,7 @@ import * as URL from 'url'
import { IAPIEmail, getDotComAPIEndpoint } from './api'
import { Account } from '../models/account'
import { caseInsensitiveEquals } from './compare'
/**
* Lookup a suitable email address to display in the application, based on the
@ -123,3 +124,14 @@ export function getAttributableEmailsFor(
return [...uniqueEmails]
}
/**
* Gets a value indicating whether a commit email matching the given email
* would get attributed to the account (i.e. user) if pushed to the endpoint
* that said account belongs to.
*
* See getAttributableEmailsFor for more information on what emails are
* considered attributable.
*/
export const isAttributableEmailFor = (account: Account, email: string) =>
getAttributableEmailsFor(account).some(x => caseInsensitiveEquals(x, email))