/// <summary>
        /// Simulates a notification to the source of the project job 
        /// that the job is complete.
        /// </summary>
        public Task NotifyAsync(
            string callbackHost,
            string callbackPath,
            string operationId,
            ProjectJobResult result)
        {
            Notified = true;
            CallbackHost = callbackHost;
            CallbackPath = callbackPath;
            OperationId = operationId;
            Result = result;

            return Task.CompletedTask;
        }
		/// <summary>
		/// Notifies the source of the project job that the job is complete.
		/// </summary>
		/// <param name="callbackHost">The callback host.</param>
		/// <param name="callbackPath">The callback path.</param>
		/// <param name="operationId">The operation ID (for logging purposes).</param>
		/// <param name="result">The result to post.</param>
		public async Task NotifyAsync(
			string callbackHost, 
			string callbackPath, 
			string operationId, 
			ProjectJobResult result)
		{
			var serializedResult = _jsonSerializer.Serialize(result);
			var httpClient = new HttpClient();
			var requestContent = new StringContent
			(
				serializedResult,
				Encoding.UTF8,
				"application/json"
			);

			requestContent.Headers.Add("X-Operation-Id", operationId);

			var response = await httpClient.PostAsync
			(
				$"{callbackHost}{callbackPath}",
				requestContent
			);
		}
Пример #3
0
		/// <summary>
		/// Called by the build service when a build completes, to store the result.
		/// </summary>
		public async Task OnBuildCompletedAsync(ProjectJobResult projectJobResult)
		{
			var commit = await _dbContext.Commits
				.Where(c => c.BuildRequestToken == projectJobResult.BuildRequestToken)
				.Include(c => c.Build)
				.Include(c => c.Project)
				.SingleOrDefaultAsync();

			if (commit == null)
			{
				return;
			}

			var previousBuild = await GetBuildsDescending(commit.Project)
				.Where(build => build.Commit.UserId == commit.UserId)
				.Where(build => build.Commit.PushDate < commit.PushDate)
				.Where(build => build.Status == BuildStatus.Completed)
				.FirstOrDefaultAsync();

			var previousTestResults = previousBuild?.TestResults
				?.ToDictionary(tr => $"{tr.ClassName}.{tr.TestName}", tr => tr);

			commit.Build = new Build()
			{
				CommitId = commit.Id,
				Commit = commit,
				DateStarted = projectJobResult.JobStartedDate,
				DateCompleted = projectJobResult.JobFinishedDate,
				Output = projectJobResult.BuildOutput,
				Status = GetBuildStatus(projectJobResult.Status),
				TestResults = projectJobResult?.TestResults
					?.Select
					(
						tr => new Model.Projects.TestResult()
						{
							ClassName = tr.ClassName,
							TestName = tr.TestName,
							Succeeded = tr.Succeeded,
							PreviouslySucceeded = GetPreviouslySucceeded(tr, previousTestResults),
							FailureMessage = tr.Failure?.Message,
							FailureOutput = tr.Failure?.Output,
							FailureTrace = tr.Failure?.Trace
						}
					)?.ToList()
			};

			await _dbContext.SaveChangesAsync();
		}