public async Task <AzureDevOpsPR> GetAzureDevOpsPullRequest(string patToken, TableStorageAuth tableStorageAuth, string organization, string project, string repositoryId, 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.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableAzureDevOpsPRs, daTableStorage.CreateGitHubPRPartitionKey(organization, project)); } else { //Get the pull requests from the Azure DevOps API AzureDevOpsAPIAccess api = new AzureDevOpsAPIAccess(); list = await api.GetAzureDevOpsPullRequestsJArray(patToken, organization, project, repositoryId); } 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, 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); }
public void GHGetPRsDAIntegrationTest() { //Arrange TableStorageAuth tableStorageAuth = Common.GenerateTableAuthorization(Configuration); string owner = "samsmithnz"; string repo = "DevOpsMetrics"; //Act AzureTableStorageDA da = new AzureTableStorageDA(); JArray list = da.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableGitHubPRs, da.CreateGitHubPRPartitionKey(owner, repo)); //Assert Assert.IsTrue(list.Count >= 0); }