Ejemplo n.º 1
0
        public async Task <int> UpdateAzureDevOpsBuilds(
            string organization, string project, string repository, string branch,
            string buildName, string buildId,
            int numberOfDays, int maxNumberOfItems)
        {
            int numberOfRecordsSaved;

            try
            {
                TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

                //Get the PAT token from the key vault
                string patTokenName = PartitionKeys.CreateAzureDevOpsSettingsPartitionKeyPatToken(organization, project, repository);
                patTokenName = SecretsProcessing.CleanKey(patTokenName);
                string patToken = Configuration[patTokenName];
                if (string.IsNullOrEmpty(patToken) == true)
                {
                    throw new Exception($"patToken '{patTokenName}' not found in key vault");
                }

                numberOfRecordsSaved = await AzureTableStorageDA.UpdateAzureDevOpsBuildsInStorage(patToken, tableStorageConfig, organization, project, branch, buildName, buildId, numberOfDays, maxNumberOfItems);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).")
                {
                    numberOfRecordsSaved = -1;
                }
                else
                {
                    throw;
                }
            }
            return(numberOfRecordsSaved);
        }
Ejemplo n.º 2
0
        public async Task <bool> UpdateGitHubSetting(string clientId, string clientSecret,
                                                     string owner, string repo,
                                                     string branch, string workflowName, string workflowId, string resourceGroup,
                                                     int itemOrder, bool showSetting)
        {
            //Save the Client Id and Client Secret to the key vault
            string clientIdName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientId(owner, repo);

            clientIdName = SecretsProcessing.CleanKey(clientIdName);
            if (clientIdName.Length > 10)
            {
                await CreateKeyVaultSecret(clientIdName, clientId);
            }
            string clientSecretName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientSecret(owner, repo);

            clientSecretName = SecretsProcessing.CleanKey(clientSecretName);
            if (clientSecretName.Length > 14)
            {
                await CreateKeyVaultSecret(clientSecretName, clientSecret);
            }

            //Save everything else to table storage
            TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

            return(await AzureTableStorageDA.UpdateGitHubSettingInStorage(tableStorageConfig, tableStorageConfig.TableGitHubSettings,
                                                                          owner, repo, branch, workflowName, workflowId, resourceGroup, itemOrder, showSetting));
        }
Ejemplo n.º 3
0
        public PocoData(Type pocoType, string tableName, string keyspaceName, LookupKeyedCollection <string, PocoColumn> columns,
                        string[] partitionkeys, Tuple <string, SortOrder>[] clusteringKeys, bool caseSensitive, bool compact, bool allowFiltering)
        {
            if (partitionkeys == null)
            {
                throw new ArgumentNullException("partitionkeys");
            }
            if (clusteringKeys == null)
            {
                throw new ArgumentNullException("clusteringKeys");
            }
            PocoType             = pocoType ?? throw new ArgumentNullException("pocoType");
            TableName            = tableName ?? throw new ArgumentNullException("tableName");
            Columns              = columns ?? throw new ArgumentNullException("columns");
            CaseSensitive        = caseSensitive;
            CompactStorage       = compact;
            AllowFiltering       = allowFiltering;
            KeyspaceName         = keyspaceName;
            _columnsByMemberName = columns.ToDictionary(c => c.MemberInfo.Name, c => c);
            PartitionKeys        = partitionkeys.Where(columns.Contains).Select(key => columns[key]).ToList();
            ClusteringKeys       = clusteringKeys.Where(c => columns.Contains(c.Item1)).Select(c => Tuple.Create(columns[c.Item1], c.Item2)).ToList();
            _primaryKeys         = new HashSet <string>(PartitionKeys.Select(p => p.ColumnName).Concat(ClusteringKeys.Select(c => c.Item1.ColumnName)));

            MissingPrimaryKeyColumns = new List <string>();
            if (PartitionKeys.Count != partitionkeys.Length)
            {
                MissingPrimaryKeyColumns.AddRange(partitionkeys.Where(k => !columns.Contains(k)));
            }
            if (ClusteringKeys.Count != clusteringKeys.Length)
            {
                MissingPrimaryKeyColumns.AddRange(partitionkeys.Where(k => !columns.Contains(k)));
            }
        }
