-
-
Notifications
You must be signed in to change notification settings - Fork 248
Proposal for Update board column function #957
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
Draft
mammabear123
wants to merge
6
commits into
solidify:master
Choose a base branch
from
mammabear123:UpdateBoardColumn
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
45d18ed
Determine which is the last revision and signify this to ImportRevision.
mammabear123 241c8be
Add BoardColumnCollector and write BoardColumn into final revision.
mammabear123 3326c1e
Harden equals comparison against null RevisionReferences.
mammabear123 7b0e4df
Remove unused isFinalRevision parameter.
mammabear123 c857ed5
Merge branch 'solidify:master' into UpdateBoardColumn
mammabear123 b9861f2
Merge branch 'master' into UpdateBoardColumn
Alexander-Hjelm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
src/WorkItemMigrator/WorkItemImport/BoardColumnCollector.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Migration.WIContract; | ||
|
||
namespace WorkItemImport | ||
{ | ||
/// <summary> | ||
/// Implementations of this interface will track the value of a field over multiple revisions for each item. They can | ||
/// then be queried for the 'current' value of the field as per the latest revision they have seen the a field in. | ||
/// </summary> | ||
/// <typeparam name="T">The type used when storing and retrieving the field's value.</typeparam> | ||
public interface IFieldCollector<T> | ||
{ | ||
/// <summary> | ||
/// Collects the field values in a similar way to <see cref="CollectValues"/> but also tests <see cref="ExecutionPlan.ExecutionItem.IsFinal"/>. For non-final | ||
/// revisions, the collected fields are also removed from the Fields array. For final revisions, adds or updates | ||
/// the Field to contain the latest value of each collected field (whether collected from this revision or a previous one). | ||
/// Usually implemented as a combination of <see cref="GetCurrentValue"/> and <see cref="CollectValues"/> | ||
/// </summary> | ||
/// <param name="executionItem">The execution item containing the revision to process.</param> | ||
/// <remarks> It is acceptable for a revision to not contain a value for the field(s) of interest. </remarks> | ||
void ProcessFields(ExecutionPlan.ExecutionItem executionItem); | ||
|
||
/// <summary> | ||
/// Return the 'current' value collected for the field(s) as per the latest revision of the given work item (that specified a value for this field). | ||
/// </summary> | ||
/// <param name="workItemId"></param> | ||
/// <returns></returns> | ||
T GetCurrentValue(string workItemId); | ||
|
||
/// <summary> | ||
/// Collect field value(s) from the given revision, updating the internal collection with the latest value(s). | ||
/// The revision provided in each call is considered to overwrite value(s) collected during previous calls. | ||
/// This method does not modify the revision - unlike <see cref="ProcessFields"/>. | ||
/// </summary> | ||
/// <param name="revision">The work item revision to collect field value(s) from.</param> | ||
/// <remarks> It is acceptable for a revision to not contain a value for the field(s) of interest. </remarks> | ||
void CollectValues(WiRevision revision); | ||
} | ||
|
||
/// <summary> | ||
/// Collects System.BoardColumn values from each revision in order to provide the final value for the last revision. | ||
/// Expected usage is to call ProcessFields on each revision, which will cause BoardColumn to be removed from all revisions except | ||
/// the last, and the final value to be updated/inserted into the BoardColumn field of the final revision. | ||
/// </summary> | ||
public class BoardColumnCollector : IFieldCollector<string> | ||
{ | ||
private readonly Dictionary<string, string> _collection = new Dictionary<string, string>(); | ||
|
||
/// <inheritdoc/> | ||
public void CollectValues(WiRevision revision) | ||
{ | ||
var boardColumn = revision?.Fields?.FirstOrDefault(f => f.ReferenceName == WiFieldReference.BoardColumn)?.Value as string; | ||
if (!string.IsNullOrEmpty(boardColumn)) | ||
{ | ||
_collection[revision.ParentOriginId] = boardColumn; | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public string GetCurrentValue(string workItemId) | ||
{ | ||
return _collection.TryGetValue(workItemId, out var value) ? value : null; | ||
} | ||
|
||
/// <summary> | ||
/// Collects the BoardColumn value and removes the field. Except in the final revision the field is explicitly inserted with the latest value. | ||
/// </summary> | ||
/// <param name="executionItem">The execution item containing the revision to process.</param> | ||
/// <inheritdoc/> | ||
public void ProcessFields(ExecutionPlan.ExecutionItem executionItem) | ||
{ | ||
CollectValues(executionItem.Revision); | ||
if (executionItem.IsFinal) | ||
{ | ||
var boardColumnValue = GetCurrentValue(executionItem.OriginId); | ||
if (!string.IsNullOrWhiteSpace(boardColumnValue)) | ||
{ | ||
executionItem.Revision.Fields.RemoveAll(i => i.ReferenceName == WiFieldReference.BoardColumn); | ||
executionItem.Revision.Fields.Add(new WiField { ReferenceName = WiFieldReference.BoardColumn, Value = boardColumnValue }); | ||
} | ||
} | ||
else | ||
{ | ||
executionItem.Revision.Fields.RemoveAll(f => f.ReferenceName == WiFieldReference.BoardColumn); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.