Пример #1
0
        public async Task <bool> UpdateAzureDevOpsSetting(string patToken, TableStorageAuth tableStorageAuth, string settingsTable,
                                                          string organization, string project, string repository, string branch, string buildName, string buildId, string resourceGroupName, int itemOrder)
        {
            string partitionKey          = "AzureDevOpsSettings";
            string rowKey                = CreateAzureDevOpsSettingsPartitionKey(organization, project, repository, buildName);
            AzureDevOpsSettings settings = new AzureDevOpsSettings
            {
                RowKey                  = rowKey,
                PatToken                = patToken,
                Organization            = organization,
                Project                 = project,
                Repository              = repository,
                Branch                  = branch,
                BuildName               = buildName,
                BuildId                 = buildId,
                ProductionResourceGroup = resourceGroupName,
                ItemOrder               = itemOrder
            };

            string json = JsonConvert.SerializeObject(settings);
            AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, json);
            TableStorageCommonDA   tableDA = new TableStorageCommonDA(tableStorageAuth, settingsTable);

            return(await tableDA.SaveItem(newItem));
        }
Пример #2
0
        public async Task <bool> UpdateGitHubSetting(string clientId, string clientSecret, TableStorageAuth tableStorageAuth, string settingsTable,
                                                     string owner, string repo, string branch, string workflowName, string workflowId, string resourceGroupName, int itemOrder)
        {
            string         partitionKey = "GitHubSettings";
            string         rowKey       = CreateGitHubSettingsPartitionKey(owner, repo, workflowName);
            GitHubSettings settings     = new GitHubSettings
            {
                RowKey                  = rowKey,
                ClientId                = clientId,
                ClientSecret            = clientSecret,
                Owner                   = owner,
                Repo                    = repo,
                Branch                  = branch,
                WorkflowName            = workflowName,
                WorkflowId              = workflowId,
                ProductionResourceGroup = resourceGroupName,
                ItemOrder               = itemOrder
            };

            string json = JsonConvert.SerializeObject(settings);
            AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, json);
            TableStorageCommonDA   tableDA = new TableStorageCommonDA(tableStorageAuth, settingsTable);

            return(await tableDA.SaveItem(newItem));
        }
Пример #3
0
        public async Task <int> UpdateGitHubActionPullRequestCommits(string clientId, string clientSecret, TableStorageAuth tableStorageAuth,
                                                                     string owner, string repo, string pull_number)
        {
            GitHubAPIAccess api   = new GitHubAPIAccess();
            JArray          items = await api.GetGitHubPullRequestCommitsJArray(clientId, clientSecret, owner, repo, pull_number);

            int itemsAdded = 0;
            TableStorageCommonDA tableDA = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableGitHubPRCommits);

            //Check each build to see if it's in storage, adding the items not in storage
            foreach (JToken item in items)
            {
                GitHubCommit commit = JsonConvert.DeserializeObject <GitHubCommit>(item.ToString());

                string partitionKey            = CreateGitHubPRCommitPartitionKey(owner, repo, pull_number);
                string rowKey                  = commit.sha;
                AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, item.ToString());
                if (await tableDA.AddItem(newItem) == true)
                {
                    itemsAdded++;
                }
            }

            return(itemsAdded);
        }
Пример #4
0
        public async Task <int> UpdateGitHubActionPullRequests(string clientId, string clientSecret, TableStorageAuth tableStorageAuth,
                                                               string owner, string repo, string branch,
                                                               int numberOfDays, int maxNumberOfItems)
        {
            GitHubAPIAccess api   = new GitHubAPIAccess();
            JArray          items = await api.GetGitHubPullRequestsJArray(clientId, clientSecret, owner, repo, branch);

            int itemsAdded = 0;
            TableStorageCommonDA tableDA = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableGitHubPRs);

            //Check each build to see if it's in storage, adding the items not in storage
            foreach (JToken item in items)
            {
                GitHubPR pr = JsonConvert.DeserializeObject <GitHubPR>(item.ToString());

                if (pr.state == "closed")
                {
                    string partitionKey            = CreateGitHubPRPartitionKey(owner, repo);
                    string rowKey                  = pr.number;
                    AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, item.ToString());
                    if (await tableDA.AddItem(newItem) == true)
                    {
                        itemsAdded++;
                    }

                    itemsAdded += await UpdateGitHubActionPullRequestCommits(clientId, clientSecret, tableStorageAuth,
                                                                             owner, repo, pr.number);
                }
            }

            return(itemsAdded);
        }
Пример #5
0
        public async Task <int> UpdateAzureDevOpsPullRequestCommits(string patToken, TableStorageAuth tableStorageAuth,
                                                                    string organization, string project, string repositoryId, string pullRequestId,
                                                                    int numberOfDays, int maxNumberOfItems)
        {
            AzureDevOpsAPIAccess api = new AzureDevOpsAPIAccess();
            JArray items             = await api.GetAzureDevOpsPullRequestCommitsJArray(patToken, organization, project, repositoryId, pullRequestId);

            int itemsAdded = 0;
            TableStorageCommonDA tableDA = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableAzureDevOpsPRCommits);

            //Check each build to see if it's in storage, adding the items not in storage
            foreach (JToken item in items)
            {
                AzureDevOpsPRCommit pullRequestCommit = JsonConvert.DeserializeObject <AzureDevOpsPRCommit>(item.ToString());

                string partitionKey            = CreateAzureDevOpsPRCommitPartitionKey(organization, project, pullRequestId);
                string rowKey                  = pullRequestCommit.commitId;
                AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, item.ToString());
                if (await tableDA.AddItem(newItem) == true)
                {
                    itemsAdded++;
                }
            }

            return(itemsAdded);
        }