Ejemplo n.º 4
0
        public List <ProjectLog> GetGitHubProjectLog(string owner, string repo)
        {
            string partitionKey = PartitionKeys.CreateGitHubSettingsPartitionKey(owner, repo);

            TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

            return(AzureTableStorageDA.GetProjectLogsFromStorage(tableStorageConfig, partitionKey));
        }
Ejemplo n.º 5
0
        public List <ProjectLog> GetAzureDevOpsProjectLog(string organization, string project, string repository)
        {
            string partitionKey = PartitionKeys.CreateAzureDevOpsSettingsPartitionKey(organization, project, repository);

            TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

            return(AzureTableStorageDA.GetProjectLogsFromStorage(tableStorageConfig, partitionKey));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Logs(string projectId = null)
        {
            //Get a list of settings
            ServiceApiClient           serviceApiClient    = new(Configuration);
            List <AzureDevOpsSettings> azureDevOpsSettings = await serviceApiClient.GetAzureDevOpsSettings();

            List <GitHubSettings> githubSettings = await serviceApiClient.GetGitHubSettings();

            List <KeyValuePair <string, string> > projects = new()
            {
                new("", "<Select project>")
            };

            foreach (AzureDevOpsSettings item in azureDevOpsSettings)
            {
                //if (item.ShowSetting == true)
                //{
                string partitionKey = PartitionKeys.CreateAzureDevOpsSettingsPartitionKey(item.Organization, item.Project, item.Repository);
                projects.Add(new KeyValuePair <string, string>(partitionKey, item.Project));
                //}
            }
            foreach (GitHubSettings item in githubSettings)
            {
                //if (item.ShowSetting == true)
                //{
                string partitionKey = PartitionKeys.CreateGitHubSettingsPartitionKey(item.Owner, item.Repo);
                projects.Add(new KeyValuePair <string, string>(partitionKey, item.Repo));
                //}
            }

            List <ProjectLog> logs = new();

            if (string.IsNullOrEmpty(projectId) == false)
            {
                //TODO: This is gross. Fix this, making it easier to maintain and more efficient
                if (projectId.Split("_").Length == 3)
                {
                    logs = await serviceApiClient.GetAzureDevOpsProjectLogs(projectId.Split("_")[0], projectId.Split("_")[1], projectId.Split("_")[2]);
                }
                else
                {
                    logs = await serviceApiClient.GetGitHubProjectLogs(projectId.Split("_")[0], projectId.Split("_")[1]);
                }
            }

            //Flip the logs/ reverse the list of log items
            logs.Reverse();

            ProjectLogViewModel logViewModel = new()
            {
                ProjectId = projectId,
                Logs      = logs,
                Projects  = new SelectList(projects, "Key", "Value")
            };

            return(View(logViewModel));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 判断成员名称是否主键成员
 /// </summary>
 public bool IsPrimaryKey(ushort mid)
 {
     if (PartitionKeys != null && PartitionKeys.Contains(mid))
     {
         return(true);
     }
     if (ClusteringColumns != null && ClusteringColumns.Any(t => t.MemberId == mid))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 8
0
        public async Task <bool> UpdateGitHubProjectLog(string owner, string repo,
                                                        int buildsUpdated, int prsUpdated, string buildUrl, string prUrl,
                                                        string exceptionMessage, string exceptionStackTrace)
        {
            ProjectLog log = new(
                PartitionKeys.CreateGitHubSettingsPartitionKey(owner, repo),
                buildsUpdated, prsUpdated, HttpUtility.UrlDecode(buildUrl), HttpUtility.UrlDecode(prUrl), exceptionMessage, exceptionStackTrace);

            TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

            return(await AzureTableStorageDA.UpdateProjectLogInStorage(tableStorageConfig, log));
        }
Ejemplo n.º 9
0
 public void TestStart()
 {
     //Arrange
     Dictionary <string, string> inMemorySettings = new()
     {
         {
             "AppSettings:KeyVaultURL",
             "keyvaultURLTest"
         },
         {
             PartitionKeys.CreateAzureDevOpsSettingsPartitionKeyPatToken("", "", ""),
             "patTokenSecret"
         },
Ejemplo n.º 10
0
        public async Task <bool> UpdateChangeFailureRate(TableStorageConfiguration tableStorageConfig,
                                                         string organization_owner, string project_repo, string buildName_workflowName,
                                                         int percentComplete, int numberOfDays)
        {
            //Gets a list of change failure rate builds
            AzureTableStorageDA daTableStorage = new AzureTableStorageDA();
            string partitionKey = PartitionKeys.CreateBuildWorkflowPartitionKey(organization_owner, project_repo, buildName_workflowName);

            Newtonsoft.Json.Linq.JArray   list          = daTableStorage.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableChangeFailureRate, partitionKey);
            List <ChangeFailureRateBuild> initialBuilds = JsonConvert.DeserializeObject <List <ChangeFailureRateBuild> >(list.ToString());

            //Get the list of items we are going to process, within the date/day range
            List <ChangeFailureRateBuild> builds = new List <ChangeFailureRateBuild>();

            foreach (ChangeFailureRateBuild item in initialBuilds)
            {
                if (item.StartTime > DateTime.Now.AddDays(-numberOfDays))
                {
                    builds.Add(item);
                }
            }

            Tuple <List <ChangeFailureRateBuild>, List <ChangeFailureRateBuild> > positiveAndNegativeBuilds = GetPositiveAndNegativeLists(percentComplete, builds);
            List <ChangeFailureRateBuild> positiveBuilds = positiveAndNegativeBuilds.Item1;
            List <ChangeFailureRateBuild> negativeBuilds = positiveAndNegativeBuilds.Item2;

            //Make the updates
            TableStorageCommonDA tableChangeFailureRateDA = new TableStorageCommonDA(tableStorageConfig, tableStorageConfig.TableChangeFailureRate);

            foreach (ChangeFailureRateBuild item in positiveBuilds)
            {
                item.DeploymentWasSuccessful = true;
                await daTableStorage.UpdateChangeFailureRate(tableChangeFailureRateDA, item, partitionKey, true);
            }
            foreach (ChangeFailureRateBuild item in negativeBuilds)
            {
                item.DeploymentWasSuccessful = false;
                await daTableStorage.UpdateChangeFailureRate(tableChangeFailureRateDA, item, partitionKey, true);
            }

            return(true);
        }
Ejemplo n.º 11
0
        public async Task <bool> UpdateAzureDevOpsSetting(string patToken,
                                                          string organization, string project, string repository,
                                                          string branch, string buildName, string buildId, string resourceGroup,
                                                          int itemOrder, bool showSetting)
        {
            //Save the PAT token to the key vault
            string patTokenName = PartitionKeys.CreateAzureDevOpsSettingsPartitionKeyPatToken(organization, project, repository);

            patTokenName = SecretsProcessing.CleanKey(patTokenName);
            if (patTokenName.Length > 12)
            {
                await CreateKeyVaultSecret(patTokenName, patToken);
            }

            //Save everything else to table storage
            TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

            return(await AzureTableStorageDA.UpdateAzureDevOpsSettingInStorage(tableStorageConfig, tableStorageConfig.TableAzureDevOpsSettings,
                                                                               organization, project, repository, branch, buildName, buildId, resourceGroup, itemOrder, showSetting));
        }
        public async Task<LeadTimeForChangesModel> GetGitHubLeadTimeForChanges(bool getSampleData, 
            string owner, string repo, string branch, string workflowName, string workflowId,
            int numberOfDays, int maxNumberOfItems, bool useCache)
        {
            LeadTimeForChangesModel model = new();
            try
            {
                TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

                //Get the client id and secret from the settings
                string clientIdName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientId(owner, repo);
                clientIdName = SecretsProcessing.CleanKey(clientIdName);
                string clientSecretName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientSecret(owner, repo);
                clientSecretName = SecretsProcessing.CleanKey(clientSecretName);
                string clientId = Configuration[clientIdName];
                string clientSecret = Configuration[clientSecretName];
                if (string.IsNullOrEmpty(clientId) == true | string.IsNullOrEmpty(clientSecret) == true)
                {
                    throw new Exception($"clientId '{clientId}' or clientSecret '{clientSecret}' not found in key vault");
                }

                LeadTimeForChangesDA da = new();
                model = await da.GetGitHubLeadTimesForChanges(getSampleData, clientId, clientSecret, tableStorageConfig,
                        owner, repo, branch, workflowName, workflowId, numberOfDays, maxNumberOfItems, useCache);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).")
                {
                    model.ProjectName = repo;
                    model.RateLimitHit = true;
                }
                else
                {
                    throw;
                }
            }
            return model;

        }
Ejemplo n.º 13
0
        public async Task <int> UpdateGitHubActionRuns(
            string owner, string repo, string branch, string workflowName, string workflowId,
            int numberOfDays, int maxNumberOfItems)
        {
            int numberOfRecordsSaved;

            try
            {
                TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

                //Get the client id and secret from the settings
                string clientIdName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientId(owner, repo);
                clientIdName = SecretsProcessing.CleanKey(clientIdName);
                string clientSecretName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientSecret(owner, repo);
                clientSecretName = SecretsProcessing.CleanKey(clientSecretName);
                string clientId     = Configuration[clientIdName];
                string clientSecret = Configuration[clientSecretName];
                if (string.IsNullOrEmpty(clientId) == true | string.IsNullOrEmpty(clientSecret) == true)
                {
                    throw new Exception($"clientId '{clientId}' or clientSecret '{clientSecret}' not found in key vault");
                }

                numberOfRecordsSaved = await AzureTableStorageDA.UpdateGitHubActionRunsInStorage(clientId, clientSecret, tableStorageConfig,
                                                                                                 owner, repo, branch, workflowName, workflowId, numberOfDays, maxNumberOfItems);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).")
                {
                    numberOfRecordsSaved = -1;
                }
                else
                {
                    throw;
                }
            }
            return(numberOfRecordsSaved);
        }
        public async Task<LeadTimeForChangesModel> GetAzureDevOpsLeadTimeForChanges(bool getSampleData, 
            string organization, string project, string repository, string branch, string buildName, 
            int numberOfDays, int maxNumberOfItems, bool useCache)
        {
            LeadTimeForChangesModel model = new();
            try
            {
                TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

                //Get the PAT token from the key vault
                string patTokenName = PartitionKeys.CreateAzureDevOpsSettingsPartitionKeyPatToken(organization, project, repository);
                patTokenName = SecretsProcessing.CleanKey(patTokenName);
                string patToken = Configuration[patTokenName];
                if (string.IsNullOrEmpty(patToken) == true)
                {
                    throw new Exception($"patToken '{patTokenName}' not found in key vault");
                }

                LeadTimeForChangesDA da = new();
                model = await da.GetAzureDevOpsLeadTimesForChanges(getSampleData,  patToken, tableStorageConfig,
                        organization, project, repository, branch, buildName, numberOfDays, maxNumberOfItems, useCache);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).")
                {
                    model.ProjectName = project;
                    model.RateLimitHit = true;
                }
                else
                {
                    throw;
                }
            }
            return model;
        }
Ejemplo n.º 15
0
        public async Task <AzureDevOpsPR> GetAzureDevOpsPullRequest(string patToken, TableStorageConfiguration tableStorageConfig,
                                                                    string organization, string project, string repository, string branch, bool useCache)
        {
            List <AzureDevOpsPR> prs = new List <AzureDevOpsPR>();

            Newtonsoft.Json.Linq.JArray list;
            if (useCache == true)
            {
                //Get the pull requests from Azure storage
                AzureTableStorageDA daTableStorage = new AzureTableStorageDA();
                list = daTableStorage.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableAzureDevOpsPRs, PartitionKeys.CreateGitHubPRPartitionKey(organization, project));
            }
            else
            {
                //Get the pull requests from the Azure DevOps API
                AzureDevOpsAPIAccess api = new AzureDevOpsAPIAccess();
                list = await api.GetAzureDevOpsPullRequestsJArray(patToken, organization, project, repository);
            }
            if (list != null)
            {
                prs = JsonConvert.DeserializeObject <List <AzureDevOpsPR> >(list.ToString());
            }

            //Find the PR id
            AzureDevOpsPR pr = null;

            foreach (AzureDevOpsPR item in prs)
            {
                if (item.sourceRefName == branch)
                {
                    pr = item;
                    break;
                }
            }
            return(pr);
        }
