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

feat(args): allow GitLab groups with --gitlab-repo #807

Merged
merged 2 commits into from
Aug 24, 2024

Conversation

weichweich
Copy link
Contributor

Description

The cli argument --gitlab-repo is split at / and the last two parts are used as owner and repo. This PR changes this behavior, splits at the right most / and takes the first part as owner and the second part as repo.

raw string owner repo
before gitlab/group/a/repo_name a repo_name
after this PR gitlab/group/a/repo_name gitlab/group/a repo_name

Motivation and Context

GitLab allows projects to be organized in groups. Groups can also be part of groups. Because of that projects are not identified by owner and repo, but by group/path and repo.

The same behavior can be achieved by using the following inside the config:

[remote.gitlab]
owner = "gitlab/group/a"
repo = "repo_name"

But since I would like to use the same config in multiple projects, I rather provide the remote information via an environment variable.

How Has This Been Tested?

I tested this with GitLab projects that are organized in groups.

There was a testcase that ignored the https://github.com domain if it was included. Since I never saw this inside the documentation I simply removed it, but I'm happy to adjust this PR in a way that this test would still pass, if needed.

Screenshots / Logs (if applicable)

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have formatted the code with rustfmt.
  • I checked the lints with clippy.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@weichweich weichweich requested a review from orhun as a code owner August 22, 2024 11:52
Copy link

welcome bot commented Aug 22, 2024

Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️

@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 39.79%. Comparing base (e74080c) to head (542510c).
Report is 7 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #807      +/-   ##
==========================================
+ Coverage   39.64%   39.79%   +0.15%     
==========================================
  Files          20       20              
  Lines        1607     1611       +4     
==========================================
+ Hits          637      641       +4     
  Misses        970      970              
Flag Coverage Δ
unit-tests 39.79% <100.00%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@orhun
Copy link
Owner

orhun commented Aug 23, 2024

Thanks for the PR! We should definitely include this fix in the upcoming release.

There was a testcase that ignored the https://github.com/ domain if it was included. Since I never saw this inside the documentation I simply removed it, but I'm happy to adjust this PR in a way that this test would still pass, if needed.

Yeah, the current state of this PR is breaking since it splits on the last occurrence. We need to somehow support both cases.

let parts = value.split('/').rev().collect::<Vec<&str>>();
if let (Some(owner), Some(repo)) = (parts.get(1), parts.first()) {
Ok(RemoteValue(Remote::new(*owner, *repo)))
let parts = value.rsplit_once('/');
Copy link
Owner

Choose a reason for hiding this comment

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

One idea is to parse it as URL then split it (just to be safe):

Suggested change
let parts = value.rsplit_once('/');
let mut value = inner.parse_ref(cmd, arg, value)?;
if let Ok(url) = Url::parse(&value) {
value = url.path().trim_start_matches('/').to_string();
}
let parts = value.rsplit_once('/');

(you need to add url crate to the workspace dependencies)

Copy link
Owner

@orhun orhun left a comment

Choose a reason for hiding this comment

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

I'm planning a release soon so I will merge this as-is, thank you!

@orhun orhun merged commit 6fbfdb5 into orhun:main Aug 24, 2024
58 of 60 checks passed
@orhun orhun changed the title feat: allow gitlab groups feat(args): allow GitLab groups with --gitlab-repo Aug 24, 2024
Copy link

welcome bot commented Aug 24, 2024

Congrats on merging your first pull request! ⛰️

@weichweich
Copy link
Contributor Author

Sorry, did read it just now. Thanks a lot for adjusting the code and merging it so quickly. And of course for building such an amazing tool! ❤️

@weichweich weichweich deleted the gitlab-groups branch August 24, 2024 09:24
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.

3 participants