public RepoOMatic(MigrationEngine me)
 {
     migrationEngine   = me;
     sourceRepoService = me.Source.Collection.GetService <GitRepositoryService>();
     sourceRepos       = sourceRepoService.QueryRepositories(me.Source.Config.Project);
     allSourceRepos    = sourceRepoService.QueryRepositories("");
     //////////////////////////////////////////////////
     targetRepoService = me.Target.Collection.GetService <GitRepositoryService>();
     targetRepos       = targetRepoService.QueryRepositories(me.Target.Config.Project);
     allTargetRepos    = targetRepoService.QueryRepositories("");
     gitWits           = new List <string>
     {
         "Branch",
         "Fixed in Commit",
         "Pull Request"
     };
 }
Ejemplo n.º 2
0
 public GitRepositoryEnricher(IMigrationEngine me)
 {
     migrationEngine   = me;
     sourceRepoService = me.Source.GetService <GitRepositoryService>();
     sourceRepos       = sourceRepoService.QueryRepositories(me.Source.Config.Project);
     allSourceRepos    = sourceRepoService.QueryRepositories("");
     //////////////////////////////////////////////////
     targetRepoService = me.Target.GetService <GitRepositoryService>();
     targetRepos       = targetRepoService.QueryRepositories(me.Target.Config.Project);
     allTargetRepos    = targetRepoService.QueryRepositories("");
     gitWits           = new List <string>
     {
         "Branch",
         "Fixed in Commit",
         "Pull Request",
         "Fixed in Changeset"        //TFVC
     };
 }