Ejemplo n.º 16
0
        public void GHGetPRsDAIntegrationTest()
        {
            //Arrange
            TableStorageConfiguration tableStorageConfig = Common.GenerateTableAuthorization(base.Configuration);
            string owner = "samsmithnz";
            string repo  = "DevOpsMetrics";

            //Act
            AzureTableStorageDA da = new();
            JArray list            = da.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableGitHubPRs, PartitionKeys.CreateGitHubPRPartitionKey(owner, repo));

            //Assert
            Assert.IsTrue(list.Count >= 0);
        }
Ejemplo n.º 17
0
        public void AzGetSamLearnsAzureLogsDAIntegrationTest()
        {
            //Arrange
            TableStorageConfiguration tableStorageConfig = Common.GenerateTableAuthorization(base.Configuration);
            string organization = "samsmithnz";
            string project      = "SamLearnsAzure";
            string repository   = "SamLearnsAzure";

            //Act
            AzureTableStorageDA da   = new();
            List <ProjectLog>   logs = da.GetProjectLogsFromStorage(tableStorageConfig, PartitionKeys.CreateAzureDevOpsSettingsPartitionKey(organization, project, repository));

            //Assert
            Assert.IsTrue(logs != null);
            Assert.IsTrue(logs.Count > 0);
        }
