Skip to content

Commit

Permalink
fix: add support for parsing actual release artifact urls
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmoz committed May 22, 2024
1 parent f74d22c commit 73113a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/utils/url-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as assert from 'node:assert';
import {parseArtifactHubReferenceUrl, parseManifestUrl} from './url-parser.js';

describe('utils/manifest/parseManifestUrl', () => {
it('should parse version from GitHub release manifest url', () => {
it('should parse version from raw GitHub url', () => {
const manifest = parseManifestUrl(
'https://raw.githubusercontent.com/username/repository/v0.0.1-alpha.10/path/to/file.yaml',
);
Expand All @@ -12,6 +12,15 @@ describe('utils/manifest/parseManifestUrl', () => {
assert.equal(manifest.semVer.raw, 'v0.0.1-alpha.10');
assert.equal(manifest.path, '/path/to/file.yaml');
});
it('should parse version from GitHub release manifest url', () => {
const manifest = parseManifestUrl(
'https://github.com/username/repository/releases/download/v1.2.3/artifact-name.yaml',
);
assert.equal(manifest.owner, 'username');
assert.equal(manifest.repo, 'repository');
assert.equal(manifest.semVer.raw, 'v1.2.3');
assert.equal(manifest.path, '/artifact-name.yaml');
});
it('should parse actual cyclops manifest url', () => {
const manifest = parseManifestUrl(
'https://raw.githubusercontent.com/cyclops-ui/cyclops/v0.0.1-alpha.10/install/cyclops-install.yaml',
Expand Down
12 changes: 8 additions & 4 deletions src/utils/url-parser.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import {ArtifactHubReference} from '../models/artifact-hub-reference.js';
import {ManifestUrl} from '../models/manifest-url.js';

const MANIFEST_REGEX =
/^https:\/\/raw.githubusercontent.com\/(?<owner>[\da-z-]+)\/(?<repo>[\da-z-]+)\/(?<version>[\d.a-z-]+)(?<path>\/.*)/;
const MANIFEST_REGEX = [
/^https:\/\/raw\.githubusercontent\.com\/(?<owner>[\da-z-]+)\/(?<repo>[\da-z-]+)\/(?<version>[\d.a-z-]+)(?<path>\/.*)/,
/^https:\/\/github\.com\/(?<owner>[\da-z-]+)\/(?<repo>[\da-z-]+)\/releases\/download\/(?<version>[\d.a-z-]+)(?<path>\/.*)/,
];

export function parseManifestUrl(manifestUrl: string): ManifestUrl {
const group = MANIFEST_REGEX.exec(manifestUrl)?.groups;
if (group !== undefined) {
const results = MANIFEST_REGEX.map(r => r.exec(manifestUrl)?.groups).filter(g => g !== undefined);

if (results.length > 0) {
const group = results[0]!;
return new ManifestUrl(manifestUrl, group.owner, group.repo, group.version, group.path);
}

Expand Down

0 comments on commit 73113a5

Please sign in to comment.