Example #1
0
        public WikiV2 UpdateWiki()
        {
            VssConnection  connection = this.Context.Connection;
            GitHttpClient  gitClient  = connection.GetClient <GitHttpClient>();
            WikiHttpClient wikiClient = connection.GetClient <WikiHttpClient>();

            WikiV2 codeWiki = Helpers.FindOrCreateCodeWiki(this.Context);

            // Get the versions in that wiki
            List <GitVersionDescriptor> versions = codeWiki.Versions.ToList();

            // Append the new version
            List <GitBranchStats> branches = gitClient.GetBranchesAsync(codeWiki.ProjectId, codeWiki.RepositoryId).SyncResult();

            foreach (var branch in branches)
            {
                versions.Add(new GitVersionDescriptor()
                {
                    Version = branch.Name
                });
            }

            WikiUpdateParameters updateParams = new WikiUpdateParameters()
            {
                Versions = versions
            };

            WikiV2 updatedCodeWiki = wikiClient.UpdateWikiAsync(updateParams, codeWiki.ProjectId, codeWiki.Name).SyncResult();

            Context.Log("Updated wiki with name '{0}' in project '{1}'", updatedCodeWiki.Name, updatedCodeWiki.ProjectId);
            Context.Log("Updated versions are : {0}", string.Join(",", updatedCodeWiki.Versions.Select(v => v.Version)));

            return(updatedCodeWiki);
        }
Example #2
0
        public async Task <int?> UpdateReferencesAndCreatePullRequest(string repoName, string baseBranchName, IPackageHandler handler, string packageVersion)
        {
            var replacer = new TemplateReplacer(handler.Name, packageVersion);
            var repo     = await _gitClient.GetRepositoryAsync(_projectId, repoName).ConfigureAwait(false);

            Log($"Received info about repo {repoName}.");

            var branches = await _gitClient.GetBranchesAsync(repo.Id).ConfigureAwait(false);

            var targetBranchName = GetTargetBranchName(replacer);

            var branch =
                branches.FirstOrDefault(m => string.Equals(m.Name, targetBranchName, StringComparison.InvariantCultureIgnoreCase)) ??
                branches.FirstOrDefault(m => string.Equals(m.Name, baseBranchName, StringComparison.InvariantCultureIgnoreCase)) ??
                branches.First();

            var lastCommit = branch.Commit.CommitId;
            var versionRef = GetVersionRef(branch);

            Log($"Received info about branches ({string.Join(", ", branches.Select(m => m.Name))}). Selected '{branch.Name}'.");

            var items = await _gitClient.GetItemsAsync(_projectId, repo.Id, versionDescriptor : versionRef, recursionLevel : VersionControlRecursionType.Full).ConfigureAwait(false);

            var changes = await GetChanges(repo.Id, handler, packageVersion, versionRef, items).ConfigureAwait(false);

            return(await CreatePullRequestIfChanged(repo.Id, changes, lastCommit, branch.Name, targetBranchName, replacer).ConfigureAwait(false));
        }
Example #3
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();
                }
            }
        }
Example #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            VssBasicCredential   credential   = new VssBasicCredential(string.Empty, textBox1.Text);
            GitHttpClient        gitClient    = new GitHttpClient(new Uri(textBox2.Text), credential);
            List <GitRepository> repositories = gitClient.GetRepositoriesAsync((bool?)null, null).GetAwaiter().GetResult();
            List <KeyValuePair <GitRepository, Task <List <GitBranchStats> > > > branchStatsTasks = new List <KeyValuePair <GitRepository, Task <List <GitBranchStats> > > >();
            List <KeyValuePair <GitRepository, GitBranchStats> > branches = new List <KeyValuePair <GitRepository, GitBranchStats> >();
            StringBuilder builder      = new StringBuilder();
            StringBuilder fetchBuilder = new StringBuilder();

            foreach (GitRepository repo in repositories)
            {
                builder.AppendLine("git clone " + repo.Url + " " + repo.Name);
                branchStatsTasks.Add(new KeyValuePair <GitRepository, Task <List <GitBranchStats> > >(repo, gitClient.GetBranchesAsync(repo.Id)));
            }
            textBox3.Text = builder.ToString();

            foreach (KeyValuePair <GitRepository, Task <List <GitBranchStats> > > task in branchStatsTasks)
            {
                branches.AddRange(task.Value.GetAwaiter().GetResult().Where(o => o.Name.ToLowerInvariant() == "developer" || o.Name == task.Key.Name).Select(o => new KeyValuePair <GitRepository, GitBranchStats>(task.Key, o)));
            }

            foreach (KeyValuePair <GitRepository, GitBranchStats> branch in branches)
            {
                fetchBuilder.AppendLine("git -C ./" + branch.Key.Name + " fetch origin " + branch.Value.Name + ":" + branch.Value.Name);
            }
            textBox4.Text = fetchBuilder.ToString();
        }