def test_github_link(): inputstr = "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/billing/resource-manager/readme.md" link = GithubLink.from_string(inputstr) assert link.gitid == "Azure/azure-rest-api-specs" assert link.branch_or_commit == "master" assert link.link_type == "raw" assert link.path == "specification/billing/resource-manager/readme.md" assert str(link) == inputstr raw_link = link.as_raw_link() assert isinstance(raw_link, GithubLink) assert str(raw_link) == str(link) inputstr = ( "https://github.com/Azure/azure-rest-api-specs/blob/master/specification/billing/resource-manager/readme.md" ) link = GithubLink.from_string(inputstr) assert link.gitid == "Azure/azure-rest-api-specs" assert link.branch_or_commit == "master" assert link.link_type == "blob" assert link.path == "specification/billing/resource-manager/readme.md" assert str(link) == inputstr raw_link = link.as_raw_link() assert isinstance(raw_link, GithubLink) assert ( str(raw_link) == "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/billing/resource-manager/readme.md" ) inputstr = "https://github.com/Azure/azure-rest-api-specs/tree/master/specification/billing/resource-manager" link = GithubLink.from_string(inputstr) assert link.gitid == "Azure/azure-rest-api-specs" assert link.branch_or_commit == "master" assert link.link_type == "tree" assert link.path == "specification/billing/resource-manager" assert str(link) == inputstr with pytest.raises(ValueError): link.as_raw_link() inputstr = "https://[email protected]/Azure/azure-rest-api-specs/blob/master/specification/billing/resource-manager/readme.md" link = GithubLink.from_string(inputstr) assert link.token == "token" assert link.gitid == "Azure/azure-rest-api-specs" assert link.branch_or_commit == "master" assert link.link_type == "blob" assert link.path == "specification/billing/resource-manager/readme.md" assert str(link) == inputstr raw_link = link.as_raw_link() assert isinstance(raw_link, GithubLink) # Raw link with token does not use token in URL, since it has to be provided as Authorization: token <token> assert ( str(raw_link) == "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/billing/resource-manager/readme.md" )
def get_readme_path(readme_file, base_folder='.'): """Get a readable Readme path. If start with http, assume online, ignore base_folder and convert to raw link if necessary. If base_folder is not None, assume relative to base_folder. """ if not isinstance(readme_file, Path) and readme_file.startswith("http"): return GithubLink.from_string(readme_file).as_raw_link() else: if base_folder is None: base_folder = '.' return str(Path(base_folder) / Path(readme_file))
def get_readme_path(readme_file, base_folder='.'): """Get a readable Readme path. If start with http, assume online, ignore base_folder and convert to raw link if necessary. If base_folder is not None, assume relative to base_folder. """ if not isinstance(readme_file, Path) and readme_file.startswith("http"): return GithubLink.from_string(readme_file).as_raw_link() else: if base_folder is None: base_folder='.' return str(Path(base_folder) / Path(readme_file))
def rebuild(self, issue, project_pattern): if not issue.pull_request: return "Rebuild is just supported in PR for now" sdkid = issue.repository.full_name pr = issue.repository.get_pull(issue.number) new_comment = issue.create_comment("Working on generating {} for you!!!".format(project_pattern)) config_path = CONFIG_FILE message = "Rebuild by "+issue.html_url autorest_bin = None branch_name = pr.head.ref branched_sdk_id = pr.head.repo.full_name+'@'+branch_name if project_pattern.startswith("https://"): link = GithubLink.from_string(project_pattern) link = link.as_raw_link() # Ensure this is a raw link. rest_api_id = link.gitid rest_api_branch = link.branch_or_commit token = link.token if link.token else self.gh_token path = link.path else: rest_api_id = "Azure/azure-rest-api-specs" rest_api_branch = "master" token = self.gh_token path = None # Not such notion of path here, since it's inside SwaggerToSdk conf branched_rest_api_id = rest_api_id + "@" + rest_api_branch config = read_config_from_github(pr.head.repo.full_name, branch_name, token) with tempfile.TemporaryDirectory() as temp_dir, \ manage_git_folder(token, Path(temp_dir) / Path("rest"), branched_rest_api_id) as restapi_git_folder, \ manage_git_folder(self.gh_token, Path(temp_dir) / Path("sdk"), branched_sdk_id) as sdk_folder: sdk_repo = Repo(str(sdk_folder)) configure_user(self.gh_token, sdk_repo) if path: # Assume this is a Readme path config["projects"] = {} # Wipe out everything build_swaggertosdk_conf_from_json_readme(path, sdkid, config, base_folder=restapi_git_folder) skip_callback = lambda x, y: False else: def skip_callback(project, local_conf): del local_conf # Unused if not project.startswith(project_pattern): return True return False from swaggertosdk import SwaggerToSdkNewCLI SwaggerToSdkNewCLI.build_libraries(config, skip_callback, restapi_git_folder, sdk_repo, temp_dir, autorest_bin) new_comment.edit("End of generation, doing commit") commit_sha = do_commit(sdk_repo, message, branch_name, "") if commit_sha: new_comment.edit("Pushing") sdk_repo.git.push('origin', branch_name, set_upstream=True) new_comment.delete() else: new_comment.delete() return "Nothing to rebuild, this PR is up to date" _LOGGER.info("Build SDK finished and cleaned") return "Build SDK finished and cleaned"
def get_configuration_github_path(sdk_id, branch="master"): return GithubLink(sdk_id, "raw", branch, CONFIG_FILE)
def rebuild(self, issue, project_pattern): if not issue.pull_request: return "Rebuild is just supported in PR for now" sdkid = issue.repository.full_name pr = issue.repository.get_pull(issue.number) new_comment = issue.create_comment( "Working on generating {} for you!!!".format(project_pattern)) config_path = CONFIG_FILE message = "Rebuild by " + issue.html_url autorest_bin = None branch_name = pr.head.ref branched_sdk_id = pr.head.repo.full_name + '@' + branch_name if project_pattern.startswith("https://"): link = GithubLink.from_string(project_pattern) link = link.as_raw_link() # Ensure this is a raw link. rest_api_id = link.gitid rest_api_branch = link.branch_or_commit token = link.token if link.token else self.gh_token path = link.path else: rest_api_id = "Azure/azure-rest-api-specs" rest_api_branch = "master" token = self.gh_token path = None # Not such notion of path here, since it's inside SwaggerToSdk conf branched_rest_api_id = rest_api_id + "@" + rest_api_branch config = read_config_from_github(pr.head.repo.full_name, branch_name, token) with tempfile.TemporaryDirectory() as temp_dir, \ manage_git_folder(token, Path(temp_dir) / Path("rest"), branched_rest_api_id) as restapi_git_folder, \ manage_git_folder(self.gh_token, Path(temp_dir) / Path("sdk"), branched_sdk_id) as sdk_folder: sdk_repo = Repo(str(sdk_folder)) configure_user(self.gh_token, sdk_repo) if path: # Assume this is a Readme path config["projects"] = {} # Wipe out everything build_swaggertosdk_conf_from_json_readme( path, sdkid, config, base_folder=restapi_git_folder) skip_callback = lambda x, y: False else: def skip_callback(project, local_conf): del local_conf # Unused if not project.startswith(project_pattern): return True return False from swaggertosdk import SwaggerToSdkNewCLI SwaggerToSdkNewCLI.build_libraries(config, skip_callback, restapi_git_folder, sdk_repo, temp_dir, autorest_bin) new_comment.edit("End of generation, doing commit") commit_sha = do_commit(sdk_repo, message, branch_name, "") if commit_sha: new_comment.edit("Pushing") sdk_repo.git.push('origin', branch_name, set_upstream=True) new_comment.delete() else: new_comment.delete() return "Nothing to rebuild, this PR is up to date" _LOGGER.info("Build SDK finished and cleaned") return "Build SDK finished and cleaned"