Skip to content

Commit 87e5749

Browse files
committed
feat: adding constants
1 parent 3655b4c commit 87e5749

File tree

4 files changed

+56
-13
lines changed

4 files changed

+56
-13
lines changed

src/ansys/tools/repo_sync/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,11 @@
3131
# Ease import statements
3232
# ------------------------------------------------------------------------------
3333

34+
from .constants import DEFAULT_BRANCH_NAME, DEFAULT_PULL_REQUEST_TITLE
3435
from .repo_sync import synchronize
36+
37+
__all__ = [
38+
"synchronize",
39+
"DEFAULT_BRANCH_NAME",
40+
"DEFAULT_PULL_REQUEST_TITLE",
41+
]

src/ansys/tools/repo_sync/__main__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727
.. code::
2828
2929
repo-sync \
30-
--token <token> \
31-
--owner <organization-name> \
32-
--repository <repository-name> \
33-
--from-dir <path-to-dir-containing-files-to-sync> \
34-
--to-dir <target-dir-for-sync> \
35-
--include-manifest <path-to-manifest>
30+
--token <token> \
31+
--owner <organization-name> \
32+
--repository <repository-name> \
33+
--from-dir <path-to-dir-containing-files-to-sync> \
34+
--to-dir <target-dir-for-sync> \
35+
--include-manifest <path-to-manifest>
3636
3737
"""
3838
import click
3939

40+
from .constants import DEFAULT_BRANCH_NAME, DEFAULT_PULL_REQUEST_TITLE
4041
from .repo_sync import synchronize as _synchronize
4142

4243

@@ -102,14 +103,14 @@
102103
@click.option(
103104
"--target-branch-name",
104105
type=str,
105-
default="sync/file-sync",
106-
help="Name of the branch to create for the synchronization, by default it is 'sync/file-sync'.",
106+
default=DEFAULT_BRANCH_NAME,
107+
help=f"Name of the branch to create for the synchronization, by default it is '{DEFAULT_BRANCH_NAME}'.",
107108
)
108109
@click.option(
109110
"--pull-request-title",
110111
type=str,
111-
default="sync: file sync performed by ansys-tools-repo-sync",
112-
help="Title of the pull request created after synchronization.",
112+
default=DEFAULT_PULL_REQUEST_TITLE,
113+
help=f"Title of the pull request created after synchronization, by default it is {DEFAULT_PULL_REQUEST_TITLE}",
113114
)
114115
def synchronize(
115116
owner,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
"""Module containing constants for the repo sync tool."""
24+
25+
DEFAULT_BRANCH_NAME = "sync/file-sync"
26+
"""Default branch name for the synchronization process."""
27+
28+
DEFAULT_PULL_REQUEST_TITLE = "sync: file sync performed by ansys-tools-repo-sync"
29+
"""Default title for the pull request created during synchronization."""

src/ansys/tools/repo_sync/repo_sync.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23+
"""Module containing the sync tool implementation."""
24+
2325
from fnmatch import filter
2426
import os
2527
import re
@@ -30,6 +32,8 @@
3032
from git import Repo
3133
from github import Auth, Github, GithubException
3234

35+
from .constants import DEFAULT_BRANCH_NAME, DEFAULT_PULL_REQUEST_TITLE
36+
3337

3438
def include_patterns(*patterns):
3539
"""Include listed patterns in ``copytree()``.
@@ -148,8 +152,8 @@ def synchronize(
148152
dry_run: bool = False,
149153
skip_ci: bool = False,
150154
random_branch_name: bool = False,
151-
target_branch_name: str = "sync/file-sync",
152-
pull_request_title: str = "sync: file sync performed by ansys-tools-repo-sync",
155+
target_branch_name: str = DEFAULT_BRANCH_NAME,
156+
pull_request_title: str = DEFAULT_PULL_REQUEST_TITLE,
153157
) -> Union[str, None]:
154158
"""Synchronize a folder to a remote repository.
155159
@@ -254,7 +258,9 @@ def synchronize(
254258
repo.index.commit(f"{'[skip ci] ' if skip_ci else ''}sync: add changes from local folder")
255259

256260
# Get a list of the files modified
257-
output = repo.git.diff("--compact-summary", f"{branch_checked_out}", f"{target_branch_name}")
261+
output = repo.git.diff(
262+
"--compact-summary", f"{branch_checked_out}", f"{target_branch_name}"
263+
)
258264

259265
# If output is empty, avoid creating PR
260266
if not output:

0 commit comments

Comments
 (0)