Ejemplo n.º 18
0
        public ChangeFailureRateModel GetChangeFailureRate(bool getSampleData, TableStorageConfiguration tableStorageConfig,
                                                           DevOpsPlatform targetDevOpsPlatform, string organization_owner, string project_repo, string branch, string buildName_workflowName,
                                                           int numberOfDays, int maxNumberOfItems)
        {
            ListUtility <ChangeFailureRateBuild> utility = new ListUtility <ChangeFailureRateBuild>();
            ChangeFailureRate changeFailureRate          = new ChangeFailureRate();

            if (getSampleData == false)
            {
                //Gets a list of change failure rate builds from Azure storage
                AzureTableStorageDA           daTableStorage = new AzureTableStorageDA();
                Newtonsoft.Json.Linq.JArray   list           = daTableStorage.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableChangeFailureRate, PartitionKeys.CreateBuildWorkflowPartitionKey(organization_owner, project_repo, buildName_workflowName));
                List <ChangeFailureRateBuild> initialBuilds  = JsonConvert.DeserializeObject <List <ChangeFailureRateBuild> >(list.ToString());

                //Build the date list and then generate the change failure rate metric
                List <ChangeFailureRateBuild>         builds   = new List <ChangeFailureRateBuild>();
                List <KeyValuePair <DateTime, bool> > dateList = new List <KeyValuePair <DateTime, bool> >();
                float maxBuildDuration = 0f;
                foreach (ChangeFailureRateBuild item in initialBuilds)
                {
                    if (item.Branch == branch && item.StartTime > DateTime.Now.AddDays(-numberOfDays))
                    {
                        //Special branch for Azure DevOps to construct the Url to each build
                        if (targetDevOpsPlatform == DevOpsPlatform.AzureDevOps)
                        {
                            item.Url = $"https://dev.azure.com/{organization_owner}/{project_repo}/_build/results?buildId={item.Id}&view=results";
                        }
                        builds.Add(item);
                    }
                }

                //then build the calcuation
                foreach (ChangeFailureRateBuild item in builds)
                {
                    KeyValuePair <DateTime, bool> newItem = new KeyValuePair <DateTime, bool>(item.StartTime, item.DeploymentWasSuccessful);
                    dateList.Add(newItem);
                }
                //calculate the metric on all of the results
                float changeFailureRateMetric = changeFailureRate.ProcessChangeFailureRate(dateList, numberOfDays);

                //Filter the results to return the last n (maxNumberOfItems)
                List <ChangeFailureRateBuild> uiBuilds = utility.GetLastNItems(builds, maxNumberOfItems);
                foreach (ChangeFailureRateBuild item in uiBuilds)
                {
                    if (item.BuildDuration > maxBuildDuration)
                    {
                        maxBuildDuration = item.BuildDuration;
                    }
                }
                //We need to do some post processing and loop over the list a couple times to find the max build duration, construct a usable url, and calculate a build duration percentage
                foreach (ChangeFailureRateBuild item in uiBuilds)
                {
                    float interiumResult = ((item.BuildDuration / maxBuildDuration) * 100f);
                    item.BuildDurationPercent = Scaling.ScaleNumberToRange(interiumResult, 0, 100, 20, 100);
                }

                ChangeFailureRateModel model = new ChangeFailureRateModel
                {
                    TargetDevOpsPlatform               = targetDevOpsPlatform,
                    DeploymentName                     = buildName_workflowName,
                    ChangeFailureRateBuildList         = uiBuilds,
                    ChangeFailureRateMetric            = changeFailureRateMetric,
                    ChangeFailureRateMetricDescription = changeFailureRate.GetChangeFailureRateRating(changeFailureRateMetric),
                    NumberOfDays     = numberOfDays,
                    MaxNumberOfItems = uiBuilds.Count,
                    TotalItems       = builds.Count
                };
                return(model);
            }
            else
            {
                //Get sample data
                List <ChangeFailureRateBuild> sampleBuilds = utility.GetLastNItems(GetSampleBuilds(), maxNumberOfItems);
                ChangeFailureRateModel        model        = new ChangeFailureRateModel
                {
                    TargetDevOpsPlatform               = targetDevOpsPlatform,
                    DeploymentName                     = buildName_workflowName,
                    ChangeFailureRateBuildList         = sampleBuilds,
                    ChangeFailureRateMetric            = 2f / 10f,
                    ChangeFailureRateMetricDescription = changeFailureRate.GetChangeFailureRateRating(2f / 10f),
                    NumberOfDays     = numberOfDays,
                    MaxNumberOfItems = sampleBuilds.Count,
                    TotalItems       = sampleBuilds.Count
                };
                return(model);
            }
        }
