|
1 | 1 | import logging
|
| 2 | +import os |
2 | 3 | from pathlib import Path
|
3 |
| -from typing import Dict, Any |
| 4 | +from typing import Dict, Any, Optional, List |
4 | 5 |
|
5 | 6 | from jinja2 import Template, PackageLoader, Environment
|
6 | 7 | from .conf import read_conf, build_default_conf, CONF_NAME
|
@@ -29,7 +30,28 @@ def build_config(config : Dict[str, Any]) -> Dict[str, str]:
|
29 | 30 | # Return result
|
30 | 31 | return result
|
31 | 32 |
|
32 |
| -def build_packaging(package_name: str, output_folder: str, build_conf: bool = False) -> None: |
| 33 | + |
| 34 | +def build_packaging(output_folder: str, gh_token: Optional[str]=None, jenkins: bool = False, packages: List[str]=None, build_conf: bool = False) -> None: |
| 35 | + package_names = set(packages) or set() |
| 36 | + if jenkins: |
| 37 | + sdk_id = os.environ["ghprbGhRepository"] |
| 38 | + pr_number = int(os.environ["ghprbPullId"]) |
| 39 | + |
| 40 | + from github import Github |
| 41 | + con = Github(gh_token) |
| 42 | + repo = con.get_repo(sdk_id) |
| 43 | + sdk_pr = repo.get_pull(pr_number) |
| 44 | + # "get_files" of Github only download the first 300 files. Might not be enough. |
| 45 | + package_names |= {f.filename.split('/')[0] for f in sdk_pr.get_files() if f.filename.startswith("azure")} |
| 46 | + |
| 47 | + if not package_names: |
| 48 | + raise ValueError("Was unable to find out the package names.") |
| 49 | + |
| 50 | + for package_name in package_names: |
| 51 | + build_packaging_by_package_name(package_name, output_folder, build_conf) |
| 52 | + |
| 53 | + |
| 54 | +def build_packaging_by_package_name(package_name: str, output_folder: str, build_conf: bool = False) -> None: |
33 | 55 | _LOGGER.info("Building template %s", package_name)
|
34 | 56 | package_folder = Path(output_folder) / Path(package_name)
|
35 | 57 |
|
|
0 commit comments