1: public class WhoBrokeTheBuild : Microsoft.Build.Utilities.Task
2: { 3: private TeamFoundationServer _tfs;
4:
5: [Output]
6: public ITaskItem[] EmailAddresses { get; set; } 7:
8: [Required]
9: public string TeamFoundationServerURL { get; set; } 10:
11: [Required]
12: public string BuildUri { get; set; } 15:
17:
18: public WhoBrokeTheBuild() { } 19:
20: public override bool Execute()
21: { 22: _tfs = TFSCommon.GetTFS(TeamFoundationServerURL);
23: IBuildDetail buildDetail = GetBuildDetail();
24: List<string> changesetOwners = GetChangesetOwners(buildDetail);
25:
26: //Now we should take the changesetOwners and look up their email
27: //in the LDAP creating ITaskItem to populate EmailAddresses
28: //but this hasn't been done yet
29: throw new System.NotImplementedException();
30:
31:
32: }
33:
34: public IBuildDetail GetBuildDetail()
35: { 36: IBuildServer buildServer = (IBuildServer)_tfs.GetService(typeof(IBuildServer));
37: IBuildDetail buildDetail = buildServer.GetAllBuildDetails(new Uri(BuildUri));
38: return buildDetail;
39: }
40:
41: public List<string> GetChangesetOwners(IBuildDetail buildDetail)
42: { 43: List<string> changesetOwners = new List<string>();
44:
45: IBuildDefinition buildDefinition = buildDetail.BuildDefinition;
46: if (buildDefinition.LastGoodBuildUri != buildDefinition.LastBuildUri)
47: { 48: return changesetOwners;
49: }
50:
51: List<IChangesetSummary> assocChangesets = InformationNodeConverters.GetAssociatedChangesets(buildDetail);
52: foreach (IChangesetSummary csSum in assocChangesets)
53: { 54: if (!(changesetOwners.Contains(csSum.CheckedInBy)))
55: { 56: changesetOwners.Add(csSum.CheckedInBy);
57:
58: }
59: }
60:
61: return changesetOwners;
62: }
63:
64: }