Ejemplo n.º 19
0
        public void GHGetSamsFeatureFlagsLogsDAIntegrationTest()
        {
            //Arrange
            TableStorageConfiguration tableStorageConfig = Common.GenerateTableAuthorization(base.Configuration);
            string owner = "samsmithnz";
            string repo  = "SamsFeatureFlags";

            //Act
            AzureTableStorageDA da   = new();
            List <ProjectLog>   logs = da.GetProjectLogsFromStorage(tableStorageConfig, PartitionKeys.CreateGitHubSettingsPartitionKey(owner, repo));

            //Assert
            Assert.IsTrue(logs != null);
            Assert.IsTrue(logs.Count > 0);
        }
Ejemplo n.º 20
0
        public async Task <List <GitHubActionsRun> > GetGitHubActionRuns(string clientId, string clientSecret, TableStorageConfiguration tableStorageConfig,
                                                                         string owner, string repo, string workflowName, string workflowId, bool useCache)
        {
            List <GitHubActionsRun> runs = new List <GitHubActionsRun>();

            Newtonsoft.Json.Linq.JArray list = null;
            if (useCache == true)
            {
                //Get the builds from Azure storage
                AzureTableStorageDA daTableStorage = new AzureTableStorageDA();
                list = daTableStorage.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableGitHubRuns, PartitionKeys.CreateBuildWorkflowPartitionKey(owner, repo, workflowName));
            }
            else
            {
                //Get the builds from the GitHub API
                GitHubAPIAccess api = new GitHubAPIAccess();
                list = await api.GetGitHubActionRunsJArray(clientId, clientSecret, owner, repo, workflowId);
            }
            if (list != null)
            {
                runs = JsonConvert.DeserializeObject <List <GitHubActionsRun> >(list.ToString());

                //sort the final list
                runs = runs.OrderBy(o => o.created_at).ToList();
            }

            return(runs);
        }
