Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
github: allow enabling repos from the UI that are out of scope
Browse files Browse the repository at this point in the history
Refs GH-16
  • Loading branch information
dcramer committed Aug 24, 2017
1 parent 8534f66 commit 0089562
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
35 changes: 34 additions & 1 deletion tests/zeus/api/resources/test_github_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,38 @@ def test_list_github_repos(client, default_login, default_user, default_identity
data = resp.json()
assert len(data) == 1
assert data[0]['name'] == 'getsentry/zeus'
# TODO(dcramer): we really should have an active test as its much more critical
assert not data[0]['active']


def test_list_github_active_repo_within_scope(
client, default_login, default_user, default_identity, default_repo, default_repo_access):
responses.add(
'GET',
'https://api.github.com/user/repos?type=owner',
match_querystring=True,
body=REPO_LIST_RESPONSE
)

resp = client.get('/api/github/repos')
assert resp.status_code == 200
data = resp.json()
assert len(data) == 1
assert data[0]['name'] == 'getsentry/zeus'
assert data[0]['active']


def test_list_github_active_repo_out_of_scope(
client, default_login, default_user, default_identity, default_repo):
responses.add(
'GET',
'https://api.github.com/user/repos?type=owner',
match_querystring=True,
body=REPO_LIST_RESPONSE
)

resp = client.get('/api/github/repos')
assert resp.status_code == 200
data = resp.json()
assert len(data) == 1
assert data[0]['name'] == 'getsentry/zeus'
assert not data[0]['active']
5 changes: 4 additions & 1 deletion zeus/api/resources/github_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ def get(self):

active_repo_ids = frozenset(
r[0]
for r in db.session.query(Repository.external_id).filter(
for r in db.session.query(Repository.external_id).join(
RepositoryAccess, RepositoryAccess.repository_id == Repository.id,
).filter(
Repository.provider == RepositoryProvider.github,
RepositoryAccess.user_id == user.id,
)
)

Expand Down
2 changes: 2 additions & 0 deletions zeus/testutils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def default_repo():
url='https://github.com/getsentry/zeus.git',
backend=models.RepositoryBackend.git,
status=models.RepositoryStatus.active,
provider=models.RepositoryProvider.github,
github=True,
external_id='1',
)


Expand Down

0 comments on commit 0089562

Please sign in to comment.