static Version GetVersionNumber(GitBranchStats b) { // Sort main to the top, always if (b.Name == "main") { return(new Version(999, 9999)); } else if (Version.TryParse(b.Name.Substring(5), out var version)) { return(version); } return(new Version(0, 0)); }
static void Main(string[] args) { var credentials = new VssAadCredential(); var messageHandler = new VssHttpMessageHandler(credentials, new VssHttpRequestSettings()); Uri uri = new Uri(@"https://microsoft.visualstudio.com/"); GitHttpClient gitHttpClient = new GitHttpClient(uri, messageHandler.Credentials); var Repositories = gitHttpClient.GetRepositoriesAsync().Result; GitRepository repository = Repositories.FirstOrDefault(r => r.Name.ToLowerInvariant() == "Localization".ToLowerInvariant()); var gitBranchStatuss = gitHttpClient.GetBranchesAsync(repository.Id).Result; GitBranchStats gitBranchStatus = gitBranchStatuss.FirstOrDefault(branch => branch.Name.ToLowerInvariant() == "master"); var descriptor = new GitVersionDescriptor() { Version = gitBranchStatus.Name, VersionOptions = GitVersionOptions.None, VersionType = GitVersionType.Branch }; //GitItem item = gitHttpClient.GetItemAsync(repositoryId: repository.Id, path: "/intl/af-za/loc/windows/lcl/aad/brokerplugin/microsoft.aad.brokerplugin.dll.lcl", scopePath: "/intl/af-za/loc/windows/lcl/aad/brokerplugin/microsoft.aad.brokerplugin.dll.lcl", recursionLevel: VersionControlRecursionType.OneLevel, includeContentMetadata: true, latestProcessedChange: true, download: true, versionDescriptor: descriptor, userState: null, cancellationToken: new CancellationToken()).Result; VersionControlProjectInfo vvvvvv = new VersionControlProjectInfo(); List <GitItem> items = gitHttpClient.GetItemsAsync(repositoryId: repository.Id, scopePath: "/intl/af-za/loc/windows/lcl/aad/brokerplugin/microsoft.aad.brokerplugin.dll.lcl", recursionLevel: VersionControlRecursionType.OneLevel, includeContentMetadata: true, latestProcessedChange: true, download: true, includeLinks: false, versionDescriptor: descriptor, userState: null, cancellationToken: new CancellationToken()).Result; List <GitCommitRef> aaaa = gitHttpClient.GetCommitsAsync(repositoryId: repository.Id, searchCriteria: new GitQueryCommitsCriteria(), skip: null, top: null, userState: null, cancellationToken: new CancellationToken()).Result; GitCommitChanges gitCommitChanges = gitHttpClient.GetChangesAsync(items[0].CommitId, repositoryId: repository.Id, top: null, skip: null, userState: null, cancellationToken: new CancellationToken()).Result; Stream ssss = gitHttpClient.GetItemContentAsync(repositoryId: repository.Id, path: items[0].Path, recursionLevel: VersionControlRecursionType.None, includeContentMetadata: true, latestProcessedChange: true, download: true, versionDescriptor: descriptor, userState: null, cancellationToken: new CancellationToken()).Result; using (MemoryStream memoryStream = new MemoryStream()) { ssss.CopyTo(memoryStream); // Use StreamReader to read MemoryStream created from byte array using (StreamReader streamReader = new StreamReader(new MemoryStream(memoryStream.ToArray()))) { string fileString = streamReader.ReadToEnd(); } } }
public async Task EvaluateAsync_NotBehindBaseBranch_ShouldSetStatusToSuceeded() { var pullRequest = new GitPullRequest { SourceRefName = "feature/branch" }; var branchStats = new GitBranchStats { BehindCount = 0 }; _gitClientMock.Setup(g => g.GetBranchAsync(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <GitVersionDescriptor>(), It.IsAny <object>(), It.IsAny <CancellationToken>())) .ReturnsAsync(branchStats); await EvaluateAsync(pullRequest, GitStatusState.Succeeded); _gitClientMock.Verify(g => g.GetBranchAsync(pullRequest.Repository.Id, pullRequest.SourceRefName, It.IsAny <GitVersionDescriptor>(), It.IsAny <object>(), It.IsAny <CancellationToken>()), Times.Once); }
private static GitVersionDescriptor GetVersionRef(GitBranchStats branch) => new GitVersionDescriptor { Version = branch.Name, VersionType = GitVersionType.Branch, };