Skip to content

Commit

Permalink
Add push parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
lmazuel committed Feb 1, 2018
1 parent 3113cd0 commit 56f30b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
16 changes: 9 additions & 7 deletions swaggertosdk/SwaggerToSdkMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

def generate_sdk(gh_token, config_path, project_pattern, restapi_git_id,
sdk_git_id, pr_repo_id, message_template, base_branch_name, branch_name,
autorest_bin=None):
autorest_bin=None, push=True):
"""Main method of the the file"""
sdk_git_id = get_full_sdk_id(gh_token, sdk_git_id)

Expand All @@ -63,7 +63,7 @@ def generate_sdk(gh_token, config_path, project_pattern, restapi_git_id,
if gh_token:
_LOGGER.info('I have a token, try to sync fork')
configure_user(gh_token, sdk_repo)
sync_fork(gh_token, sdk_git_id, sdk_repo)
sync_fork(gh_token, sdk_git_id, sdk_repo, push)

config = read_config(sdk_repo.working_tree_dir, config_path)

Expand Down Expand Up @@ -104,7 +104,7 @@ def skip_callback(project, local_conf):
else:
raise ValueError(f"Unsupported version {conf_version}")

if gh_token:
if gh_token and push:
hexsha = get_repo_hexsha(restapi_git_folder)
if do_commit(sdk_repo, message_template, branch_name, hexsha):
sdk_repo.git.push('origin', branch_name, set_upstream=True)
Expand All @@ -113,10 +113,8 @@ def skip_callback(project, local_conf):
github_pr = do_pr(gh_token, sdk_git_id, pr_repo_id, branch_name, base_branch_name, pr_body)
comment = compute_pr_comment_with_sdk_pr(github_pr.html_url, sdk_git_id, branch_name)
add_comment_to_initial_pr(gh_token, comment)
else:
add_comment_to_initial_pr(gh_token, "No modification for {}".format(sdk_git_id))
else:
_LOGGER.warning('Skipping commit creation since no token is provided')
_LOGGER.warning('Skipping commit creation since no token is provided or no push')

_LOGGER.info("Build SDK finished and cleaned")

Expand Down Expand Up @@ -181,6 +179,9 @@ def main(argv):
parser.add_argument('--autorest',
dest='autorest_bin',
help='Force the Autorest to be executed. Must be a executable command.')
parser.add_argument("--push",
dest="push", action="store_true",
help="Should this execution push or just read")
parser.add_argument("-v", "--verbose",
dest="verbose", action="store_true",
help="Verbosity in INFO mode")
Expand Down Expand Up @@ -209,4 +210,5 @@ def main(argv):
args.message,
args.base_branch,
args.branch,
args.autorest_bin)
args.autorest_bin,
args.push)
7 changes: 4 additions & 3 deletions swaggertosdk/github_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_full_sdk_id(gh_token, sdk_git_id):
return '{}/{}'.format(login, sdk_git_id)
return sdk_git_id

def sync_fork(gh_token, github_repo_id, repo):
def sync_fork(gh_token, github_repo_id, repo, push=True):
"""Sync the current branch in this fork against the direct parent on Github"""
if not gh_token:
_LOGGER.warning('Skipping the upstream repo sync, no token')
Expand All @@ -111,8 +111,9 @@ def sync_fork(gh_token, github_repo_id, repo):
_LOGGER.info('Merge from upstream')
msg = repo.git.rebase('upstream/{}'.format(repo.active_branch.name))
_LOGGER.debug(msg)
msg = repo.git.push()
_LOGGER.debug(msg)
if push:
msg = repo.git.push()
_LOGGER.debug(msg)

def clone_to_path(gh_token, folder, sdk_git_id, branch=None):
"""Clone the given repo_id to the folder.
Expand Down

0 comments on commit 56f30b1

Please sign in to comment.