Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Services/EnvUpdaterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ public Task<List<string>> UpdateEnvFile(List<string> localEnvVars, List<string>
result.Add($"\n\n{marker}\n\n");
}

var seenCommentLines = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);

foreach (string repoVar in repoEnvVars)
{
try
Expand Down Expand Up @@ -250,6 +252,26 @@ public Task<List<string>> UpdateEnvFile(List<string> localEnvVars, List<string>
if (!isVarInLocalEnv)
{
_logger.LogDebug($"Adding missing environment variable '{repoVar}' to the local .env file.");

foreach (string comment in commentsFromRepo)
{
string trimmed = comment.TrimEnd();
if (!seenCommentLines.Add(trimmed))
{
int commentIndex = result.FindIndex(x => string.Equals(x.Trim(), comment.Trim()));
if(commentIndex >= 0)
{
_logger.LogDebug($"Removing {result[commentIndex]} as it is a duplicate");
result.RemoveAt(commentIndex);
}
}
}

if (repoLine.TrimStart().StartsWith('#'))
{
seenCommentLines.Add(repoLine);
}

result.AddRange(commentsFromRepo);
result.Add(repoLine + "\n");
}
Expand Down Expand Up @@ -299,6 +321,7 @@ public Task<List<string>> UpdateEnvFile(List<string> localEnvVars, List<string>
_logger.LogError($"An error occurred while trying to update the local .env file with the variable '{repoVar}'. Exception: {ex.Message}");
}
}

return Task.FromResult(result);
}
}
Expand Down
Loading