microsoft / azure-devops-extension-sdk

Client SDK for developing Azure DevOps extensions
MIT License
123 stars 38 forks source link

How to get an instance of GitRestClient? #46

Closed georgdrobny closed 2 years ago

georgdrobny commented 2 years ago

I need to get an instance of the GitRestClient in my extension (Custom Work Item Control). When I was using the "old" extension SDK I did the following:

import * as GitRestClient from "TFS/VersionControl/GitRestClient"; private gitClient: GitRestClient.GitHttpClient4_1; this.gitClient = GitRestClient.getClient();

But I'm currently using the new SDK and want to stay on it. the getClient() method does not exist on the GitRestClient. I'm importing the types as follows: import { GitRestClient, GitVersionDescriptor, GitVersionOptions, GitVersionType, VersionControlRecursionType, } from "azure-devops-extension-api/Git";

But how do I get an instance of the GitRest Client? I can see that there's a getClient in azure-devops-extension-api but it requires a RestClientFactory and it looks there's a default which calls the constructor with IVssRestClientOptions which would need to be passed.

As I said I would like to obtain an instance of the GitRestClient in my custom control to call some GitAPI's.

Thanks for your support. Georg

hanneswidrig commented 2 years ago

export const gitClient = getClient(GitRestClient); should be all you need.

georgdrobny commented 2 years ago

Perfect, thanks Hannes. Works :-)