@@ -0,0 +1,2278 @@
+from django.contrib.auth.models import User%0Afrom django.core.management.base import BaseCommand%0A%0Afrom readthedocs.oauth.tasks import sync_remote_repositories%0A%0A%0Aclass Command(BaseCommand):%0A    help = %22Sync OAuth RemoteRepository and RemoteOrganization%22%0A%0A    def add_arguments(self, parser):%0A        parser.add_argument(%0A            '--queue',%0A            type=str,%0A            default='resync-oauth',%0A            help='Celery queue name.',%0A        )%0A        parser.add_argument(%0A            '--users',%0A            nargs='*',%0A            type=str,%0A            default=%5B%5D,%0A            help='Re-sync VCS provider data for specific users only.',%0A        )%0A        parser.add_argument(%0A            '--skip-users',%0A            nargs='*',%0A            type=str,%0A            default=%5B%5D,%0A            help='Skip re-sync VCS provider data for specific users.',%0A        )%0A        parser.add_argument(%0A            '--max-users',%0A            type=int,%0A            default=100,%0A            help='Maximum number of users that should be synced.',%0A        )%0A%0A    def handle(self, *args, **options):%0A        queue = options.get('queue')%0A        sync_users = options.get('users')%0A        skip_users = options.get('skip_users')%0A        max_users = options.get('max_users')%0A%0A        # Filter users who have social accounts connected%0A        # and has no remote repository relations%0A        users = User.objects.filter(%0A            socialaccount__isnull=False,%0A            remote_repository_relations__isnull=True%0A        ).distinct()%0A%0A        if sync_users:%0A            users = users.filter(username__in=sync_users)%0A%0A        if skip_users:%0A            users = users.exclude(username__in=skip_users)%0A%0A        users_to_sync = users.values_list('id', flat=True)%5B:max_users%5D%0A%0A        self.stdout.write(%0A            self.style.SUCCESS(%0A                'Found %25s user(s) with the given parameters' %25 users.count()%0A            )%0A        )%0A        self.stdout.write(%0A            self.style.SUCCESS(%0A                'Re-syncing VCS Providers for %25s user(s)' %25 len(users_to_sync)%0A            )%0A        )%0A%0A        for user_id in users_to_sync:%0A            # Trigger Sync Remote Repository Tasks for users%0A            sync_remote_repositories.apply_async(%0A                args=%5Buser_id%5D, queue=queue%0A            )%0A

Add manafement command to Sync RemoteRepositories and RemoteOrganizations