static PlanResult Run(
                IRestApi restApi,
                string ciName,
                string planPath,
                string objectSpec,
                string comment,
                Dictionary <string, string> properties,
                int maxWaitTimeSeconds)
            {
                LaunchPlanRequest request = new LaunchPlanRequest()
                {
                    ObjectSpec = objectSpec,
                    Comment    = string.Format("MergeBot - {0}", comment),
                    Properties = properties
                };

                SingleResponse planResponse = restApi.CI.LaunchPlan(
                    ciName, planPath, request);

                GetPlanStatusResponse statusResponse =
                    Task.Run(() =>
                             WaitForFinishedPlanStatus(
                                 restApi,
                                 ciName,
                                 planResponse.Value,
                                 planPath,
                                 maxWaitTimeSeconds)
                             ).Result;

                if (statusResponse != null)
                {
                    return(new PlanResult()
                    {
                        Succeeded = statusResponse.Succeeded,
                        Explanation = statusResponse.Explanation
                    });
                }

                return(new PlanResult()
                {
                    Succeeded = false,
                    Explanation = string.Format(
                        "{0} reached the time limit to get the status " +
                        "for plan:'{1}' and executionId:'{2}'" +
                        "\nRequest details: objectSpec:'{3}' and comment:'{4}'",
                        ciName, planPath, planResponse.Value, objectSpec, comment)
                });
            }
示例#2
0
            static async Task <GetPlanStatusResponse> WaitForFinishedPlanStatus(
                RestApi restApi,
                string ciName,
                string planBranch,
                string executionId,
                int maxWaitTimeSeconds)
            {
                long startTime = Environment.TickCount;

                do
                {
                    GetPlanStatusResponse statusResponse = restApi.CI.
                                                           GetPlanStatus(ciName, planBranch, executionId);

                    if (statusResponse.IsFinished)
                    {
                        return(statusResponse);
                    }

                    await Task.Delay(5000);
                } while (Environment.TickCount - startTime < maxWaitTimeSeconds * 1000);

                return(null);
            }