예제 #1
0
        public async Task <IActionResult> TriggerAzure([FromRoute] string projectName, [FromBody] QueueBuildRequest request)
        {
            Project project = await ProjectDataService.GetAsync(CosmosDbConfig.DomainString, projectName);

            if (null == project)
            {
                return(new NotFoundObjectResult("Project not found"));
            }

            if (project.AzureDevOps != null)
            {
                string aadAccessToken = this.HttpContext.Request?.Headers["Authorization"].ToString().Replace("Bearer ", "");
                string accessToken    = await ExchangeToAzureDevOpsToken(aadAccessToken);

                Revision revision = await AzureDevOpsService.QueueBuild(project.AzureDevOps, request, accessToken);

                if (revision == null)
                {
                    return(StatusCode(500));
                }

                revision.ProjectName = projectName;
                await RevisionDataService.InsertAsync(revision);

                return(Ok(revision));
            }

            return(new NotFoundObjectResult("CI/CD service not found"));
        }
예제 #2
0
        public async Task <IActionResult> UpdateProcedureExecutionStatus([FromRoute] string procedureName, [FromRoute] string projectName,
                                                                         [FromRoute] string revisionNumber, [FromRoute] string status, [FromBody] JobStatusRequest jobStatus)
        {
            Project project = await ProjectDataService.GetAsync(TableStorageConfig.DomainString, projectName);

            if (project == null)
            {
                return(Unauthorized());
            }

            Revision revision = await RevisionDataService.GetAsync(projectName, revisionNumber);

            if (revision == null)
            {
                revision = new Revision()
                {
                    ProjectName    = projectName,
                    RevisionNumber = revisionNumber,
                    Requestor      = "",
                    CommitSet      = jobStatus.CommitSet,
                    CommitPayload  = JsonSerializer.Serialize(jobStatus.Commit),
                    CreatedTime    = DateTimeOffset.Now
                };
                await RevisionDataService.InsertAsync(revision);
            }
            else
            {
                revision.CommitPayload = JsonSerializer.Serialize(jobStatus.Commit);
                await RevisionDataService.UpdateAsync(revision);
            }

            Procedure procedure = await ProcedureDataService.GetAsync(projectName, procedureName);

            if (procedure == null)
            {
                procedure = new Procedure(projectName, procedureName)
                {
                    CreatedTime = DateTimeOffset.Now,
                    LongName    = procedureName
                };
                await ProcedureDataService.InsertAsync(procedure);
            }

            // Update status
            ProcedureExecution procedureExecution = new ProcedureExecution(revisionNumber, jobStatus.JobId, procedureName,
                                                                           JsonSerializer.Serialize(jobStatus.CiConfiguration), status)
            {
                DownloadLink = jobStatus.DownloadLink,
                ConsoleLog   = jobStatus.ConsoleLog,
                Machine      = jobStatus.Machine
            };
            await ProcedureExecutionDataService.InsertOrReplaceAsync(projectName, procedureExecution);

            return(Ok());
        }
예제 #3
0
        public async Task <IActionResult> UpdateProcedureExecutionStatus([FromRoute] string procedureName, [FromRoute] string projectName,
                                                                         [FromRoute] string revisionNumber, [FromRoute] string status, [FromBody] JobStatusRequest jobStatus)
        {
            Project project = await ProjectDataService.GetAsync(TableStorageConfig.DomainString, projectName);

            if (project == null)
            {
                return(Unauthorized());
            }

            var tasks = new List <Task>();

            Revision revision = await RevisionDataService.GetAsync(projectName, revisionNumber);

            if (revision == null)
            {
                revision = new Revision()
                {
                    ProjectName    = projectName,
                    RevisionNumber = revisionNumber,
                    Requestor      = "",
                    CommitSet      = jobStatus.CommitSet,
                    CommitPayload  = JsonSerializer.Serialize(jobStatus.Commit),
                    CreatedTime    = DateTimeOffset.Now
                };
                tasks.Add(RevisionDataService.InsertAsync(revision));
            }
            else
            {
                revision.CommitPayload = JsonSerializer.Serialize(jobStatus.Commit);
                tasks.Add(RevisionDataService.UpdateAsync(revision));
            }

            Procedure procedure = await ProcedureDataService.GetAsync(projectName, procedureName);

            if (procedure == null)
            {
                procedure = new Procedure(projectName, procedureName)
                {
                    CreatedTime = DateTimeOffset.Now,
                    LongName    = procedureName
                };
                tasks.Add(ProcedureDataService.InsertAsync(procedure));
            }

            // Update status
            ProcedureExecution procedureExecution = new ProcedureExecution(revisionNumber, jobStatus.JobId, procedureName,
                                                                           JsonSerializer.Serialize(jobStatus.CiConfiguration), status)
            {
                DownloadLink = jobStatus.DownloadLink,
                ConsoleLog   = jobStatus.ConsoleLog,
                Machine      = jobStatus.Machine
            };

            tasks.Add(ProcedureExecutionDataService.InsertOrReplaceAsync(projectName, procedureExecution));

            // Make sure all changes from database are done before trigger event to clients
            await Task.WhenAll(tasks).ContinueWith(async(antecedent) =>
            {
                await BroadcastStatusHubContext.Clients.All.SendAsync(EventTable.GetEventMessage(EventTable.EventID.EventProcedureExecutionStatusChanged), projectName, revision, procedureExecution);
            }, TaskContinuationOptions.OnlyOnRanToCompletion);

            return(Ok());
        }