Пример #6
0
        public async Task <bool> UpdateDevOpsMonitoringEvent(TableStorageAuth tableStorageAuth, MonitoringEvent monitoringEvent)
        {
            string partitionKey            = monitoringEvent.PartitionKey;
            string rowKey                  = monitoringEvent.RowKey;
            string json                    = monitoringEvent.RequestBody;
            AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, json);
            TableStorageCommonDA   tableDA = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableMTTR);

            return(await tableDA.SaveItem(newItem));
        }
Пример #7
0
        //Note that this can't be async due to performance issues with Azure Storage when you retrieve items
        public JArray GetTableStorageItems(TableStorageAuth tableStorageAuth, string tableName, string partitionKey)
        {
            TableStorageCommonDA          tableDA = new TableStorageCommonDA(tableStorageAuth, tableName);
            List <AzureStorageTableModel> items   = tableDA.GetItems(partitionKey);
            JArray list = new JArray();

            foreach (AzureStorageTableModel item in items)
            {
                list.Add(JToken.Parse(item.Data));
            }
            return(list);
        }
Пример #8
0
        public async Task <int> UpdateChangeFailureRate(TableStorageCommonDA tableChangeFailureRateDA, ChangeFailureRateBuild newBuild, string partitionKey, bool forceUpdate = false)
        {
            int    itemsAdded = 0;
            string rowKey     = newBuild.Id;
            string json       = JsonConvert.SerializeObject(newBuild);
            AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, json);

            if (await tableChangeFailureRateDA.AddItem(newItem, forceUpdate) == true)
            {
                itemsAdded++;
            }
            return(itemsAdded);
        }
Пример #9
0
        public async Task <int> UpdateAzureDevOpsBuilds(string patToken, TableStorageAuth tableStorageAuth,
                                                        string organization, string project, string branch, string buildName, string buildId,
                                                        int numberOfDays, int maxNumberOfItems)
        {
            AzureDevOpsAPIAccess api = new AzureDevOpsAPIAccess();
            JArray items             = await api.GetAzureDevOpsBuildsJArray(patToken, organization, project);

            int itemsAdded = 0;
            TableStorageCommonDA tableBuildsDA            = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableAzureDevOpsBuilds);
            TableStorageCommonDA tableChangeFailureRateDA = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableChangeFailureRate);

            //Check each build to see if it's in storage, adding the items not in storage
            foreach (JToken item in items)
            {
                AzureDevOpsBuild build = JsonConvert.DeserializeObject <AzureDevOpsBuild>(item.ToString());

                //Save the build information for builds
                if (build.status == "completed")
                {
                    string partitionKey            = CreateBuildWorkflowPartitionKey(organization, project, buildName);
                    string rowKey                  = build.buildNumber;
                    AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, item.ToString());
                    if (await tableBuildsDA.AddItem(newItem) == true)
                    {
                        itemsAdded++;
                    }

                    //Save the build information for change failure rate
                    ChangeFailureRateBuild newBuild = new ChangeFailureRateBuild
                    {
                        Id                   = build.id,
                        Branch               = build.sourceBranch,
                        BuildNumber          = build.buildNumber,
                        StartTime            = build.queueTime,
                        EndTime              = build.finishTime,
                        BuildDurationPercent = build.buildDurationPercent,
                        Status               = build.status,
                        Url                  = build.url
                    };
                    itemsAdded += await UpdateChangeFailureRate(tableChangeFailureRateDA, newBuild, CreateBuildWorkflowPartitionKey(organization, project, buildName));
                }
            }

            return(itemsAdded);
        }
Пример #10
0
        public async Task <int> UpdateGitHubActionRuns(string clientId, string clientSecret, TableStorageAuth tableStorageAuth,
                                                       string owner, string repo, string branch, string workflowName, string workflowId,
                                                       int numberOfDays, int maxNumberOfItems)
        {
            GitHubAPIAccess api   = new GitHubAPIAccess();
            JArray          items = await api.GetGitHubActionRunsJArray(clientId, clientSecret, owner, repo, workflowId);

            int itemsAdded = 0;
            TableStorageCommonDA tableBuildDA             = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableGitHubRuns);
            TableStorageCommonDA tableChangeFailureRateDA = new TableStorageCommonDA(tableStorageAuth, tableStorageAuth.TableChangeFailureRate);

            //Check each build to see if it's in storage, adding the items not in storage
            foreach (JToken item in items)
            {
                GitHubActionsRun build = JsonConvert.DeserializeObject <GitHubActionsRun>(item.ToString());

                //Save the build information for builds
                if (build.status == "completed")
                {
                    string partitionKey            = CreateBuildWorkflowPartitionKey(owner, repo, workflowName);
                    string rowKey                  = build.run_number;
                    AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, item.ToString());
                    if (await tableBuildDA.AddItem(newItem) == true)
                    {
                        itemsAdded++;
                    }

                    //Save the build information for change failure rate
                    ChangeFailureRateBuild newBuild = new ChangeFailureRateBuild
                    {
                        Id                   = build.run_number,
                        Branch               = build.head_branch,
                        BuildNumber          = build.run_number,
                        StartTime            = build.created_at,
                        EndTime              = build.updated_at,
                        BuildDurationPercent = build.buildDurationPercent,
                        Status               = build.status,
                        Url                  = build.html_url
                    };
                    itemsAdded += await UpdateChangeFailureRate(tableChangeFailureRateDA, newBuild, CreateBuildWorkflowPartitionKey(owner, repo, workflowName));
                }
            }
            return(itemsAdded);
        }