Example #1
0
        /// <summary>
        /// Create new git repo
        /// </summary>
        /// <param name="TeamProjectName"></param>
        /// <param name="GitNewRepoName"></param>
        /// <param name="ParentRepo"></param>
        private static void CreateGitRepo(string TeamProjectName, string GitNewRepoName, string ParentRepo = null)
        {
            GitRepository newRepo;

            if (ParentRepo != null)
            {
                GitRepositoryCreateOptions newGitRepository = new GitRepositoryCreateOptions();
                newGitRepository.Name = GitNewRepoName;
                GitRepository parent = GitClient.GetRepositoryAsync(TeamProjectName, ParentRepo).Result;
                newGitRepository.ParentRepository    = new GitRepositoryRef();
                newGitRepository.ParentRepository.Id = parent.Id;
                newGitRepository.ParentRepository.ProjectReference = parent.ProjectReference;
                newRepo = GitClient.CreateRepositoryAsync(newGitRepository, TeamProjectName, "refs/heads/master").Result;
            }
            else
            {
                newRepo      = new GitRepository();
                newRepo.Name = GitNewRepoName;
                newRepo      = GitClient.CreateRepositoryAsync(newRepo, TeamProjectName).Result;
            }


            Console.WriteLine("===============Created New Repo===============================");
            PrintRepoInfo(newRepo);
            Console.WriteLine("==============================================================");
        }
Example #2
0
        /// <summary>
        /// Creates a repository Fork through the VSTS <see cref="GitHttpClient"/>.
        /// </summary>
        /// <param name="client">The <see cref="GitHttpClient"/> used to create the Fork.</param>
        /// <param name="vstsCollectionId">The target collection ID where we are creating the fork on.</param>
        /// <param name="vstsTargetProjectId">The target project ID where we are creating the fork on.</param>
        /// <param name="sourceRepo">The origin repo for the Fork.</param>
        /// <param name="targetRepo">name of the tenant fork</param>
        /// <returns>The async <see cref="Task{GitRepository}"/> wrapper with pre-existing or new repo</returns>
        internal static async Task <GitRepository> CreateForkIfNotExists(this GitHttpClient client, string vstsCollectionId, string vstsTargetProjectId, GitRepository sourceRepo, string targetRepo)
        {
            var repo = await client.LoadGitRepositoryIfExists(targetRepo);

            if (repo != null)
            {
                return(repo);
            }

            return(await client.CreateRepositoryAsync(
                       new GitRepositoryCreateOptions
            {
                Name = targetRepo,
                ProjectReference = new TeamProjectReference {
                    Id = Guid.Parse(vstsTargetProjectId)
                },
                ParentRepository = new GitRepositoryRef
                {
                    Id = sourceRepo.Id,
                    ProjectReference = new TeamProjectReference {
                        Id = sourceRepo.ProjectReference.Id
                    },
                    Collection = new TeamProjectCollectionReference {
                        Id = Guid.Parse(vstsCollectionId)
                    }
                }
            }));
        }
Example #3
0
        public async Task CreateRepository(string repositoryName)
        {
            _vstsGitClient = _connection.GetClient <GitHttpClient>();

            await _vstsGitClient.CreateRepositoryAsync(new GitRepository()
            {
                Name = repositoryName
            }, Project.Value);
        }
Example #4
0
        public async Task <GitRepository> CreateRepo(string newRepoName, string nameOfProjectToCopyFrom, string nameOfRepoToCopyFrom)
        {
            VssConnection connection = this.Context.Connection;
            GitHttpClient gitClient  = connection.GetClient <GitHttpClient>();

            var repoToCopyFrom = await gitClient.GetRepositoryAsync(nameOfProjectToCopyFrom, nameOfRepoToCopyFrom);

            return(await gitClient.CreateRepositoryAsync(new GitRepositoryCreateOptions { Name = newRepoName, ParentRepository = repoToCopyFrom.ParentRepository, ProjectReference = repoToCopyFrom.ProjectReference }));
        }
 internal static void CreateRepositories(GitHttpClient gitClient)
 {
     for (int i = 0; i < 300; i++)
     {
         var repo = gitClient.CreateRepositoryAsync(new GitRepository {
             Name             = $"StressRepo{i}",
             ProjectReference = new TeamProjectReference {
                 Id = Config.TargetProject
             }
         }).Result;
     }
 }