feat: add git tag to AzureUrl class

Signed-off-by: Gio Divino <giodivino.tech@gmail.com>
This commit is contained in:
Gio Divino
2025-11-08 04:17:21 +08:00
parent 3fa839c200
commit 6999f6df21
2 changed files with 16 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/integration': minor
---
The AzureUrl class in the @backstage/integration package is now able to process BOTH git branches and git tags. Initially this class only processed git branches and threw an error when non-branch Azure URLs were passed in.
+11 -7
View File
@@ -14,8 +14,6 @@
* limitations under the License.
*/
const VERSION_PREFIX_GIT_BRANCH = 'GB';
export class AzureUrl {
/**
* Parses an azure URL as copied from the browser address bar.
@@ -50,16 +48,19 @@ export class AzureUrl {
const path = url.searchParams.get('path') ?? undefined;
let ref;
let prefix;
const version = url.searchParams.get('version');
if (version) {
const prefix = version.slice(0, 2);
if (prefix !== 'GB') {
throw new Error('Azure URL version must point to a git branch');
prefix = version.slice(0, 2);
if (prefix !== 'GB' && prefix !== 'GT') {
throw new Error(
'Azure URL version must point to a git branch or git tag',
);
}
ref = version.slice(2);
}
return new AzureUrl(url.origin, owner, project, repo, path, ref);
return new AzureUrl(url.origin, owner, project, repo, path, ref, prefix);
}
#origin: string;
@@ -68,6 +69,7 @@ export class AzureUrl {
#repo: string;
#path?: string;
#ref?: string;
#prefix?: string;
private constructor(
origin: string,
@@ -76,6 +78,7 @@ export class AzureUrl {
repo: string,
path?: string,
ref?: string,
prefix?: string,
) {
this.#origin = origin;
this.#owner = owner;
@@ -83,6 +86,7 @@ export class AzureUrl {
this.#repo = repo;
this.#path = path;
this.#ref = ref;
this.#prefix = prefix;
}
#baseUrl = (...parts: string[]): URL => {
@@ -108,7 +112,7 @@ export class AzureUrl {
url.searchParams.set('path', this.#path);
}
if (this.#ref) {
url.searchParams.set('version', VERSION_PREFIX_GIT_BRANCH + this.#ref);
url.searchParams.set('version', this.#prefix + this.#ref);
}
return url.toString();