Пример #1
0
        public async Task <IActionResult> CreateRelease([FromRoute] string revisionNumber, [FromRoute] string projectName, [FromBody] QueueReleaseRequest request)
        {
            Project project = await ProjectDataService.GetAsync(TableStorageConfig.DomainString, projectName);

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

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

            if (revision == null)
            {
                return(new NotFoundObjectResult("Revision not found"));
            }
            else
            {
                if (project.AzureDevOps != null)
                {
                    dynamic desObject    = JsonConvert.DeserializeObject <dynamic>(revision.CommitPayload);
                    string  commitNumber = Convert.ToString(desObject.commit);

                    string aadAccessToken = this.HttpContext.Request?.Headers["Authorization"].ToString().Replace("Bearer ", "");
                    string accessToken = await ExchangeToAzureDevOpsToken(aadAccessToken); Release returnRelease = await AzureDevOpsService.QueueRelease(project.AzureDevOps, request, accessToken, projectName, revisionNumber, commitNumber);

                    if (returnRelease != null)
                    {
                        await ReleaseDataService.InsertOrReplaceAsync(returnRelease);

                        return(Ok(returnRelease));
                    }
                }
                return(StatusCode(500));
            }
        }
Пример #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> CreateRelease([FromRoute] string revisionNumber, [FromRoute] string projectName, [FromBody] QueueReleaseRequest request)
        {
            Project project = await ProjectDataService.GetAsync(TableStorageConfig.DomainString, projectName);

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

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

            if (revision == null)
            {
                return(new NotFoundObjectResult("Revision not found"));
            }
            else
            {
                if (project.AzureDevOps != null)
                {
                    dynamic desObject    = JsonConvert.DeserializeObject <dynamic>(revision.CommitPayload);
                    string  commitNumber = Convert.ToString(desObject.commit);

                    string aadAccessToken = this.HttpContext.Request?.Headers["Authorization"].ToString().Replace("Bearer ", "");
                    string accessToken = await ExchangeToAzureDevOpsToken(aadAccessToken); Release returnRelease = await AzureDevOpsService.QueueRelease(project.AzureDevOps, request, accessToken, projectName, revisionNumber, commitNumber);

                    if (returnRelease != null)
                    {
                        returnRelease.Status = "InProgress";
                        await ReleaseDataService.InsertOrReplaceAsync(returnRelease).ContinueWith(async(antecedent) =>
                        {
                            await BroadcastStatusHubContext.Clients.All.SendAsync(EventTable.GetEventMessage(EventTable.EventID.EventReleaseStatusChanged), returnRelease);
                        }, TaskContinuationOptions.OnlyOnRanToCompletion);

                        return(Ok(returnRelease));
                    }
                }
                return(StatusCode(500));
            }
        }
Пример #4
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());
        }
Пример #5
0
 public async Task <Revision> GetRevision([FromRoute] string projectName, [FromRoute] string revisionNumber)
 {
     return(await RevisionDataService.GetAsync(projectName, revisionNumber));
 }