|
|
@ -9,6 +9,11 @@ export const defaultRelativeDateLength = 13; |
|
|
|
export const defaultAuthorLength = 16; |
|
|
|
export const defaultMessageLength = 32; |
|
|
|
|
|
|
|
export const cssEllipse = '\\2026'; |
|
|
|
export const cssIndent = '\\02759'; |
|
|
|
export const cssSeparator = '\\2022'; |
|
|
|
export const cssSpace = '\\00a0'; |
|
|
|
|
|
|
|
export enum BlameAnnotationFormat { |
|
|
|
Constrained, |
|
|
|
Unconstrained |
|
|
@ -18,16 +23,15 @@ export default class BlameAnnotationFormatter { |
|
|
|
|
|
|
|
static getAnnotation(config: IBlameConfig, commit: GitCommit, format: BlameAnnotationFormat) { |
|
|
|
const sha = commit.sha.substring(0, defaultShaLength); |
|
|
|
const message = this.getMessage(config, commit, format === BlameAnnotationFormat.Unconstrained ? 0 : defaultMessageLength); |
|
|
|
let message = this.getMessage(config, commit, format === BlameAnnotationFormat.Unconstrained ? 0 : defaultMessageLength); |
|
|
|
|
|
|
|
if (format === BlameAnnotationFormat.Unconstrained) { |
|
|
|
const authorAndDate = this.getAuthorAndDate(config, commit, 'MMMM Do, YYYY h:MMa'); |
|
|
|
if (config.annotation.sha) { |
|
|
|
return `${sha}${(authorAndDate ? `\\00a0\\2022\\00a0 ${authorAndDate}` : '')}${(message ? `\\00a0\\2022\\00a0 ${message}` : '')}`; |
|
|
|
message = `${sha}${(authorAndDate ? ` ${cssSeparator} ${authorAndDate}` : '')}${(message ? ` ${cssSeparator} ${message}` : '')}`; |
|
|
|
} |
|
|
|
|
|
|
|
if (config.annotation.author || config.annotation.date) { |
|
|
|
return `${authorAndDate}${(message ? `\\00a0\\2022\\00a0 ${message}` : '')}`; |
|
|
|
else if (config.annotation.author || config.annotation.date) { |
|
|
|
message = `${authorAndDate}${(message ? ` ${cssSeparator} ${message}` : '')}`; |
|
|
|
} |
|
|
|
|
|
|
|
return message; |
|
|
@ -36,15 +40,13 @@ export default class BlameAnnotationFormatter { |
|
|
|
const author = this.getAuthor(config, commit, defaultAuthorLength); |
|
|
|
const date = this.getDate(config, commit, 'MM/DD/YYYY', true); |
|
|
|
if (config.annotation.sha) { |
|
|
|
return `${sha}${(author ? `\\00a0\\2022\\00a0 ${author}` : '')}${(date ? `\\00a0\\2022\\00a0 ${date}` : '')}${(message ? `\\00a0\\2022\\00a0 ${message}` : '')}`; |
|
|
|
message = `${sha}${(author ? ` ${cssSeparator} ${author}` : '')}${(date ? ` ${cssSeparator} ${date}` : '')}${(message ? ` ${cssSeparator} ${message}` : '')}`; |
|
|
|
} |
|
|
|
|
|
|
|
if (config.annotation.author) { |
|
|
|
return `${author}${(date ? `\\00a0\\2022\\00a0 ${date}` : '')}${(message ? `\\00a0\\2022\\00a0 ${message}` : '')}`; |
|
|
|
else if (config.annotation.author) { |
|
|
|
message = `${author}${(date ? ` ${cssSeparator} ${date}` : '')}${(message ? ` ${cssSeparator} ${message}` : '')}`; |
|
|
|
} |
|
|
|
|
|
|
|
if (config.annotation.date) { |
|
|
|
return `${date}${(message ? `\\00a0\\2022\\00a0 ${message}` : '')}`; |
|
|
|
else if (config.annotation.date) { |
|
|
|
message = `${date}${(message ? ` ${cssSeparator} ${message}` : '')}`; |
|
|
|
} |
|
|
|
|
|
|
|
return message; |
|
|
@ -80,10 +82,10 @@ export default class BlameAnnotationFormatter { |
|
|
|
if (!truncateTo) return author; |
|
|
|
|
|
|
|
if (author.length > truncateTo) { |
|
|
|
return `${author.substring(0, truncateTo - 1)}\\2026`; |
|
|
|
return `${author.substring(0, truncateTo - cssEllipse.length)}${cssEllipse}`; |
|
|
|
} |
|
|
|
|
|
|
|
return author + '\\00a0'.repeat(truncateTo - author.length); |
|
|
|
return author + `${cssSpace}`.repeat(truncateTo - author.length); |
|
|
|
} |
|
|
|
|
|
|
|
static getDate(config: IBlameConfig, commit: GitCommit, format?: string, truncate: boolean = false, force: boolean = false) { |
|
|
@ -96,10 +98,10 @@ export default class BlameAnnotationFormatter { |
|
|
|
|
|
|
|
const truncateTo = config.annotation.date === 'relative' ? defaultRelativeDateLength : defaultAbsoluteDateLength; |
|
|
|
if (date.length > truncateTo) { |
|
|
|
return `${date.substring(0, truncateTo - 1)}\\2026`; |
|
|
|
return `${date.substring(0, truncateTo - cssEllipse.length)}${cssEllipse}`; |
|
|
|
} |
|
|
|
|
|
|
|
return date + '\\00a0'.repeat(truncateTo - date.length); |
|
|
|
return date + `${cssSpace}`.repeat(truncateTo - date.length); |
|
|
|
} |
|
|
|
|
|
|
|
static getMessage(config: IBlameConfig, commit: GitCommit, truncateTo: number = 0, force: boolean = false) { |
|
|
@ -107,7 +109,7 @@ export default class BlameAnnotationFormatter { |
|
|
|
|
|
|
|
let message = commit.message; |
|
|
|
if (truncateTo && message.length > truncateTo) { |
|
|
|
return `${message.substring(0, truncateTo - 1)}\\2026`; |
|
|
|
return `${message.substring(0, truncateTo - cssEllipse.length)}${cssEllipse}`; |
|
|
|
} |
|
|
|
|
|
|
|
return message; |
|
|
|