Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lmazuel committed Feb 5, 2018
1 parent d88cd6d commit 5a7315b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion swaggertosdk/git_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def checkout_create_push_branch(repo, name):
repo.git.checkout(name)
_LOGGER.info("Checkout %s success", name)
except GitCommandError:
_LOGGER.info("Checkout %s was impossible (branch does not exist)", name)
_LOGGER.info("Checkout %s was impossible (branch does not exist). Creating it and push it.", name)
checkout_and_create_branch(repo, name)
repo.git.push('origin', name, set_upstream=True)

Expand Down
22 changes: 15 additions & 7 deletions swaggertosdk/restapi/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def rest_pull_open(body, github_con, restapi_repo, sdk_pr_target_repo, context_t
# If the PR contains a merge commit, we might generate the entire world
# even if the global PR itself is not impacted by this merge commit.
_LOGGER.info("This comes from a fork, I need generation first, since targetted branch does not exist")
msg = generate_sdk_from_git_object(
commit_url = generate_sdk_from_git_object(
rest_pr,
sdk_dest_branch,
origin_repo,
Expand All @@ -232,7 +232,11 @@ def rest_pull_open(body, github_con, restapi_repo, sdk_pr_target_repo, context_t
fallback_base_branch_name=sdk_default_base,
sdk_tag=sdk_tag
)
dashboard.create_comment(msg)
if commit_url:
dashboard.create_comment("Did a commit to {}:\n{}".format(sdk_tag, commit_url))
else:
dashboard.create_comment("This commit was treated and no generation was made for {}".format(sdk_tag))
return
else:
context_branch = None

Expand Down Expand Up @@ -369,11 +373,15 @@ def rest_pull_sync(body, github_con, restapi_repo, sdk_pr_target_repo, context_t
_LOGGER.info("This will be handled by 'push' event on the branch")
return

context_branch = None
if len(context_tags) == 1:
context_branch = "restapi_auto_"+context_tags[0]

# Look for the SDK pr
sdk_pr_model = SdkPRModel.from_pr_webhook(body, github_con, restapi_repo, sdk_pr_target_repo, sdk_default_base)
sdk_prs = list(sdk_pr_target_repo.get_pulls(
head=sdk_pr_model.head_branch_name,
base=sdk_pr_model.base_branch_name
head=sdk_pr_target_repo.owner.login+":"+sdk_pr_model.head_branch_name,
base=context_branch or sdk_pr_model.base_branch_name
))
if not sdk_prs:
# Didn't find it, let's consider this event as opening
Expand All @@ -385,7 +393,7 @@ def rest_pull_sync(body, github_con, restapi_repo, sdk_pr_target_repo, context_t
fork_repo = github_con.get_repo(origin_repo)
fork_owner = fork_repo.owner.login
subbranch_name_part = fork_owner+"_"+dest_branch
msg = generate_sdk_from_git_object(
generate_sdk_from_git_object(
rest_pr,
"restapi_auto_"+subbranch_name_part,
origin_repo,
Expand All @@ -395,8 +403,8 @@ def rest_pull_sync(body, github_con, restapi_repo, sdk_pr_target_repo, context_t
sdk_tag=sdk_tag
)
dashboard = DashboardCommentableObject(rest_pr, "# Automation for {}".format(sdk_tag))
dashboard.create_comment(msg)

# Do not comment on this commit, just push back the PR html url just in case last one was an exception
dashboard.create_comment("A PR has been created for you:\n{}".format(sdk_prs[0].html_url))
return {'message': 'No return for this endpoint'}

def consume():
Expand Down
9 changes: 4 additions & 5 deletions swaggertosdk/restapi/github_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def generate_sdk_from_git_object(git_object, branch_name, restapi_git_id, sdk_gi

for base_branch in base_branch_names:
_LOGGER.info('Checkout and create %s', base_branch)
checkout_create_push_branch(sdk_repo, base_branch)
checkout_and_create_branch(sdk_repo, base_branch)

_LOGGER.info('Try to checkout destination branch %s', branch_name)
try:
Expand Down Expand Up @@ -324,8 +324,7 @@ def skip_callback(project, local_conf):
message = message_template + "\n\n" + commit_for_sha.message
commit_sha = do_commit(sdk_repo, message, branch_name, commit_for_sha.sha)
if commit_sha:
for base_branch in base_branch_names:
sdk_repo.git.push('origin', base_branch, set_upstream=True)
sdk_repo.git.push('origin', branch_name, set_upstream=True)
commit_url = "https://github.com/{}/commit/{}".format(sdk_git_id, commit_sha)
return "Did a commit to {}:\n{}".format(sdk_git_id, commit_url)
else:
return "This commit was treated and no generation was made for {}".format(sdk_git_id)
return "https://github.com/{}/commit/{}".format(sdk_git_id, commit_sha)

0 comments on commit 5a7315b

Please sign in to comment.