Repository: microsoft/onefuzz
File: src/ApiService/ApiService/onefuzzlib/notifications/Ado.cs (C#)

Code before:
                if (string.Equals(field, "System.Tags")) {
                    value += ";Onefuzz";
                }

                document.Add(new JsonPatchOperation() {
                    Operation = VisualStudio.Services.WebApi.Patch.Operation.Add,
                    Path = $"/fields/{field}",
                    Value = value
                });
            }

            return (taskType, document);
        }

        public async Async.Task Process(IList<(string, string)> notificationInfo) {
            var updated = false;
            WorkItem? oldestWorkItem = null;
            await foreach (var workItem in ExistingWorkItems(notificationInfo)) {
                // work items are ordered by id, so the oldest one is the first one
                oldestWorkItem ??= workItem;
                using (_logTracer.BeginScope("Search matching work items")) {
                    _logTracer.AddTags(new List<(string, string)> { ("MatchingWorkItemIds", $"{workItem.Id}") });
                    _logTracer.LogInformation("Found matching work item");
                }
                if (IsADODuplicateWorkItem(workItem)) {
                    continue;
                }

                using (_logTracer.BeginScope("Non-duplicate work item")) {
                    _logTracer.AddTags(new List<(string, string)> { ("NonDuplicateWorkItemId", $"{workItem.Id}") });
                    _logTracer.LogInformation("Found matching non-duplicate work item");
                }

                _ = await UpdateExisting(workItem, notificationInfo);
                updated = true;
            }

            if (!updated) {
                if (oldestWorkItem != null) {
                    // We have matching work items but all are duplicates
                    _logTracer.AddTags(notificationInfo);
                    _logTracer.LogInformation($"All matching work items were duplicates, re-opening the oldest one");
                    var stateChanged = await UpdateExisting(oldestWorkItem, notificationInfo);
                    if (stateChanged) {
                        // add a comment if we re-opened the bug
                        _ = await _client.AddCommentAsync(
                            new CommentCreate() {
                                Text =
                                    "This work item was re-opened because OneFuzz could only find related work items that are marked as duplicate."
                            },
                            _project,

Review comment (refactor):
Continuing from earlier comment, we can pass `_config.AdoDuplicateFields` here and remove the `duplicateFields` argument.


Code after:

                if (string.Equals(field, "System.Tags")) {
                    value += ";Onefuzz";
                }

                document.Add(new JsonPatchOperation() {
                    Operation = VisualStudio.Services.WebApi.Patch.Operation.Add,
                    Path = $"/fields/{field}",
                    Value = value
                });
            }

            return (taskType, document);
        }

        public async Async.Task Process(IList<(string, string)> notificationInfo, Dictionary<string, string>? duplicateFields) {
            var updated = false;
            WorkItem? oldestWorkItem = null;
            await foreach (var workItem in ExistingWorkItems(notificationInfo)) {
                // work items are ordered by id, so the oldest one is the first one
                oldestWorkItem ??= workItem;
                using (_logTracer.BeginScope("Search matching work items")) {
                    _logTracer.AddTags(new List<(string, string)> { ("MatchingWorkItemIds", $"{workItem.Id}") });
                    _logTracer.LogInformation("Found matching work item");
                }
                if (IsADODuplicateWorkItem(workItem, duplicateFields)) {
                    continue;
                }

                using (_logTracer.BeginScope("Non-duplicate work item")) {
                    _logTracer.AddTags(new List<(string, string)> { ("NonDuplicateWorkItemId", $"{workItem.Id}") });
                    _logTracer.LogInformation("Found matching non-duplicate work item");
                }

                _ = await UpdateExisting(workItem, notificationInfo);
                updated = true;
            }

            if (!updated) {
                if (oldestWorkItem != null) {
                    // We have matching work items but all are duplicates
                    _logTracer.AddTags(notificationInfo);
                    _logTracer.LogInformation($"All matching work items were duplicates, re-opening the oldest one");
                    var stateChanged = await UpdateExisting(oldestWorkItem, notificationInfo);
                    if (stateChanged) {
                        // add a comment if we re-opened the bug
                        _ = await _client.AddCommentAsync(
                            new CommentCreate() {
                                Text =
                                    "This work item was re-opened because OneFuzz could only find related work items that are marked as duplicate."
                            },