-
Notifications
You must be signed in to change notification settings - Fork 20
add support for cloning Git repository via SSH rather than HTTPS #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
e96ec76
66ba1f9
6ba9625
fa91fcd
a5b40e9
357f9df
a444bcc
6dcdd80
3f2cfcb
37c06af
4b046f6
45bd556
b19fe23
5c51665
a1c2635
02f3125
47e2076
c7a98f2
7da317d
293ce3c
668915c
882354c
a99ae60
4d9dc0e
9b582ab
1ea33d9
df1a258
46d14a9
f4c0940
95c574b
4021c20
4a3dd94
e30cd5b
a985803
1381689
750b8a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
_ERROR_GIT_APPLY = "git apply" | ||
_ERROR_GIT_CHECKOUT = "git checkout" | ||
_ERROR_GIT_CLONE = "curl" | ||
boegel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_ERROR_GIT_DIFF = "git diff" | ||
_ERROR_NONE = "none" | ||
|
||
# other constants | ||
|
@@ -147,6 +148,10 @@ def get_build_env_cfg(cfg): | |
log(f"{fn}(): load_modules '{load_modules}'") | ||
config_data[config.BUILDENV_SETTING_LOAD_MODULES] = load_modules | ||
|
||
clone_git_repo_via = buildenv.get(config.BUILDENV_SETTING_CLONE_GIT_REPO_VIA, None) | ||
log(f"{fn}(): clone_git_repo_via '{clone_git_repo_via}'") | ||
config_data[config.BUILDENV_SETTING_CLONE_GIT_REPO_VIA] = clone_git_repo_via | ||
|
||
return config_data | ||
|
||
|
||
|
@@ -355,7 +360,7 @@ def clone_git_repo(repo, path): | |
return (clone_output, clone_error, clone_exit_code) | ||
|
||
|
||
def download_pr(repo_name, branch_name, pr, arch_job_dir): | ||
def download_pr(repo_name, branch_name, pr, arch_job_dir, clone_via=None): | ||
""" | ||
Download pull request to job working directory | ||
|
||
|
@@ -364,6 +369,7 @@ def download_pr(repo_name, branch_name, pr, arch_job_dir): | |
branch_name (string): name of the base branch of the pull request | ||
pr (github.PullRequest.PullRequest): instance representing the pull request | ||
arch_job_dir (string): working directory of the job to be submitted | ||
clone_via (string): mechanism to clone Git repository, should be 'https' (default) or 'ssh' | ||
|
||
Returns: | ||
None (implicitly), in case an error is caught in the git clone, git checkout, curl, | ||
|
@@ -376,7 +382,16 @@ def download_pr(repo_name, branch_name, pr, arch_job_dir): | |
# - 'git checkout' base branch of pull request | ||
# - 'curl' diff for pull request | ||
# - 'git apply' diff file | ||
clone_output, clone_error, clone_exit_code = clone_git_repo(f'https://github.com/{repo_name}', arch_job_dir) | ||
log(f"Cloning Git repo via: {clone_via}") | ||
if clone_via in (None, 'https'): | ||
repo_url = f'https://github.com/{repo_name}' | ||
boegel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
elif clone_via == 'ssh': | ||
repo_url = f'git@github.com:{repo_name}.git' | ||
else: | ||
error_stage = _ERROR_GIT_CLONE | ||
return '', f"Unknown mechanism to clone Git repo: {clone_via}", 1, error_stage | ||
|
||
clone_output, clone_error, clone_exit_code = clone_git_repo(repo_url, arch_job_dir) | ||
if clone_exit_code != 0: | ||
error_stage = _ERROR_GIT_CLONE | ||
return clone_output, clone_error, clone_exit_code, error_stage | ||
|
@@ -407,6 +422,17 @@ def download_pr(repo_name, branch_name, pr, arch_job_dir): | |
error_stage = _ERROR_CURL | ||
return curl_output, curl_error, curl_exit_code, error_stage | ||
|
||
git_diff_cmd = ' '.join([ | ||
f"git fetch origin pull/{pr.number}/head:{pr.number}", | ||
f"git diff HEAD pr{pr.number} > {pr.number}.diff", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you're now creating the diff like this, shouldn't you remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, of course, I'll tackle that too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. edit: nvm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smoors made a good point (in Slack) about this change: this doesn't take into account that there may be changes in the So, a better approach would be to:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This procedure hasn't been implemented yet, right? A few thoughts:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to determine base branch for PR (the target branch), maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll change this so the new approach based on That gives us some freedom to experiment with the situation where the target branch has been updated since the branch for the PR was created. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated this in a99ae60 to only use the It's still doing only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. created a PR to this PR using |
||
]) | ||
git_diff_output, git_diff_error, git_diff_exit_code = run_cmd( | ||
git_diff_cmd, "Obtain patch", arch_job_dir, raise_on_error=False | ||
) | ||
if git_diff_exit_code != 0: | ||
error_stage = _ERROR_GIT_DIFF | ||
return git_diff_output, git_diff_error, git_diff_exit_code | ||
|
||
git_apply_cmd = f'git apply {pr.number}.diff' | ||
log(f'git apply with command {git_apply_cmd}') | ||
git_apply_output, git_apply_error, git_apply_exit_code = run_cmd( | ||
|
@@ -615,8 +641,9 @@ def prepare_jobs(pr, cfg, event_info, action_filter): | |
log(f"{fn}(): job_dir '{job_dir}'") | ||
|
||
# TODO optimisation? download once, copy and cleanup initial copy? | ||
clone_git_repo_via = build_env_cfg.get(config.BUILDENV_SETTING_CLONE_GIT_REPO_VIA) | ||
download_pr_output, download_pr_error, download_pr_exit_code, error_stage = download_pr( | ||
base_repo_name, base_branch_name, pr, job_dir | ||
base_repo_name, base_branch_name, pr, job_dir, clone_via=clone_git_repo_via, | ||
) | ||
comment_download_pr(base_repo_name, pr, download_pr_exit_code, download_pr_error, error_stage) | ||
# prepare job configuration file 'job.cfg' in directory <job_dir>/cfg | ||
|
Uh oh!
There was an error while loading. Please reload this page.