Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AreAPICodeFilesTheSame #8641

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public override async Task<CodeFile> GetCodeFileAsync(string originalName, Strea
var tempDirectory = Path.Combine(tempPath, "ApiView", randomSegment);
Directory.CreateDirectory(tempDirectory);
originalName = Path.GetFileName(originalName);
// Replace spaces and parentheses in the file name to remove invalid file name in cosmos DB.
// temporary work around. We need to make sure FileName is set for all requests.
originalName = originalName.Replace(" ", "_").Replace("(", "").Replace(")","");
var originalFilePath = Path.Combine(tempDirectory, originalName);

var jsonFilePath = (LanguageServiceHelpers.UseTreeStyleParser(this.Name)) ? Path.ChangeExtension(originalFilePath, ".json.tgz") : Path.ChangeExtension(originalFilePath, ".json");
Expand Down
5 changes: 5 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Managers/CodeFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ public async Task<APICodeFileModel> CreateReviewCodeFileModel(string apiRevision
/// <returns></returns>
public async Task<bool> AreAPICodeFilesTheSame(RenderedCodeFile codeFileA, RenderedCodeFile codeFileB)
{
if (codeFileA.CodeFile.VersionString != codeFileA.CodeFile.VersionString)
praveenkuttappan marked this conversation as resolved.
Show resolved Hide resolved
{
return false;
}

if (LanguageServiceHelpers.UseTreeStyleParser(codeFileA.CodeFile.Language))
{
var diffTree =CodeFileHelpers.ComputeAPIForestDiff(codeFileA.CodeFile.APIForest, codeFileB.CodeFile.APIForest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,18 @@ public async Task<RenderedCodeFile> GetCodeFileAsync(string revisionId, string c

var info = await client.DownloadAsync();

codeFile = new RenderedCodeFile(await CodeFile.DeserializeAsync(info.Value.Content, doTreeStyleParserDeserialization: LanguageServiceHelpers.UseTreeStyleParser(language)));
CodeFile deserializedCodeFile = null;
// Try to deserialize the code file twice, as the first time might fail due to the file being not yet updated to new tree token format.
// This is a temporary work around. We should have a property in Cosmos revision to indicate whether a token is using new format or old format.
try
{
deserializedCodeFile = await CodeFile.DeserializeAsync(info.Value.Content, doTreeStyleParserDeserialization: LanguageServiceHelpers.UseTreeStyleParser(language));
}
catch
{
deserializedCodeFile = await CodeFile.DeserializeAsync(info.Value.Content, doTreeStyleParserDeserialization: false);
}
codeFile = new RenderedCodeFile(deserializedCodeFile);

if (updateCache)
{
Expand Down