Skip to content

Instantly share code, notes, and snippets.

@robdmoore
Created August 12, 2013 02:48
Show Gist options
  • Save robdmoore/6207947 to your computer and use it in GitHub Desktop.
Save robdmoore/6207947 to your computer and use it in GitHub Desktop.
Linqpad script to quickly parse trello story map board
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\System.Collections.dll</Reference>
<Reference>&lt;RuntimeDirectory&gt;\System.Linq.dll</Reference>
<NuGetReference>Newtonsoft.Json</NuGetReference>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Bson</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
</Query>
void Main()
{
var content = File.ReadAllText(@"c:\users\robert\desktop\export-from-trello.json");
var parsed = JsonConvert.DeserializeObject<TrelloBoard>(content);
var regex = new Regex(@"\(((.+?)\) )?(.+)");
var joined = parsed.cards
.Where(c => !c.closed)
.Join(parsed.lists, c => c.idList, l => l.id, (c, l) => new {List = l.name, Story = c.name, StoryId = c.id})
.GroupJoin(parsed.checklists, c => c.StoryId, cl => cl.idCard, (c, cl) =>
new {
List = c.List,
Story = c.Story,
Assumptions = string.Join(", ",
(cl.SingleOrDefault(l => l.name == "Assumptions") ?? new TrelloChecklist(){checkItems = Enumerable.Empty<TrelloCheckListItem>()})
.checkItems.Select(i => i.name)
)
}
)
.Select(
c => new {c.List, Story = regex.Match(c.Story).Groups[3].Value, Estimate = regex.Match(c.Story).Groups[2].Value, c.Assumptions}
);
joined.Dump();
}
public class TrelloBoard {
public IEnumerable<TrelloList> lists { get; set; }
public IEnumerable<TrelloCard> cards { get; set; }
public IEnumerable<TrelloChecklist> checklists { get; set; }
}
public class TrelloList {
public string id { get; set; }
public string name { get; set; }
}
public class TrelloCard {
public string id { get; set; }
public string name { get; set; }
public string idList { get; set; }
public bool closed { get; set; }
}
public class TrelloChecklist {
public string name { get; set; }
public string idCard { get; set; }
public IEnumerable<TrelloCheckListItem> checkItems { get; set; }
}
public class TrelloCheckListItem {
public string name { get; set; }
}
// Define other methods and classes here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment