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

Code before:
                    Operation = VisualStudio.Services.WebApi.Patch.Operation.Add,
                    Path = "/fields/System.Tags",
                    Value = "Onefuzz"
                });
            }

            foreach (var field in _config.AdoFields.Keys) {
                var value = await Render(_config.AdoFields[field]);

                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((string, string)[] notificationInfo) {
            var matchingItems = ExistingWorkItems(notificationInfo)
                .Select(wi => new { IsDuplicate = !IsADODuplicateWorkItem(wi), wi });

            var updated = false;
            WorkItem? oldest = null;
            await foreach (var workItem in matchingItems) {
                oldest ??= workItem.wi;

                _logTracer.WithTags(new List<(string, string)> { ("MatchingWorkItemIds", $"{workItem.wi.Id}") }).Info($"Found matching work item");
                if (workItem.IsDuplicate) {

                    continue;
                }
                _logTracer.WithTags(new List<(string, string)> { ("NonDuplicateWorkItemId", $"{workItem.wi.Id}") }).Info($"Found matching non-duplicate work item");
                _ = await UpdateExisting(workItem.wi, notificationInfo);
                updated = true;
            }

            if (!updated) {
                if (oldest != null) {
                    // We have matching work items but all are duplicates
                    _logTracer.WithTags(notificationInfo)
                        .Info($"All matching work items were duplicates, re-opening the oldest one");
                    var oldestWorkItem = oldest;
                    var stateChanged = await UpdateExisting(oldestWorkItem, notificationInfo);
                    if (stateChanged) {
                        // add a comment if we re-opened the bug

Review comment (refactor):
```suggestion
                .Select(wi => new { IsDuplicate = IsADODuplicateWorkItem(wi), wi });
```

Code after:
            var taskType = await Render(_config.Type);
            var document = new JsonPatchDocument();
            if (!_config.AdoFields.ContainsKey("System.Tags")) {
                document.Add(new JsonPatchOperation() {
                    Operation = VisualStudio.Services.WebApi.Patch.Operation.Add,
                    Path = "/fields/System.Tags",
                    Value = "Onefuzz"
                });
            }

            foreach (var field in _config.AdoFields.Keys) {
                var value = await Render(_config.AdoFields[field]);

                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((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;
                _logTracer.WithTags(new List<(string, string)> { ("MatchingWorkItemIds", $"{workItem.Id}") }).Info($"Found matching work item");
                if (IsADODuplicateWorkItem(workItem)) {
                    continue;
                }
                _logTracer.WithTags(new List<(string, string)> { ("NonDuplicateWorkItemId", $"{workItem.Id}") }).Info($"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.WithTags(notificationInfo)
                        .Info($"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(