private async Task PopulateCounters(BuildResultEntity result) { await _buildCounterUtil.UpdateAsync(x => { var succeeded = result.ClassificationKind == ClassificationKind.Succeeded; if (JobUtil.IsPullRequestJobName(result.JobName)) { if (succeeded) { x.PullRequestSucceededCount++; } else { x.PullRequestFailedCount++; } } else { if (succeeded) { x.CommitSucceededCount++; } else { x.CommitFailedCount++; } } }); }
/// <summary> /// Is this build alreadiy fully populated. /// </summary> public async Task <bool> IsPopulated(BuildId buildId, CancellationToken cancellationToken = default(CancellationToken)) { var key = BuildResultEntity.GetExactEntityKey(buildId); var entity = await AzureUtil.QueryAsync <DynamicTableEntity>(_buildResultExactTable, key, cancellationToken); return(entity != null); }
public BuildResultEntity CopyExact() { var entity = new BuildResultEntity(this); entity.SetEntityKey(GetExactEntityKey(BuildId)); return(entity); }
public BuildResultEntity CopyDate() { var entity = new BuildResultEntity(this); entity.SetEntityKey(GetDateEntityKey(BuildDateTimeOffset, BuildId)); return(entity); }
public BuildResultEntity(BuildResultEntity other) : this( buildId : other.BoundBuildId, buildDateTime : other.BuildDateTimeOffset, duration : other.Duration, jobKind : other.JobKind, machineName : other.MachineName, classification : other.Classification, prInfo : other.PullRequestInfo) { }
public void PullRequestInfo() { var buildId = Create("example.com", 42, JobId.ParseName("hello")); var buildDate = DateTimeOffset.UtcNow; var prInfo = new PullRequestInfo("bob", "dog", 42, "cat", "tree"); var entity = new BuildResultEntity( buildId, buildDate, TimeSpan.FromSeconds(1), "kind", "test", BuildResultClassification.Succeeded, prInfo: prInfo); Assert.True(entity.HasPullRequestInfo); Assert.Equal(entity.PullRequestInfo.Author, prInfo.Author); Assert.Equal(entity.PullRequestInfo.AuthorEmail, prInfo.AuthorEmail); Assert.Equal(entity.PullRequestInfo.Id, prInfo.Id); Assert.Equal(entity.PullRequestInfo.PullUrl, prInfo.PullUrl); Assert.Equal(entity.PullRequestSha1, prInfo.Sha1); }
public async Task PopulateBuildMissing(BoundBuildId buildId) { // The bulid is now deemed to be missing. Finish it off. var result = new BuildResultEntity( buildId, DateTimeOffset.UtcNow, TimeSpan.MinValue, JobKind.Normal, "", BuildResultClassification.Infrastructure, prInfo: null); // Deliberately using Insert here vs. InsertOrReplace. This is the worst possible outcome for this // type so let anyone else win await _buildResultDateTable.ExecuteAsync(TableOperation.Insert(result.CopyDate())); await _buildResultDateTable.ExecuteAsync(TableOperation.Insert(result.CopyExact())); await PopulateCounters(result); }
public void Properties() { var buildId = Create("example.com", 42, JobId.ParseName("hello")); var buildDate = DateTimeOffset.UtcNow; var entity = new BuildResultEntity( buildId, buildDate, TimeSpan.FromSeconds(1), "kind", "test", BuildResultClassification.Succeeded, prInfo: null); Assert.Equal(BuildResultClassification.Succeeded.Kind, entity.Classification.Kind); Assert.Equal(BuildResultClassification.Succeeded.Name, entity.Classification.Name); Assert.Equal(buildId, entity.BoundBuildId); Assert.Equal(buildId.Number, entity.BuildNumber); Assert.Equal(buildId.JobId, entity.JobId); Assert.Equal(buildDate, entity.BuildDateTimeOffset); Assert.Equal("test", entity.MachineName); Assert.False(entity.HasPullRequestInfo); Assert.Null(entity.PullRequestInfo); }
public void MissingHostName() { var jobId = JobId.ParseName("test"); var entity = new BuildResultEntity() { BuildNumber = 42, JobName = jobId.Name }; var buildId = entity.BoundBuildId; Assert.Equal(LegacyUtil.DefaultHost, buildId.Host); Assert.Equal(jobId, buildId.JobId); Assert.Equal(42, buildId.Number); }
public void ViewNameOther() { var buildId = Create("example.com", 42, JobId.ParseName("house/test")); var entity = new BuildResultEntity(buildId, DateTimeOffset.UtcNow, TimeSpan.FromSeconds(1), "kind", "test", BuildResultClassification.Succeeded, null); Assert.Equal("house", entity.ViewName); }
public BuildResultEntity CopyExact() { var entity = new BuildResultEntity(this); entity.SetEntityKey(GetExactEntityKey(BuildId)); return entity; }
/// <summary> /// Update the table storage to contain the result of the specified build. /// </summary> private async Task<PopulateData> GetPopulateDataCore(BoundBuildId id) { var buildInfo = await _client.GetBuildInfoAsync(id.BuildId); var jobKind = await _client.GetJobKindAsync(id.JobId); PullRequestInfo prInfo = null; if (JobUtil.IsPullRequestJobName(id.JobId.Name)) { try { prInfo = await _client.GetPullRequestInfoAsync(id.BuildId); } catch (Exception ex) { // TODO: Flow builds don't have the PR directly in the triggered jobs. Have to walk // back up to the parent job. For now swallow this error so we don't trigger false // positives in the error detection. _textWriter.WriteLine($"Error pulling PR info for {id}: {ex.Message}"); } } BuildResultClassification classification; switch (buildInfo.State) { case BuildState.Succeeded: classification = BuildResultClassification.Succeeded; break; case BuildState.Aborted: classification = BuildResultClassification.Aborted; break; case BuildState.Failed: classification = await PopulateFailedBuildResult(buildInfo, jobKind, prInfo); break; case BuildState.Running: classification = BuildResultClassification.Unknown; break; default: throw new Exception($"Invalid enum: {buildInfo.State} for {id.JobName} - {id.Number}"); } var resultEntity = new BuildResultEntity( id, buildInfo.Date, buildInfo.Duration, jobKind: jobKind, machineName: buildInfo.MachineName, classification: classification, prInfo: prInfo); var failures = classification.Kind == ClassificationKind.TestFailure ? await GetUnitTestFailures(buildInfo, jobKind, prInfo) : new List<BuildFailureEntity>(); return new PopulateData(resultEntity, failures); }
public BuildResultEntity(BuildResultEntity other) : this( buildId: other.BoundBuildId, buildDateTime: other.BuildDateTimeOffset, duration: other.Duration, jobKind: other.JobKind, machineName: other.MachineName, classification: other.Classification, prInfo: other.PullRequestInfo) { }
/// <summary> /// Update the table storage to contain the result of the specified build. /// </summary> private async Task <PopulateData> GetPopulateDataCore(BoundBuildId id) { var buildInfo = await _client.GetBuildInfoAsync(id.BuildId); var jobKind = await _client.GetJobKindAsync(id.JobId); PullRequestInfo prInfo = null; if (JobUtil.IsPullRequestJobName(id.JobId.Name)) { try { prInfo = await _client.GetPullRequestInfoAsync(id.BuildId); } catch (Exception ex) { // TODO: Flow builds don't have the PR directly in the triggered jobs. Have to walk // back up to the parent job. For now swallow this error so we don't trigger false // positives in the error detection. _textWriter.WriteLine($"Error pulling PR info for {id}: {ex.Message}"); } } BuildResultClassification classification; switch (buildInfo.State) { case BuildState.Succeeded: classification = BuildResultClassification.Succeeded; break; case BuildState.Aborted: classification = BuildResultClassification.Aborted; break; case BuildState.Failed: classification = await PopulateFailedBuildResult(buildInfo, jobKind, prInfo); break; case BuildState.Running: classification = BuildResultClassification.Unknown; break; default: throw new Exception($"Invalid enum: {buildInfo.State} for {id.JobName} - {id.Number}"); } var resultEntity = new BuildResultEntity( id, buildInfo.Date, buildInfo.Duration, jobKind: jobKind, machineName: buildInfo.MachineName, classification: classification, prInfo: prInfo); var failures = classification.Kind == ClassificationKind.TestFailure ? await GetUnitTestFailures(buildInfo, jobKind, prInfo) : new List <BuildFailureEntity>(); return(new PopulateData(resultEntity, failures)); }
internal PopulateData(BuildResultEntity result, List <BuildFailureEntity> failures) { Result = result; Failures = failures; }
internal PopulateData(BuildResultEntity result, List<BuildFailureEntity> failures) { Result = result; Failures = failures; }
public BuildResultEntity CopyDate() { var entity = new BuildResultEntity(this); entity.SetEntityKey(GetDateEntityKey(BuildDateTimeOffset, BuildId)); return entity; }