Skip to content

Commit

Permalink
Merge pull request #1074 from solidify/bugfix/handle-case-where-full-…
Browse files Browse the repository at this point in the history
…sprint-object-is-returned-from-jira-api

MapSprint(): Handle case where the full Sprint object is returned from the Fields API
  • Loading branch information
Alexander-Hjelm authored Dec 3, 2024
2 parents eef6496 + 0899996 commit 55cd028
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/WorkItemMigrator/JiraExport/RevisionUtils/FieldMapperUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,24 @@ public static object MapSprint(string iterationPathsString)
if (string.IsNullOrWhiteSpace(iterationPathsString))
return null;

// For certain configurations of Jira, the entire Sprint object is returned by the
// fields Rest API instead of the Sprint name
if (iterationPathsString.StartsWith("com.atlassian.greenhopper.service.sprint.Sprint@"))
{
Regex regex = new Regex(@",name=([^,]+),");
Match match = regex.Match(iterationPathsString);
if (match.Success)
{
iterationPathsString = match.Groups[1].Value;
}
else
{
Logger.Log(LogLevel.Error, "Missing 'name' property for Sprint object. "
+ $"Skipping mapping this sprint. The full object was: '{iterationPathsString}'."
);
}
}

var iterationPaths = iterationPathsString.Split(',').AsEnumerable();
iterationPaths = iterationPaths.Select(ip => ip.Trim());
var iterationPath = iterationPaths.Last();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ public void When_calling_map_sprint_with_invalid_azdo_chars_Then_expected_output
Assert.AreEqual(expected, output);
}

[Test]
public void When_calling_map_sprint_with_full_sprint_object_as_str_Then_expected_output_is_returned()
{
string sprintPath = "com.atlassian.greenhopper.service.sprint.Sprint@7c6e1967[id=442906,rapidViewId"
+ "=187524,state=ACTIVE,name=LMS 2024_05,startDate=2024-10-14T00:00:00.000Z,endDate=2024-11-01T"
+ "23:00:00.000Z,completeDate=<null>,activatedDate=2024-10-13T18:14:54.334Z,sequence=449386,goa"
+ "l=,synced=false,autoStartStop=false,incompleteIssuesDestinationId=<null>]";
string expectedOutput = "LMS 2024_05";
object output = FieldMapperUtils.MapSprint(sprintPath);
Assert.AreEqual(expectedOutput, output);
}

[Test]
public void When_calling_map_value_with_valid_args_Then_expected_output_is_returned()
{
Expand Down

0 comments on commit 55cd028

Please sign in to comment.