Ejemplo n.º 21
0
        public void AzGetPRsDAIntegrationTest()
        {
            //Arrange
            TableStorageConfiguration tableStorageConfig = Common.GenerateTableAuthorization(base.Configuration);
            string organization = "samsmithnz";
            string project      = "SamLearnsAzure";

            //Act
            AzureTableStorageDA da = new();
            JArray list            = da.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableAzureDevOpsBuilds, PartitionKeys.CreateAzureDevOpsPRPartitionKey(organization, project));

            //Assert
            Assert.IsTrue(list.Count >= 0);
        }
Ejemplo n.º 22
0
        public async Task <List <AzureDevOpsBuild> > GetAzureDevOpsBuilds(string patToken, TableStorageConfiguration tableStorageConfig,
                                                                          string organization, string project, string buildName, bool useCache)
        {
            List <AzureDevOpsBuild> builds = new List <AzureDevOpsBuild>();

            Newtonsoft.Json.Linq.JArray list = null;
            if (useCache == true)
            {
                //Get the builds from Azure storage
                AzureTableStorageDA daTableStorage = new AzureTableStorageDA();
                list = daTableStorage.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableAzureDevOpsBuilds, PartitionKeys.CreateBuildWorkflowPartitionKey(organization, project, buildName));
            }
            else
            {
                //Get the builds from the Azure DevOps API
                AzureDevOpsAPIAccess api = new AzureDevOpsAPIAccess();
                list = await api.GetAzureDevOpsBuildsJArray(patToken, organization, project);
            }
            if (list != null)
            {
                builds = JsonConvert.DeserializeObject <List <AzureDevOpsBuild> >(list.ToString());
                //We need to do some post processing and loop over the list to construct a usable url
                foreach (AzureDevOpsBuild item in builds)
                {
                    item.url = $"https://dev.azure.com/{organization}/{project}/_build/results?buildId={item.id}&view=results";
                }

                //sort the final list
                builds = builds.OrderBy(o => o.queueTime).ToList();
            }

            return(builds);
        }
