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); }
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 <List <AzureDevOpsBuild> > GetAzureDevOpsBuilds(string patToken, TableStorageAuth tableStorageAuth, 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.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableAzureDevOpsBuilds, daTableStorage.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); }
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); }
public async Task <List <AzureDevOpsPRCommit> > GetAzureDevOpsPullRequestCommits(string patToken, TableStorageAuth tableStorageAuth, string organization, string project, string repositoryId, string pullRequestId, 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.TableAzureDevOpsPRCommits, daTableStorage.CreateAzureDevOpsPRCommitPartitionKey(organization, project, pullRequestId)); } else { //Get the commits from the Azure DevOps API AzureDevOpsAPIAccess api = new AzureDevOpsAPIAccess(); list = await api.GetAzureDevOpsPullRequestCommitsJArray(patToken, organization, project, repositoryId, pullRequestId); } List <AzureDevOpsPRCommit> commits = JsonConvert.DeserializeObject <List <AzureDevOpsPRCommit> >(list.ToString()); return(commits); }