Skip to content

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

Merged
merged 36 commits into from
Jun 23, 2025

Conversation

boegel
Copy link
Contributor

@boegel boegel commented Feb 6, 2025

This is useful when the target repository of PRs that the bot should act on is a private repository.

Opt-in via this in bot configuration file (app.cfg):

[buildenv]
clone_git_repo_via = 'ssh'

(draft PR since this needs actual testing, and perhaps more changes)

tasks/build.py Outdated
@@ -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",
Copy link
Contributor

@smoors smoors Feb 6, 2025

Choose a reason for hiding this comment

The 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 curl_cmd above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course, I'll tackle that too

Copy link
Contributor

@smoors smoors Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: nvm

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 main branch that are not included in the PR branch yet.

So, a better approach would be to:

  • fetch the PR branch
  • check out the PR branch
  • git merge main
  • swap back to main branch
  • git diff
  • git apply

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This procedure hasn't been implemented yet, right?

A few thoughts:

  • main should probably be the target branch of the PR, for example, for EESSI/2023.06 that would be 2023.06-software.eessi.io?
  • the git diff after the swap back to "main" is really just the plain git diff or rather git diff PR_branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to determine base branch for PR (the target branch), maybe git merge-base is useful...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change this so the new approach based on git is only used when clone_via is set to 'ssh' (so nothing changes for existing bots that listen to a public repo).

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.

Copy link
Contributor Author

@boegel boegel Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this in a99ae60 to only use the git diff approach when clone_git_repo_via is used.

It's still doing only git fetch + git diff, so you could still have issues when the PR branch is way behind on the target branch, I'll try to look into that next.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created a PR to this PR using git merge-base:
boegel#1

@boegel boegel marked this pull request as ready for review February 6, 2025 16:37
@boegel
Copy link
Contributor Author

boegel commented Feb 6, 2025

This is working as expected now, so marking it ready-for-review.

Hopefully @trz42 has time to take a look?

Copy link
Contributor

@trz42 trz42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as intended. See trz42/software-layer#78

The optional settings have to be commented. The intention with listing them, is more to document that they are optional and it could be easily changed in the future if we wish so.

I think, it might be good to add some comments (README.md and app.cfg.example) about what is needed if the ssh key has not a standard name and if it uses a passphrase.

…king it required

Co-authored-by: Thomas Röblitz <trz42@users.noreply.github.com>
boegel and others added 3 commits February 21, 2025 14:15
Co-authored-by: Thomas Röblitz <trz42@users.noreply.github.com>
…app.cfg.example

Co-authored-by: Thomas Röblitz <trz42@users.noreply.github.com>
@boegel boegel force-pushed the git_clone_via_ssh branch 2 times, most recently from c03e52b to 299b9e8 Compare February 21, 2025 13:58
@boegel
Copy link
Contributor Author

boegel commented Feb 21, 2025

I haven't actually re-tested this after the changes I've made, and some more changes are required to the git diff approach to take into account that the target branch of a PR may have been updated since the PR was opened, so I'm marking this as work-in-progress for now...

@boegel boegel marked this pull request as draft February 21, 2025 16:25
@smoors
Copy link
Contributor

smoors commented May 4, 2025

this works as expected now that we're creating a diff from the merge-base instead of from the HEAD, which produces exactly the same diff as the one downloaded directly from api.github.com.

one thing that doesn't work with SSH is the bot: status command as that still requires using the github api. might be good to add a note about this.

@smoors
Copy link
Contributor

smoors commented May 22, 2025

one thing that doesn't work with SSH is the bot: status command as that still requires using the github api. might be good to add a note about this.

@boegel README updated in boegel#2

@boegel boegel marked this pull request as ready for review May 28, 2025 11:14
@boegel
Copy link
Contributor Author

boegel commented May 28, 2025

@trz42 This should be good to go now, can you take a look?

It doesn't change anything in the default behavior, but extra feature it adds is essential for working with private repositories, since those can't be cloned via HTTPS.

Copy link
Contributor

@trz42 trz42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment.

Can you also pull in upstream changes, thus one could test this PR and the PR for allowing no spaces between bot: and build?

Comment on lines +508 to +509
f"{download_pr_comments_cfg[config.DOWNLOAD_PR_COMMENTS_SETTING_PR_DIFF_FAILURE]}"
f"\n{download_pr_comments_cfg[config.DOWNLOAD_PR_COMMENTS_SETTING_PR_DIFF_TIP]}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These settings should probably be added to the list of required settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 750b8a4

Copy link
Contributor

@trz42 trz42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested via a pull request to a private repo. Works as intended.

Nice work @boegel and @smoors !

@trz42 trz42 merged commit 50c21d7 into EESSI:develop Jun 23, 2025
4 checks passed
@boegel boegel deleted the git_clone_via_ssh branch June 24, 2025 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants