Skip to content

Commit

Permalink
Improve repository URL parsing and support for nested structures
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchristianschroeter committed Oct 7, 2024
1 parent 8d41659 commit ef3a0bd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## [2.2.0]

### Added

- Support for GitLab repositories with nested group structures

### Fixed

- Improved URL parsing to correctly handle repositories with subgroups
- Fixed issue with extracting owner and repo from URLs containing credentials
- Enhanced compatibility with various Git remote URL formats (HTTPS, SSH, with/without credentials)

### Improved

- Robustness of repository information extraction from remote URLs
- Error handling and logging for repository parsing issues

## [2.1.0]

### Added
Expand Down
34 changes: 21 additions & 13 deletions src/services/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,28 @@ export class GitService {
const remoteUrl = await this.getRemoteUrl();
console.log('Remote URL:', remoteUrl);

// Handle both HTTPS and SSH URLs for GitHub and GitLab
const httpsMatch = remoteUrl.match(/(?:https?:\/\/(?:[^@]+@)?(?:github|gitlab)\.com\/|git@(?:github|gitlab)\.com:)([^\/]+)\/([^\/\.]+)(?:\.git)?/);

if (httpsMatch) {
const [, owner, repo] = httpsMatch;
console.log('Extracted owner and repo:', { owner, repo });
return { owner, repo };
}
// Unified regex pattern for both HTTPS (with or without credentials) and SSH URLs
const urlPattern = /(?:https?:\/\/(?:[^@]+@)?|git@)(?:github\.com|gitlab\.com)[/:](.+?)(?:\.git)?$/;
const match = remoteUrl.match(urlPattern);

if (match) {
const fullPath = match[1];
const parts = fullPath.split('/');

if (parts.length < 2) {
throw new Error(`Invalid repository path: ${fullPath}`);
}

// For GitHub, or GitLab without subgroups
if (parts.length === 2) {
return { owner: parts[0], repo: parts[1] };
}

// For GitLab with subgroups
const repo = parts.pop()!; // Get the last part as the repo name
const owner = parts.join('/'); // Join the rest as the owner (including subgroups)

// If HTTPS/SSH pattern doesn't match, try GitLab-specific pattern
const gitlabSshMatch = remoteUrl.match(/git@gitlab\.com:(.+)\/(.+)\.git/);
if (gitlabSshMatch) {
const [, owner, repo] = gitlabSshMatch;
console.log('Extracted owner and repo from GitLab SSH URL:', { owner, repo });
console.log('Extracted owner and repo:', { owner, repo });
return { owner, repo };
}

Expand Down

0 comments on commit ef3a0bd

Please sign in to comment.