Skip to content
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

update cloneOrOpenRepo to verify matching remote before updating repo. #308

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DannyBrito
Copy link

What type of PR is this?

What this PR does / why we need it:

This PR adds verification of matching remote within repo to be updated/clone in function updateRepo
If repo URL from the repo to be clone or updated matches any remote in repo will proceed as normal, otherwise will return a new ErrNoMatchingRemote error
This will be helpful for better handling, in scenario where the given repoPath exists but this doesn't have a remote pointing to target repo to clone or update. This issue can be seen in kubernetes/release#3444

cc: @jeremyrickard

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?


@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 7, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: DannyBrito
Once this PR has been reviewed and has the lgtm label, please assign palnabarun for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the sig/release Categorizes an issue or PR as relevant to SIG Release. label Feb 7, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @DannyBrito!

It looks like this is your first PR to kubernetes-sigs/release-sdk 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/release-sdk has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 7, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @DannyBrito. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 7, 2024
@jeremyrickard
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 7, 2024
@DannyBrito DannyBrito force-pushed the dannybrito/update-cloneorOpenRepo-to-verify-remote branch from 322b3e5 to 7ffc6d8 Compare February 7, 2024 21:54
@DannyBrito
Copy link
Author

/retest

@xmudrii
Copy link
Member

xmudrii commented Feb 7, 2024

Thank you for the contribution @DannyBrito!

This verification will work fine for repos cloned using our tooling, however, we might run into issues with repos cloned manually or using other tooling (which is supported by the release-notes tool). For example, both of these remote URLs are valid:

git@github.com:kubernetes-sigs/boskos.git # this format is generated by our tooling
git@github.com:kubernetes-sigs/boskos     # there's no .git suffix

repoURL is mostly like to follow the first format (with the .git suffix), but the actual remote URL might use a different format and still be valid. There are also some tricks around HTTPs-based remote URLs, e.g. URLs with and without authentication token in them (see https://stackoverflow.com/a/18936804 for an example).

We could try to do some pattern matching, but that still sounds kind of risky in my opinion. Maybe we should consider if we can fix this directly in the release-notes tool. I talked with @jeremyrickard about this, and we could randomize the repo-path flag, which is not going to fix the issue, but is considered a good enough mitigation. We're also open to ideas if this PR can be modified to accommodate different remote URL formats.

@jeremyrickard
Copy link
Member

@DannyBrito do you want to go ahead and update release-notes to just randomize the repo-path if not specified? that will provide a good impact while we figure out if we should continue with this path.

r, err := OpenRepo(repoPath)
if err != nil {
return nil, err
}

if updateRepository {
remotes, err := r.Remotes()
if err != nil {
return nil, fmt.Errorf("unable to get repository remotes: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
return nil, fmt.Errorf("unable to get repository remotes: %v", err)
return nil, fmt.Errorf("unable to get repository remotes: %w", err)

@saschagrunert
Copy link
Member

we could randomize the repo-path flag, which is not going to fix the issue, but is considered a good enough mitigation.

With that we break one beneficial use case: Being able to run the tool multiple times (without specifying the repo path) on a single repo while only pulling on the first run. For k/k this was particularly helpful because the repo is huge and pulling takes quite some time.

@xmudrii
Copy link
Member

xmudrii commented Feb 8, 2024

@saschagrunert What about instead of completely randomizing the directory name, we build it based on org and repo, e.g. kubernetes-kubernetes-repo or kubernetes-sigs-promo-tools-repo? The directory name will be slightly longer, but we would keep the benefit that you mentioned.

@saschagrunert
Copy link
Member

@xmudrii that would be great and I think it will work pretty well!

@jeremyrickard
Copy link
Member

I think @xmudrii 's suggestion would be great. @DannyBrito do you want to try that out?

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. sig/release Categorizes an issue or PR as relevant to SIG Release. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants