Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to Github Enterprise #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ The client supports a high-level `import_project` method on organizations for ad
```python
org = client.organizations.first()
org.import_project("github.com/user/project@branch")
org.import_project("api.github.com/user/project@branch") # Github Enterprise
org.import_project("docker.io/repository:tag")
```

Expand Down
14 changes: 10 additions & 4 deletions snyk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ def integrations(self) -> Manager:
and files, and better errors, would be required.
"""

def import_project(self, url, files: Optional[List[str]] = None) -> bool:
self def import_project(self, url, files: Optional[List[str]] = []) -> bool:
try:
components = url.split("/")
service = components[0]

if service == "github.com":
if service in ("github.com", "api.github.com"):
owner = components[1]
name = components[2]
parts = name.split("@")
Expand All @@ -222,7 +222,11 @@ def import_project(self, url, files: Optional[List[str]] = None) -> bool:
except ValueError:
raise SnykError
try:
integrations = {"github.com": "github", "docker.io": "docker-hub"}
integrations = {
"github.com": "github",
"api.github.com": "github-enterprise",
"docker.io": "docker-hub"
}
integration_name = integrations[service]
except KeyError:
raise SnykError
Expand All @@ -231,13 +235,15 @@ def import_project(self, url, files: Optional[List[str]] = None) -> bool:
return self.integrations.filter(name=integration_name)[0].import_image(
name
)
else:
elif service in ("github.com", "api.github.com"):
integration = self.integrations.filter(name=integration_name)[0]

if files:
return integration.import_git(owner, name, branch, files)
else:
return integration.import_git(owner, name, branch)
else:
raise SnykNotImplementedError

except KeyError:
raise SnykError
Expand Down