private async Task FetchAndSaveComment(Func<TfsJsonBuild, Task<string>> getCommentFunc, TfsJsonBuild tfsJsonBuild) { var buildDefinitionId = tfsJsonBuild.Definition.Id; var buildId = tfsJsonBuild.Id; var comment = await getCommentFunc(tfsJsonBuild); _commentsCache[buildDefinitionId] = new Tuple<int, string>(buildId, comment); }
public TfsRestBuildStatus(TfsJsonBuild tfsRestBuildDefinition, CommentsCache commentsCache) { BuildStatusEnum = GetBuildStatus(tfsRestBuildDefinition); Name = tfsRestBuildDefinition.Definition.Name; BuildDefinitionId = tfsRestBuildDefinition.Definition.Id.ToString(); RequestedBy = tfsRestBuildDefinition.RequestedFor.DisplayName; BuildId = tfsRestBuildDefinition.Id.ToString(); Url = tfsRestBuildDefinition._links.Web.Href; Comment = commentsCache.GetCachedCommentForBuild(tfsRestBuildDefinition); }
private async Task<string> GetComment(TfsJsonBuild tfsJsonBuild, TfsConnectionDetails connection, string projectCollection) { var message = await GetCommentOnce(tfsJsonBuild, connection, projectCollection); if (tfsJsonBuild.Definition.Type == "xaml" && message == null) { // old style xaml builds don't get associated with a commit immediately for some annoying reason, so keep trying for 2 minutes const int maxRetries = 12; for (int i = 0; i < maxRetries && message == null; i++) { _log.Debug("Comment was null for a xaml build definition, so delaying and checking for a comment again in 10 seconds"); await Task.Delay(10000); message = await GetCommentOnce(tfsJsonBuild, connection, projectCollection); } } return message?.Trim(); }
private static BuildStatusEnum GetBuildStatus(TfsJsonBuild tfsRestBuildDefinition) { if (tfsRestBuildDefinition.Status == "inProgress") return BuildStatusEnum.InProgress; BuildStatusEnum buildStatusEnum; return _buildStatusMapping.TryGetValue(tfsRestBuildDefinition.Result, out buildStatusEnum) ? buildStatusEnum : BuildStatusEnum.Unknown; }
public string GetCachedCommentForBuild(TfsJsonBuild build) { var buildDefinition = build.Definition.Id; var cachedCommentForBuild = _commentsCache[buildDefinition]; return cachedCommentForBuild.Item2; }
private async Task<string> GetCommentOnce(TfsJsonBuild tfsJsonBuild, TfsConnectionDetails connection, string projectCollection) { var comments = await _tfsJsonService.GetComments(tfsJsonBuild, connection, projectCollection); var firstComment = comments.FirstOrDefault(); var message = firstComment?.Message; return message; }