From 771d246a96cd476fa9fddf600c532a28b2efd93a Mon Sep 17 00:00:00 2001 From: to-s Date: Mon, 19 Oct 2020 12:38:51 -0400 Subject: Substitute author and email by git config (#186) * Substitute author and email by git config * Upgraded version of typescript Due to https://github.com/cschlosser/doxdocgen/pull/186#discussion_r505813068 * Moved to CppDocGen.generateAuthorTag() Due to https://github.com/cschlosser/doxdocgen/pull/186#discussion_r505819542 * Update README.md Due to https://github.com/cschlosser/doxdocgen/pull/186#discussion_r505822908 * Update TestSetup.ts * Added tests * Changed return type to string Due to https://ci.appveyor.com/project/cschlosser/doxdocgen/builds/35818180#L566 Co-authored-by: Christoph Schlosser <2466365+cschlosser@users.noreply.github.com> --- src/Lang/Cpp/CppDocGen.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/Lang/Cpp/CppDocGen.ts') diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts index 2795ec6..bc9f09a 100644 --- a/src/Lang/Cpp/CppDocGen.ts +++ b/src/Lang/Cpp/CppDocGen.ts @@ -3,6 +3,7 @@ import * as moment from "moment"; import { Position, Range, Selection, TextEditor } from "vscode"; import { IDocGen } from "../../Common/IDocGen"; import { Config } from "../../Config"; +import GitConfig from "../../GitConfig"; import { CppArgument } from "./CppArgument"; import * as CppParser from "./CppParser"; import { CppToken, CppTokenType } from "./CppToken"; @@ -47,6 +48,8 @@ export class CppDocGen implements IDocGen { protected vscodeAutoGeneratedComment: boolean; + private gitConfig; + /** * @param {TextEditor} actEdit Active editor window * @param {Position} cursorPosition Where the cursor of the user currently is @@ -84,8 +87,9 @@ export class CppDocGen implements IDocGen { /** * @inheritdoc */ - public GenerateDoc(rangeToReplace: Range) { + public GenerateDoc(rangeToReplace: Range, gitConfig: GitConfig) { let comment: string = ""; + this.gitConfig = gitConfig; if (this.commentType === CommentType.file) { comment = this.generateFileDescription(); } else if (this.commentType === CommentType.method) { @@ -291,13 +295,26 @@ export class CppDocGen implements IDocGen { } protected generateAuthorTag(lines: string[]) { + let authorName: string = this.cfg.Generic.authorName; + let authorEmail: string = this.cfg.Generic.authorEmail; + + // Check if set to use the git username + if (this.cfg.Generic.useGitUserName === true) { + authorName = this.gitConfig.UserName; + } + + // Check if set to use the git email + if (this.cfg.Generic.useGitUserEmail === true) { + authorEmail = this.gitConfig.UserEmail; + } + if (this.cfg.Generic.authorTag.trim().length !== 0) { // Allow substitution of {author} and {email} only lines.push( ...this.getMultiTemplatedString( [this.cfg.authorTemplateReplace, this.cfg.emailTemplateReplace], this.cfg.Generic.authorTag, - [this.cfg.Generic.authorName, this.cfg.Generic.authorEmail], + [authorName, authorEmail], ).split("\n"), ); } -- cgit v1.2.3