Skip to content

Commit

Permalink
Download the conf
Browse files Browse the repository at this point in the history
  • Loading branch information
lmazuel committed Apr 2, 2018
1 parent 7a488ac commit d267dcb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion swaggertosdk/SwaggerToSdkCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import tempfile
from pathlib import Path

import requests

from github import Github, UnknownObjectException

from .autorest_tools import (
Expand Down Expand Up @@ -117,6 +119,10 @@ def read_config(sdk_git_folder, config_file):
with open(config_path, 'r') as config_fd:
return json.loads(config_fd.read())

def read_config_from_github(sdk_id, branch="master"):
raw_link = str(get_configuration_github_path(sdk_id, branch))
content = requests.get(raw_link).text
return json.loads(content)

def extract_conf_from_readmes(swagger_files_in_pr, restapi_git_folder, sdk_git_id, config):
readme_files_in_pr = {readme for readme in swagger_files_in_pr if getattr(readme, "name", readme).lower().endswith("readme.md")}
Expand Down Expand Up @@ -207,4 +213,4 @@ def solve_relative_path(autorest_options, sdk_root):

def get_configuration_github_path(sdk_id, branch="master"):
gh_token = os.environ.get("GH_TOKEN", None) # Token here is just for private
return GithubLink(sdk_id, "raw", branch, "swagger_to_sdk_config.json", gh_token)
return GithubLink(sdk_id, "raw", branch, CONFIG_FILE, gh_token)
8 changes: 7 additions & 1 deletion tests/test_swaggertosdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
extract_conf_from_readmes,
get_context_tag_from_git_object,
get_readme_files_from_git_object,
get_configuration_github_path
get_configuration_github_path,
read_config_from_github
)
from swaggertosdk.SwaggerToSdkNewCLI import (
solve_relative_path,
Expand Down Expand Up @@ -287,3 +288,8 @@ def test_get_configuration_github_path(github_token):
raw_link = str(get_configuration_github_path("Azure/azure-sdk-for-python", "dev"))
raw_link = raw_link.replace(github_token, "TOKEN")
assert raw_link == "https://TOKEN@raw.githubusercontent.com/Azure/azure-sdk-for-python/dev/swagger_to_sdk_config.json"

def test_read_config_from_github(github_token):
conf = read_config_from_github("Azure/azure-sdk-for-python")
# Don't do too much
assert "meta" in conf

0 comments on commit d267dcb

Please sign in to comment.