}
/**
* Class representing the Author of a change
* TODO: Handle multiple authors
*/
export class PijulChangeAuthor {
public readonly name: string;
public readonly fullName?: string;
public readonly email?: string;
/**
* Creates a new PijulChangeAuthor by parsing the Author string in the change
* @param authorString The full author string, in the format `[Author { name: "GarettWithOneR", full_name: Some("Garett Cooper"), email: Some("garett@garettcooper.com") }]`
*/
constructor (authorString: string) {
const parsePattern = /Author\s\{\sname:\s"([^"]*)",\sfull_name:\s(?:Some\("([^"]*)"\)|(None)),\semail:\s(?:Some\("([^"]*)"\)|(None))\s\}/g;
const match = parsePattern.exec(authorString);
if (match != null) {
// The 4th match needs to be skipped, as it is the (None) capture group
[, this.name, this.fullName,, this.email] = match;
if (this.fullName === 'None') {
this.fullName = undefined;
}
if (this.email === 'None') {
this.fullName = undefined;
}
} else {
throw new Error('Failed to parse author string: ' + authorString);
}
}