Skip to content
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 @@ -58,7 +58,7 @@
value = Convert.ToString(target.Fields[Config.sourceField]?.Value);
break;
default:
throw new ArgumentOutOfRangeException();

Check warning on line 61 in src/MigrationTools.Clients.TfsObjectModel/Tools/FieldMappingTool/FieldMaps/FieldToFieldMap.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Use a constructor overloads that allows a more meaningful exception message to be provided. (https://rules.sonarsource.com/csharp/RSPEC-3928)
}

if (string.IsNullOrEmpty(value) && Config.defaultValue is not null)
Expand All @@ -66,9 +66,17 @@
value = Config.defaultValue;
}

target.Fields[Config.targetField].Value = value;
Log.LogDebug("FieldToFieldMap: [UPDATE] Successfully mapped field {SourceField} to {TargetField} with value '{Value}' using mode {FieldMapMode} | Source WorkItem: {SourceId} -> Target WorkItem: {TargetId}",
Config.sourceField, Config.targetField, value, Config.fieldMapMode, source.Id, target.Id);
if (!string.IsNullOrEmpty(value))
{
target.Fields[Config.targetField].Value = value;
Log.LogDebug("FieldToFieldMap: [UPDATE] Successfully mapped field {SourceField} to {TargetField} with value '{Value}' using mode {FieldMapMode} | Source WorkItem: {SourceId} -> Target WorkItem: {TargetId}",
Config.sourceField, Config.targetField, value, Config.fieldMapMode, source.Id, target.Id);
}
else
{
Log.LogDebug("FieldToFieldMap: [SKIPPED] Proposed value is empty {SourceField} to {TargetField} with value '{Value}' using mode {FieldMapMode} | Source WorkItem: {SourceId} -> Target WorkItem: {TargetId}",
Config.sourceField, Config.targetField, value, Config.fieldMapMode, source.Id, target.Id);
}
}

private bool IsValid(WorkItem source, WorkItem target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
* from https://gist.github.com/pietergheysens/792ed505f09557e77ddfc1b83531e4fb
*/

protected override void FixEmbededImages(WorkItemData wi, string oldTfsurl, string newTfsurl, string sourcePersonalAccessToken = "")

Check warning on line 75 in src/MigrationTools.Clients.TfsObjectModel/Tools/TfsEmbededImagesTool.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
Log.LogInformation("EmbededImagesRepairEnricher: Fixing HTML field attachments for work item {Id} from {OldTfsurl} to {NewTfsUrl}", wi.Id, oldTfsurl, newTfsurl);

Expand Down Expand Up @@ -150,6 +150,10 @@
}
else
{
// Provide more detailed error information for non-404 failures
Log.LogWarning("EmbededImagesRepairEnricher: Failed to download image {MatchValue} from WorkItem {WorkItemId}, Field {FieldName}. Status: {StatusCode} ({ReasonPhrase})",
matchedSourceUri, targetWorkItem.Id, sourceFieldName, (int)result.StatusCode, result.ReasonPhrase);

result.EnsureSuccessStatusCode();
}
}
Expand Down Expand Up @@ -258,7 +262,7 @@
if (fails.Count > 0)
{
Log.LogWarning("Dummy Work Item is not ready to save as it has some invalid fields. This may not result in an error. Enable LogLevel as 'Debug' in the config to see more.");
Log.LogDebug("--------------------------------------------------------------------------------------------------------------------");

Check warning on line 265 in src/MigrationTools.Clients.TfsObjectModel/Tools/TfsEmbededImagesTool.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Define a constant instead of using this literal '--------------------------------------------------------------------------------------------------------------------' 4 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
Log.LogDebug("--------------------------------------------------------------------------------------------------------------------");
foreach (Field f in fails)
{
Expand All @@ -279,7 +283,7 @@
else
{
Log.LogDebug("TfsEmbededImagesTool: Dummy workitem {id} created on the target collection.", _targetDummyWorkItem.Id);
//_targetProject.Store.DestroyWorkItems(new List<int> { _targetDummyWorkItem.Id });

Check warning on line 286 in src/MigrationTools.Clients.TfsObjectModel/Tools/TfsEmbededImagesTool.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125)
}
}
_DummyWorkItemCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
protected readonly HttpClientHandler _httpClientHandler;
protected bool _ignore404Errors = true;

protected EmbededImagesRepairToolBase(IOptions<ToolOptions> options, IServiceProvider services, ILogger<ITool> logger, ITelemetryLogger telemetry) : base(options, services, logger, telemetry)

Check warning on line 19 in src/MigrationTools/Tools/Infrastructure/EmbededImagesRepairEnricherBase.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Update this logger to use its enclosing type. (https://rules.sonarsource.com/csharp/RSPEC-6672)

Check warning on line 19 in src/MigrationTools/Tools/Infrastructure/EmbededImagesRepairEnricherBase.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Update this logger to use its enclosing type. (https://rules.sonarsource.com/csharp/RSPEC-6672)
{
_httpClientHandler = new HttpClientHandler { AllowAutoRedirect = false, UseDefaultCredentials = true, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate };
_httpClientHandler = new HttpClientHandler { AllowAutoRedirect = true, UseDefaultCredentials = true, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate };
}

/**
Expand All @@ -41,6 +41,13 @@
}
}
}
else
{
// Log details about non-success responses for debugging
var logger = Microsoft.Extensions.Logging.LoggerFactory.Create(builder => builder.AddConsole()).CreateLogger("EmbededImagesRepairEnricher");
logger.LogDebug("DownloadFile failed for URL {Url}. Status: {StatusCode} ({ReasonPhrase}). Location header: {LocationHeader}",
url, (int)response.StatusCode, response.ReasonPhrase, response.Headers.Location?.ToString() ?? "None");
}

return response;
}
Expand Down Expand Up @@ -98,7 +105,7 @@
return ImageFormat.unknown;
}

protected string GetUrlWithOppositeSchema(string url)

Check warning on line 108 in src/MigrationTools/Tools/Infrastructure/EmbededImagesRepairEnricherBase.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Make 'GetUrlWithOppositeSchema' a static method. (https://rules.sonarsource.com/csharp/RSPEC-2325)

Check warning on line 108 in src/MigrationTools/Tools/Infrastructure/EmbededImagesRepairEnricherBase.cs

View workflow job for this annotation

GitHub Actions / Build, Test, Sonar Cloud Analysis, & Package

Make 'GetUrlWithOppositeSchema' a static method. (https://rules.sonarsource.com/csharp/RSPEC-2325)
{
string oppositeUrl;
var sourceUrl = new Uri(url);
Expand Down Expand Up @@ -126,4 +133,4 @@
jpeg
}
}
}
}
Loading