@altostra/core
Version:
Core library for shared types and logic
59 lines (58 loc) • 2.38 kB
TypeScript
import type { NonEmptyString } from "../../common/CustomTypes/NonEmptyString";
import type { UrlLiteral } from "../../common/Utils/Url";
export interface GitUtils {
/**
* Returns an account name describing the integrated account
*/
getAccountName(): string;
/**
* Return a URL to redirect the user's browser to, to view and manage the repository
* in the git provider
* @example
* `https://github.com/altostra/core`
* @param repository The name of the repository to get URL for
*/
getRepositoryBrowserUrl(repository: string): NonEmptyString;
getFileBrowserUrl(repository: string, branch: string, file: string): NonEmptyString;
getPullRequestsBrowserUrl(repository: string): NonEmptyString;
/**
* Generate git-clone URL
*
* @example
* `https://github.com/altostra/core.git`
* `git@github.com:altostra/core.git`
* @param repository The name of the repository to get URL for
* @param remoteURLType The remote URL type. Either `'https'` or `'ssh'`
*/
getRepositoryCloneUrl(repository: string, remoteURLType: RemoteURLType): NonEmptyString;
/**
* Return the repository name from the specified repository browser url
* @example
* const myRepoName = 'my-repo'
* const repoURL = this.getRepositoryBrowserUrl(myRepoName)
*
* myRepoName === this.getRepositoryNameFromBrowserUrl(repoURL) // true
* @param repositoryUrl The repository URL
*/
getRepositoryNameFromBrowserUrl(repositoryUrl: string): NonEmptyString;
/**
* Return the repository name from the specified repository clone url
* @param repositoryUrl The repository **clone** URL
*/
getRepositoryNameFromUrl(repositoryUrl: string): NonEmptyString;
/**
* Return a URL to redirect the user's browser to, to view and manage the account
* in the git provider
*
* @example
* `https://github.com/altostra`
*/
getAccountURL(): NonEmptyString;
/**
* Checks if the provided URLs if for a repository hosted with the current host and account
* @param repositoryUrl The repository URL (either browser or clone/remote URL)
*/
isHostedRepository(repositoryUrl: string): boolean;
}
export declare type RemoteURLType = 'https' | 'ssh';
export declare function filePathAsUrl(file: string): UrlLiteral;