|
| 1 | +/* eslint-disable @typescript-eslint/naming-convention */ |
| 2 | +import {ApiClient} from "../api-client"; |
| 3 | + |
| 4 | +export interface GetRepoResponse { |
| 5 | + /** |
| 6 | + * ID of the repo object in the workspace. |
| 7 | + */ |
| 8 | + id: number; |
| 9 | + |
| 10 | + /** |
| 11 | + * URL of the Git repository to be linked. |
| 12 | + */ |
| 13 | + url?: string; |
| 14 | + |
| 15 | + /** |
| 16 | + * Git provider. This field is case-insensitive. The available Git providers are gitHub, bitbucketCloud, gitLab, azureDevOpsServices, gitHubEnterprise, bitbucketServer, gitLabEnterpriseEdition and awsCodeCommit. |
| 17 | + */ |
| 18 | + provider?: string; |
| 19 | + |
| 20 | + /** |
| 21 | + * Desired path for the repo in the workspace. Must be in the format /Repos/{folder}/{repo-name}. |
| 22 | + */ |
| 23 | + path: string; |
| 24 | + |
| 25 | + /** |
| 26 | + * Branch that the local version of the repo is checked out to. |
| 27 | + */ |
| 28 | + branch?: string; |
| 29 | + |
| 30 | + /** |
| 31 | + * SHA-1 hash representing the commit ID of the current HEAD of the repo. |
| 32 | + */ |
| 33 | + head_commit_id?: string; |
| 34 | +} |
| 35 | + |
| 36 | +export interface GetReposRequest { |
| 37 | + path_prefix?: string; |
| 38 | + next_page_token?: string; |
| 39 | +} |
| 40 | + |
| 41 | +export interface GetReposResponse { |
| 42 | + repos: Array<GetRepoResponse>; |
| 43 | + next_page_token?: string; |
| 44 | +} |
| 45 | + |
| 46 | +export interface CreateRepoRequest { |
| 47 | + /** URL of the Git repository to be linked. */ |
| 48 | + url: string; |
| 49 | + provider: string; |
| 50 | + path?: string; |
| 51 | +} |
| 52 | + |
| 53 | +export interface DeleteRepoRequest { |
| 54 | + id: number; |
| 55 | +} |
| 56 | + |
| 57 | +export interface DeleteRepoResponse {} |
| 58 | + |
| 59 | +export interface GetRepoRequest { |
| 60 | + id: number; |
| 61 | +} |
| 62 | + |
| 63 | +export interface UpdateRepoRequest { |
| 64 | + id: number; |
| 65 | + |
| 66 | + /** Branch that the local version of the repo is checked out to. */ |
| 67 | + branch?: string; |
| 68 | + |
| 69 | + /** |
| 70 | + * Tag that the local version of the repo is checked out to. Updating the |
| 71 | + * repo to a tag puts the repo in a detached HEAD state. Before committing |
| 72 | + * new changes, you must update the repo to a branch instead of the |
| 73 | + * detached HEAD. |
| 74 | + */ |
| 75 | + tag?: string; |
| 76 | +} |
| 77 | + |
| 78 | +/** |
| 79 | + * The repos API allows users to manage their |
| 80 | + * [repos](https://docs.databricks.com/repos.html). Users can use the API to |
| 81 | + * access all repos that they have manage permissions on. |
| 82 | + */ |
| 83 | +export class ReposService { |
| 84 | + constructor(readonly client: ApiClient) {} |
| 85 | + |
| 86 | + /** |
| 87 | + * Returns repos that the calling user has Manage permissions on. Results |
| 88 | + * are paginated with each page containing twenty repos. |
| 89 | + */ |
| 90 | + async getRepos(req: GetReposRequest): Promise<GetReposResponse> { |
| 91 | + return (await this.client.request( |
| 92 | + "/api/2.0/repos", |
| 93 | + "GET", |
| 94 | + req |
| 95 | + )) as GetReposResponse; |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Creates a repo in the workspace and links it to the remote Git repo |
| 100 | + * specified. Note that repos created programmatically must be linked to a |
| 101 | + * remote Git repo, unlike repos created in the browser. |
| 102 | + */ |
| 103 | + async createRepo(req: CreateRepoRequest): Promise<GetRepoResponse> { |
| 104 | + return (await this.client.request( |
| 105 | + "/api/2.0/repos", |
| 106 | + "POST", |
| 107 | + req |
| 108 | + )) as GetRepoResponse; |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * Returns the repo with the given repo ID. |
| 113 | + */ |
| 114 | + async getRepo(req: GetRepoRequest): Promise<GetRepoResponse> { |
| 115 | + return (await this.client.request( |
| 116 | + `/api/2.0/repos/${req.id}`, |
| 117 | + "GET", |
| 118 | + req |
| 119 | + )) as GetRepoResponse; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Updates the repo to a different branch or tag, or updates the repo to |
| 124 | + * the latest commit on the same branch. |
| 125 | + */ |
| 126 | + async updateRepo(req: UpdateRepoRequest): Promise<GetRepoResponse> { |
| 127 | + return (await this.client.request( |
| 128 | + `/api/2.0/repos/${req.id}`, |
| 129 | + "PATCH", |
| 130 | + req |
| 131 | + )) as GetRepoResponse; |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Deletes the specified repo |
| 136 | + */ |
| 137 | + async deleteRepo(req: DeleteRepoRequest): Promise<DeleteRepoResponse> { |
| 138 | + return (await this.client.request( |
| 139 | + `/api/2.0/repos/${req.id}`, |
| 140 | + "DELETE", |
| 141 | + req |
| 142 | + )) as DeleteRepoResponse; |
| 143 | + } |
| 144 | +} |
0 commit comments