Ejemplo n.º 23
0
        public async Task <GitHubPR> GetGitHubPullRequest(string clientId, string clientSecret, TableStorageConfiguration tableStorageConfig, string owner, string repo, string branch, bool useCache)
        {
            List <GitHubPR> prs = new List <GitHubPR>();

            Newtonsoft.Json.Linq.JArray list;
            if (useCache == true)
            {
                //Get the pull requests from Azure storage
                AzureTableStorageDA daTableStorage = new AzureTableStorageDA();
                list = daTableStorage.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableGitHubPRs, PartitionKeys.CreateGitHubPRPartitionKey(owner, repo));
            }
            else
            {
                //Get the pull requests from the GitHub API
                GitHubAPIAccess api = new GitHubAPIAccess();
                list = await api.GetGitHubPullRequestsJArray(clientId, clientSecret, owner, repo, branch);
            }
            if (list != null)
            {
                prs = JsonConvert.DeserializeObject <List <GitHubPR> >(list.ToString());
            }

            //Find the PR id
            GitHubPR pr = null;

            foreach (GitHubPR item in prs)
            {
                if (item.head.@ref == branch)
                {
                    pr = item;
                    break;
                }
            }
            return(pr);
        }
Ejemplo n.º 24
0
        public async Task <List <AzureDevOpsPRCommit> > GetAzureDevOpsPullRequestCommits(string patToken, TableStorageConfiguration tableStorageConfig, string organization, string project, string repository, string pullRequestId, bool useCache)
        {
            Newtonsoft.Json.Linq.JArray list;
            if (useCache == true)
            {
                //Get the commits from Azure storage
                AzureTableStorageDA daTableStorage = new AzureTableStorageDA();
                list = daTableStorage.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableAzureDevOpsPRCommits, PartitionKeys.CreateAzureDevOpsPRCommitPartitionKey(organization, project, pullRequestId));
            }
            else
            {
                //Get the commits from the Azure DevOps API
                AzureDevOpsAPIAccess api = new AzureDevOpsAPIAccess();
                list = await api.GetAzureDevOpsPullRequestCommitsJArray(patToken, organization, project, repository, pullRequestId);
            }

            List <AzureDevOpsPRCommit> commits = JsonConvert.DeserializeObject <List <AzureDevOpsPRCommit> >(list.ToString());

            return(commits);
        }
