parsePath: commit url support
This commit is contained in:
parent
6bced576bf
commit
1621b6edff
|
@ -61,3 +61,22 @@ test('parsePath github project (trailing slash)', () => {
|
||||||
expect(path.entity).toBeNull();
|
expect(path.entity).toBeNull();
|
||||||
expect(path.entityID).toBeNull();
|
expect(path.entityID).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('parsePath gitlab commit', () => {
|
||||||
|
const path = parsePath(
|
||||||
|
'https://git.sakamoto.pl/laudompat/haruhi-dl/-/commit/1c3ca4fe2c32dc42ceeaec107981287c798d3df0.patch',
|
||||||
|
);
|
||||||
|
expect(path.domain).toEqual('git.sakamoto.pl');
|
||||||
|
expect(path.path).toEqual('laudompat/haruhi-dl');
|
||||||
|
expect(path.entity).toEqual(ENTITY_TYPE.COMMIT);
|
||||||
|
expect(path.entityID).toEqual('1c3ca4fe2c32dc42ceeaec107981287c798d3df0');
|
||||||
|
});
|
||||||
|
test('parsePath github commit', () => {
|
||||||
|
const path = parsePath(
|
||||||
|
'https://github.com/haruhi-dl/haruhi-dl/commit/07f5e2ae1c81d43ecdb5d089ce6bc279560ef25a?diff=split',
|
||||||
|
);
|
||||||
|
expect(path.domain).toEqual('github.com');
|
||||||
|
expect(path.path).toEqual('haruhi-dl/haruhi-dl');
|
||||||
|
expect(path.entity).toEqual(ENTITY_TYPE.COMMIT);
|
||||||
|
expect(path.entityID).toEqual('07f5e2ae1c81d43ecdb5d089ce6bc279560ef25a');
|
||||||
|
});
|
||||||
|
|
11
src/utils.ts
11
src/utils.ts
|
@ -82,6 +82,17 @@ export const parsePath = (path: string): Path => {
|
||||||
entityID: mobj[4],
|
entityID: mobj[4],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
mobj = /^https?:\/\/([^/]+)\/([a-zA-Z\d-]+\/(?:[a-zA-Z\d-]+\/)*?[a-zA-Z\d-]+)(?:\/-)?(?:\/commit(?:\/([a-f\d]+))(?:\.(patch|diff))?\/?)(?:\?[^#]+)?(?:#.+)?$/.exec(
|
||||||
|
path,
|
||||||
|
);
|
||||||
|
if (mobj) {
|
||||||
|
return {
|
||||||
|
domain: mobj[1],
|
||||||
|
path: mobj[2],
|
||||||
|
entity: ENTITY_TYPE.COMMIT,
|
||||||
|
entityID: mobj[3],
|
||||||
|
};
|
||||||
|
}
|
||||||
mobj = /^https?:\/\/([^/]+)\/([a-zA-Z\d-]+\/(?:[a-zA-Z\d-]+\/)*?[a-zA-Z\d-]+)\/?(?:\?[^#]+)?(?:#.+)?$/.exec(
|
mobj = /^https?:\/\/([^/]+)\/([a-zA-Z\d-]+\/(?:[a-zA-Z\d-]+\/)*?[a-zA-Z\d-]+)\/?(?:\?[^#]+)?(?:#.+)?$/.exec(
|
||||||
path,
|
path,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue