Skip to content

Commit

Permalink
product-details: move git clone / push to separate functions for easi…
Browse files Browse the repository at this point in the history
…er mocking
  • Loading branch information
jcristau committed Dec 17, 2024
1 parent 441569b commit a898886
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions api/src/shipit_api/admin/product_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,20 +1102,7 @@ def run_check(*arg, **kw):
return cli_common.utils.retry(lambda: cli_common.command.run_check(*arg, **kw))


async def rebuild(
db_session: sqlalchemy.orm.Session,
git_branch: str,
git_repo_url: str,
folder_in_repo: str,
breakpoint_version: typing.Optional[int],
clean_working_copy: bool = True,
):
secrets = [urllib.parse.urlparse(git_repo_url).password]

# Sometimes we want to work from a clean working copy
if clean_working_copy and shipit_api.common.config.PRODUCT_DETAILS_DIR.exists():
shutil.rmtree(shipit_api.common.config.PRODUCT_DETAILS_DIR)

def setup_working_copy(git_branch, git_repo_url, secrets):
# Clone/pull latest product details
logger.info(f"Getting latest product details from {cli_common.command.hide_secrets(git_repo_url, secrets)}.")
if shipit_api.common.config.PRODUCT_DETAILS_DIR.exists():
Expand All @@ -1137,6 +1124,23 @@ async def rebuild(
run_check(["git", "config", "user.email", "[email protected]"], cwd=shipit_api.common.config.PRODUCT_DETAILS_DIR, secrets=secrets)
run_check(["git", "config", "user.name", "Release Services Robot"], cwd=shipit_api.common.config.PRODUCT_DETAILS_DIR, secrets=secrets)


async def rebuild(
db_session: sqlalchemy.orm.Session,
git_branch: str,
git_repo_url: str,
folder_in_repo: str,
breakpoint_version: typing.Optional[int],
clean_working_copy: bool = True,
):
secrets = [urllib.parse.urlparse(git_repo_url).password]

# Sometimes we want to work from a clean working copy
if clean_working_copy and shipit_api.common.config.PRODUCT_DETAILS_DIR.exists():
shutil.rmtree(shipit_api.common.config.PRODUCT_DETAILS_DIR)

setup_working_copy(git_branch, git_repo_url, secrets)

# XXX: we need to implement how to figure out breakpoint_version from old_product_details
# if breakpoint_version is not provided we should figure it out from old_product_details
# and if we can not figure it out we should use shipit_api.common.config.BREAKPOINT_VERSION
Expand Down Expand Up @@ -1299,4 +1303,8 @@ async def rebuild(
# XXX: we need a better commmit message, maybe mention what triggered this update
commit_message = "Updating product details"
run_check(["git", "commit", "-m", commit_message], cwd=shipit_api.common.config.PRODUCT_DETAILS_DIR, secrets=secrets)
run_check(["git", "push", "origin", git_branch], cwd=shipit_api.common.config.PRODUCT_DETAILS_DIR, secrets=secrets)
git_push(git_branch, secrets)


def git_push(git_branch, secrets):
run_check(["git", "push", "origin", git_branch], cwd=shipit_api.common.config.PRODUCT_DETAILS_DIR, secrets=secrets)

0 comments on commit a898886

Please sign in to comment.