Exemplo n.º 1
0
        public static (Project project, Repo repo) ImportProject(User me, string originId)
        {
            var  externalRepo = GetClient().Repository.Get(Convert.ToInt64(originId)).Result;
            User creator      = null;

            if (me != null)
            {
                var token = me.ServiceAccessToken(ServiceType.GitHub);

                if (token.origin_user_id == "")
                {
                    GitHubUserUtils.UpdateOriginUserId(me);
                }

                var originUserId = token.origin_user_id;

                creator = externalRepo.Owner.Id == Convert.ToInt64(originUserId) ? me : null;
            }

            Repo repository = RepoRepository.CreateAndGet(
                me, externalRepo.Name, externalRepo.HtmlUrl, RepoServiceType.GitHub, externalRepo.Id.ToString()
                );

            var project = ProjectRepository.FindOrCreate(repository.title, creator, repository);

            if (externalRepo.Description != null)
            {
                project.UpdateCol("description", externalRepo.Description);
            }

            return(project, repository);
        }
Exemplo n.º 2
0
        public static (bool finished, string originUserId) UpdateOriginUserId(User me)
        {
            var serviceAccessToken = me.ServiceAccessToken(ServiceType.GitLab);

            if (serviceAccessToken == null)
            {
                return(false, "");
            }

            var client = new GitLabClient(serviceAccessToken.access_token);

            client.SetAuthorizedUser();

            var originUserId = client.User.Id.ToString();

            serviceAccessToken.UpdateCol("origin_user_id", originUserId);

            return(true, originUserId);
        }
Exemplo n.º 3
0
        public static ExternalRepo[] GetUserRepositories(User user)
        {
            var token = user.ServiceAccessToken(ServiceType.GitHub);

            if (token == null)
            {
                return(new ExternalRepo[] { });
            }

            var gitHubClient = GetClient();

            gitHubClient.Credentials = new Credentials(token.access_token);

            var gitHubUser = gitHubClient.User.Current().Result;

            var repos = gitHubClient.Repository.GetAllForUser(gitHubUser.Login).Result;

            return(ExternalRepoTransformer.CreateFromMany(user, repos));
        }
Exemplo n.º 4
0
        public static (bool finished, string originUserId) UpdateOriginUserId(User me)
        {
            var serviceAccessToken = me.ServiceAccessToken(ServiceType.GitHub);

            if (serviceAccessToken == null)
            {
                return(false, "");
            }

            var client = new GitHubClient(new ProductHeaderValue("GitCom"));

            client.Credentials = new Credentials(serviceAccessToken.access_token);

            var githubUser = client.User.Current().Result;

            var originUserId = githubUser.Id.ToString();

            serviceAccessToken.UpdateCol("origin_user_id", originUserId);

            return(true, originUserId);
        }