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); }
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); }
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); }