Ejemplo n.º 3
0
        public TfsGitRepositoryEnricher(IMigrationEngine engine, ILogger <TfsGitRepositoryEnricher> logger) : base(engine, logger)
        {
            _Engine = engine ?? throw new ArgumentNullException(nameof(engine));
            _Logger = logger ?? throw new ArgumentNullException(nameof(logger));

            sourceRepoService = engine.Source.GetService <GitRepositoryService>();
            sourceRepos       = sourceRepoService.QueryRepositories(engine.Source.Config.AsTeamProjectConfig().Project);
            allSourceRepos    = sourceRepoService.QueryRepositories("");
            //////////////////////////////////////////////////
            targetRepoService = engine.Target.GetService <GitRepositoryService>();
            targetRepos       = targetRepoService.QueryRepositories(engine.Target.Config.AsTeamProjectConfig().Project);
            allTargetRepos    = targetRepoService.QueryRepositories("");
            gitWits           = new List <string>
            {
                "Branch",
                "Fixed in Commit",
                "Pull Request",
                "Fixed in Changeset"        //TFVC
            };
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Downloads the latest version of file from TFS-Git server
        /// </summary>
        /// <param name="fullPath"></param>
        /// <returns></returns>
        public string DownloadLatestVersion(string fullPath)
        {
            GitRepositoryService grs = new GitRepositoryService();

            grs.Initialize(TeamColl);

            var gitRepo = grs.QueryRepositories(SettingTFS.TeamProjectName).FirstOrDefault(x => x.Name == SettingTFS.RepoName);

            if (gitRepo == null)
            {
                throw new Exception("No repo found");
            }

            var tmpUrl = string.Format(urlLatestFileVersion, TeamColl.Uri, gitRepo.Id, fullPath);

            var rawJson = HttpGet(tmpUrl);

            return(rawJson);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// !!! DANGER : if you are using "pull request" and "push" together there is a catch.
        /// WebApi finds changes between "pull request"s or "push"es.
        /// Because of this, first you make "pull request" then "push", at last "pull request"; api brings last"pull request" and "push" changes together.
        /// Like they pulled at the same time.
        /// </summary>
        /// <returns></returns>
        public List <TFSFileState> GitPendingChangeFiles()
        {
            var filesChanged = new List <TFSFileState>();

            GitRepositoryService grs = new GitRepositoryService();

            grs.Initialize(TeamColl);

            var gitRepo = grs.QueryRepositories(SettingTFS.TeamProjectName).FirstOrDefault(x => x.Name == SettingTFS.RepoName);

            if (gitRepo == null)
            {
                return(new List <TFSFileState>());
            }

            string tmpUrl  = string.Format(urlFindCommitsFiles, TeamColl.Uri, gitRepo.Id, SettingTFS.BuildSourceVersion);
            string rawJson = HttpGet(tmpUrl);

            if (string.IsNullOrEmpty(rawJson))
            {
                return(new List <TFSFileState>());
            }

            var gitCommitData = JsonConvert.DeserializeObject <GitCommitRef>(rawJson);
            var isExist       = gitCommitData?.Changes?.Any() ?? false;

            if (!isExist)
            {
                return(new List <TFSFileState>());
            }

            foreach (var item in gitCommitData.Changes)
            {
                var tmpState = item.ChangeType.ToSourceControlFileState();

                filesChanged.Add(new TFSFileState(item.Item.Path, tmpState));
            }

            return(filesChanged);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Sample method on how to extracts the git version control permissions.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="groups">The groups.</param>
        /// <param name="userIdentity">The user identity.</param>
        /// <param name="projectSecurityToken">The project security token.</param>
        /// <param name="identityManagementService">The identityManagementService.</param>
        /// <param name="vcs">The VCS.</param>
        /// <param name="gitService">The git service.</param>
        /// <returns>List of Permissions</returns>
        private static List <GitPermission> ExtractGitVersionControlPermissions(
            ISecurityService server,
            List <string> groups,
            TeamFoundationIdentity userIdentity,
            string projectSecurityToken,
            IIdentityManagementService identityManagementService,
            VersionControlServer vcs,
            GitRepositoryService gitService)
        {
            Console.WriteLine("== Extract Git Version Control Permissions ==");
            SecurityNamespace     gitVersionControlSecurityNamespace = server.GetSecurityNamespace(Helpers.GetSecurityNamespaceId(PermissionScope.GitSourceControl, server));
            IList <GitRepository> gitProjectRepoService = gitService.QueryRepositories(projectSecurityToken);

            var groupsIdentities = new List <TeamFoundationIdentity>(groups.Count);

            foreach (string group in groups)
            {
                TeamFoundationIdentity groupIdentity = identityManagementService.ReadIdentity(
                    IdentitySearchFactor.Identifier, group, MembershipQuery.None,
                    ReadIdentityOptions.IncludeReadFromSource);
                groupsIdentities.Add(groupIdentity);
            }

            var results = new List <GitPermission>();

            foreach (GitRepository repo in gitProjectRepoService)
            {
                string primaryBranch = (repo.DefaultBranch ?? "(no default branch)").StartsWith("refs/heads/") ?
                                       repo.DefaultBranch.Substring(11) :
                                       repo.DefaultBranch;

                Console.WriteLine("  -- Repo: {0} branch {1}", repo.Name, primaryBranch);

                // Repository Security Token is repoV2/TeamProjectId/RepositoryId
                string repoIdToken = string.Format("repoV2{0}{1}{2}{3}",
                                                   gitVersionControlSecurityNamespace.Description.SeparatorValue,
                                                   repo.ProjectReference.Id,
                                                   gitVersionControlSecurityNamespace.Description.SeparatorValue,
                                                   repo.Id);

                AccessControlList versionControlAccessList =
                    gitVersionControlSecurityNamespace.QueryAccessControlList(
                        repoIdToken,
                        new List <IdentityDescriptor> {
                    userIdentity.Descriptor
                },
                        true);

                var gitVersionControlPermissions = new List <Permission>();
                foreach (AccessControlEntry ace in versionControlAccessList.AccessControlEntries)
                {
                    foreach (AclAndName aclAndName in Helpers.EnumerateAcls(ace, false))
                    {
                        if (aclAndName.Acl != 0)
                        {
                            string versionControlPermissions = ((EnumerationsList.GitPermissions)aclAndName.Acl).ToString();
                            gitVersionControlPermissions.AddRange(
                                Helpers.GetActionDetailsByName(versionControlPermissions, aclAndName.Name,
                                                               PermissionScope.GitSourceControl));
                        }
                    }
                }

                foreach (TeamFoundationIdentity groupIdentity in groupsIdentities)
                {
                    AccessControlList groupAccessList =
                        gitVersionControlSecurityNamespace.QueryAccessControlList(
                            repoIdToken,
                            new List <IdentityDescriptor> {
                        groupIdentity.Descriptor
                    },
                            true);

                    foreach (AccessControlEntry ace in groupAccessList.AccessControlEntries)
                    {
                        foreach (AclAndName aclAndName in Helpers.EnumerateAcls(ace, true))
                        {
                            if (aclAndName.Acl != 0)
                            {
                                string versionControlPermissions = ((EnumerationsList.GitPermissions)aclAndName.Acl).ToString();
                                gitVersionControlPermissions.AddRange(
                                    Helpers.GetActionDetailsByName(versionControlPermissions, aclAndName.Name,
                                                                   PermissionScope.GitSourceControl));
                            }
                        }
                    }
                }

                List <Permission> modifiedPermissions = Helpers.RemoveDuplicatePermissionsAndCombineGroups(gitVersionControlPermissions);
                results.AddRange(modifiedPermissions.Select(perm => new GitPermission(perm, repo.Name, primaryBranch)));
            }

            return(results);
        }