Example #1
0
def show_migration_status(args):
    """
    List authorised repos for teams
    """
    with cli.catch_api_errors():
        src = Organisation(args.src)
        dest = Organisation(args.dest)

    repos_dest = list(dest.list_repos())
    lod = [ ] # "list of dicts"

    for repo_src in src.list_repos():
            (migrated,repo_dest) = exists_in(repo_src, repos_dest)
            dest_private = str(repo_dest['private']) if migrated else 'N/A'
            lod.append({
                'NAME':repo_src['name'], 
                'MIGRATED':str(migrated), 
                'SRC_PRIVATE':str(repo_src['private']),
                'DEST_PRIVATE':dest_private})

    # TODO:
    # Technically you should be able to do something like:
    # query_lod(lod, sort_keys=('MIGRATED', 'NAME'))) but I can't seem
    # to get it to work
    query_results = query_lod(lod, lambda r:r['MIGRATED']=='True' )

    pattern = '{0:45s} {1:10s} {2:11s} {3:11s}'
    inputs = ['NAME', 'MIGRATED', 'SRC_PRIVATE', 'DEST_PRIVATE']

    print(pattern.format(*inputs))
    for row in query_results:
        print(pattern.format(*[row[r] for r in inputs]))
def list_members(args):
    """
    List all members of an organisation along with the teams they're in.
    """
    with cli.catch_api_errors():
        org = Organisation(args.org)

        members = defaultdict(list)
        for team in org.list_teams():
            for member in org.list_team_members(team):
                members[member['login']].append(team['name'])

        writer = csv.writer(sys.stdout, delimiter=',', quotechar='"')

        for member in org.list_members():
            if member['type'] == 'User':
                writer.writerow([member['login']] + members[member['login']])
Example #3
0
def list_members(args):
    """
    List all members of an organisation along with the teams they're in.
    """
    with cli.catch_api_errors():
        org = Organisation(args.org)

        members = defaultdict(list)
        for team in org.list_teams():
            for member in org.list_team_members(team):
                members[member["login"]].append(team["name"])

        writer = csv.writer(sys.stdout, delimiter=",", quotechar='"')

        for member in org.list_members():
            if member["type"] == "User":
                writer.writerow([member["login"]] + members[member["login"]])
Example #4
0
def show_migration_status(args):
    """
    List authorised repos for teams
    """
    with cli.catch_api_errors():
        src = Organisation(args.src)
        dest = Organisation(args.dest)

    repos_dest = list(dest.list_repos())
    lod = []  # "list of dicts"

    for repo_src in src.list_repos():
        (migrated, repo_dest) = exists_in(repo_src, repos_dest)
        dest_private = str(repo_dest['private']) if migrated else 'N/A'
        lod.append({
            'NAME': repo_src['name'],
            'MIGRATED': str(migrated),
            'SRC_PRIVATE': str(repo_src['private']),
            'DEST_PRIVATE': dest_private
        })

    # TODO:
    # Technically you should be able to do something like:
    # query_lod(lod, sort_keys=('MIGRATED', 'NAME'))) but I can't seem
    # to get it to work
    query_results = query_lod(lod, lambda r: r['MIGRATED'] == 'True')

    pattern = '{0:45s} {1:10s} {2:11s} {3:11s}'
    inputs = ['NAME', 'MIGRATED', 'SRC_PRIVATE', 'DEST_PRIVATE']

    print(pattern.format(*inputs))
    for row in query_results:
        print(pattern.format(*[row[r] for r in inputs]))
Example #5
0
 def test_str(self):
     o1 = Organisation('foo')
     assert_equal(str(o1), '<Organisation foo>')
     o2 = Organisation('enterprise:foo')
     assert_equal(str(o2), '<Organisation enterprise:foo>')
Example #6
0
class TestOrganisation(object):

    def setup(self):
        self.patcher = patch('ghtools.github.organisation.make_client')
        self.mock_client_cons = self.patcher.start()
        self.mock_client = self.mock_client_cons.return_value
        self.o = Organisation('foo')

    def teardown(self):
        self.patcher.stop()

    def test_add_team_member(self):
        self.mock_client.put.return_value.json.return_value = {'id': 456}
        self.o.add_team_member({'id': 123}, 'joebloggs')
        self.mock_client.put.assert_called_with('/teams/123/members/joebloggs', data=' ')

    def test_add_team_repo(self):
        self.mock_client.put.return_value.json.return_value = {'id': 456}
        self.o.add_team_repo({'id': 123}, 'myproj')
        self.mock_client.put.assert_called_with('/teams/123/repos/foo/myproj', data=' ')

    def test_create_repo(self):
        repo = {
            'name': 'reponame',
            'description': 'My description',
            'homepage': 'http://google.com',
            'private': False,
            'has_issues': False,
            'has_wiki': False,
            'has_downloads': False,
            'not_included': "I shouldn't be included",
        }

        repo_passed = repo.copy()
        del repo_passed['not_included']

        self.o.create_repo(repo)
        self.mock_client.post.assert_called_with('/orgs/foo/repos', data=repo_passed)

    def test_create_team(self):
        self.mock_client.post.return_value.json.return_value = {'id': 456}
        res = self.o.create_team({'id': 123})
        self.mock_client.post.assert_called_with('/orgs/foo/teams', data={'id': 123})
        assert_equal(res, {'id': 456})

    def test_get_repo(self):
        self.o.get_repo('bar')
        self.mock_client.get.assert_called_with('/repos/foo/bar')

    def test_get_repo_nickname(self):
        o = Organisation('enterprise:foo')
        o.get_repo('bar')
        self.mock_client.get.assert_called_with('/repos/foo/bar')

    def test_list_members(self):
        self.o.list_members()
        self.mock_client.paged_get.assert_called_with('/orgs/foo/members')

    def test_list_repos(self):
        self.o.list_repos()
        self.mock_client.paged_get.assert_called_with('/orgs/foo/repos')

    def test_list_teams(self):
        self.o.list_teams()
        self.mock_client.paged_get.assert_called_with('/orgs/foo/teams')

    def test_list_team_members(self):
        self.o.list_team_members({'id': 123})
        self.mock_client.paged_get.assert_called_with('/teams/123/members')

    def test_list_team_repos(self):
        self.o.list_team_repos({'id': 123})
        self.mock_client.paged_get.assert_called_with('/teams/123/repos')

    def test_str(self):
        o1 = Organisation('foo')
        assert_equal(str(o1), '<Organisation foo>')
        o2 = Organisation('enterprise:foo')
        assert_equal(str(o2), '<Organisation enterprise:foo>')
Example #7
0
 def test_get_repo_nickname(self):
     o = Organisation('enterprise:foo')
     o.get_repo('bar')
     self.mock_client.get.assert_called_with('/repos/foo/bar')
Example #8
0
 def setup(self):
     self.patcher = patch('ghtools.github.organisation.make_client')
     self.mock_client_cons = self.patcher.start()
     self.mock_client = self.mock_client_cons.return_value
     self.o = Organisation('foo')
Example #9
0
def migrate_teams(args):
    with cli.catch_api_errors():
        src = Organisation(args.src)
        dst = Organisation(args.dst)

        teams.migrate(src, dst, args.mapping)