Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public async Task <GitHubPR> GetGitHubPullRequest(string clientId, string clientSecret, TableStorageAuth tableStorageAuth, 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.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableGitHubPRs, daTableStorage.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.º 4
0
        public async Task <List <GitHubActionsRun> > GetGitHubActionRuns(string clientId, string clientSecret, TableStorageAuth tableStorageAuth,
                                                                         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.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableGitHubRuns, daTableStorage.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.º 5
0
        public async Task <int> UpdateGitHubActionRunsInStorage(string clientId, string clientSecret, TableStorageConfiguration tableStorageConfig,
                                                                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);

            Debug.WriteLine($"{items.Count} builds found for {owner}/{repo}/{workflowName}");

            int itemsAdded = 0;
            TableStorageCommonDA tableBuildDA             = new TableStorageCommonDA(tableStorageConfig, tableStorageConfig.TableGitHubRuns);
            TableStorageCommonDA tableChangeFailureRateDA = new TableStorageCommonDA(tableStorageConfig, tableStorageConfig.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            = PartitionKeys.CreateBuildWorkflowPartitionKey(owner, repo, workflowName);
                    string rowKey                  = build.run_number;
                    AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, item.ToString());
                    if (await tableBuildDA.AddItem(newItem) == true)
                    {
                        itemsAdded++;
                    }
                    //Debug.WriteLine($"Processing build {build.run_number} with items adding={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, PartitionKeys.CreateBuildWorkflowPartitionKey(owner, repo, workflowName));

                    //Debug.WriteLine($"UpdateChangeFailureRate for build {build.run_number} with items adding={itemsAdded}");
                }
            }
            Debug.WriteLine($"{items.Count} builds updated for {owner}/{repo}/{workflowName}");
            return(itemsAdded);
        }
Ejemplo n.º 6
0
        public async Task <List <GitHubPRCommit> > GetGitHubPullRequestCommits(string clientId, string clientSecret, TableStorageAuth tableStorageAuth, 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.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableGitHubPRCommits, daTableStorage.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);
        }