Ejemplo n.º 25
0
        public void AzGetPRCommitsDAIntegrationTest()
        {
            //Arrange
            TableStorageConfiguration tableStorageConfig = Common.GenerateTableAuthorization(base.Configuration);
            string organization = "samsmithnz";
            string project      = "SamLearnsAzure";

            //Act
            AzureTableStorageDA da = new();
            JArray prList          = da.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableAzureDevOpsPRs, PartitionKeys.CreateAzureDevOpsPRPartitionKey(organization, project));
            int    itemsAdded      = 0;

            foreach (JToken item in prList)
            {
                AzureDevOpsPR pullRequest   = JsonConvert.DeserializeObject <AzureDevOpsPR>(item.ToString());
                string        pullRequestId = pullRequest.PullRequestId;
                JArray        list          = da.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableAzureDevOpsPRCommits, PartitionKeys.CreateAzureDevOpsPRCommitPartitionKey(organization, project, pullRequestId));
                if (list.Count > 0)
                {
                    itemsAdded = list.Count;
                    break;
                }
            }

            //Assert
            Assert.IsTrue(itemsAdded >= 0);
        }
Ejemplo n.º 26
0
        public async Task <List <GitHubPRCommit> > GetGitHubPullRequestCommits(string clientId, string clientSecret, TableStorageConfiguration tableStorageConfig, string owner, string repo, string pull_number, bool useCache)
        {
            Newtonsoft.Json.Linq.JArray list;
            if (useCache == true)
            {
                //Get the commits from Azure storage
                AzureTableStorageDA daTableStorage = new AzureTableStorageDA();
                list = daTableStorage.GetTableStorageItemsFromStorage(tableStorageConfig, tableStorageConfig.TableGitHubPRCommits, PartitionKeys.CreateGitHubPRCommitPartitionKey(owner, repo, pull_number));
            }
            else
            {
                //Get the commits from the GitHub API
                GitHubAPIAccess api = new GitHubAPIAccess();
                list = await api.GetGitHubPullRequestCommitsJArray(clientId, clientSecret, owner, repo, pull_number);
            }
            List <GitHubPRCommit> commits = JsonConvert.DeserializeObject <List <GitHubPRCommit> >(list.ToString());

            return(commits);
        }