Skip to content

Instantly share code, notes, and snippets.

@TsuyoshiUshio
Last active July 29, 2019 18:12
Show Gist options
  • Save TsuyoshiUshio/ead8a011fd50c9dc93ce0b13834ac2f8 to your computer and use it in GitHub Desktop.
Save TsuyoshiUshio/ead8a011fd50c9dc93ce0b13834ac2f8 to your computer and use it in GitHub Desktop.
Mock target class
import * as tl from 'azure-pipelines-task-lib';
import * as wa from "azure-devops-node-api/WebApi";
import * as GitInterfaces from "azure-devops-node-api/interfaces/GitInterfaces";
import VariableResolver from './variableresolver';
import { IGitApi, GitApi } from 'azure-devops-node-api/GitApi';
export interface IClientFactory {
create(pat:string): Promise<IGitApi>;
}
class ClientFactory implements IClientFactory {
public async create(pat:string): Promise<IGitApi> {
let credHandler = wa.getPersonalAccessTokenHandler(pat);
let connection = new wa.WebApi(tl.getVariable('System.TeamFoundationCollectionUri'), credHandler);
return await connection.getGitApi();
}
}
export class CreatePRCommentTask {
factory: IClientFactory;
constructor(clientFactory: IClientFactory) {
this.factory = clientFactory;
}
:
new CreatePRCommentTask(new ClientFactory()).run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment