public static bool FindRepository(AzureDevOpsClientContext context, Guid projectId, string repositoryName, out GitRepository repo) { // Check if we already have a repo loaded VssConnection connection = context.Connection; GitHttpClient gitClient = connection.GetClient <GitHttpClient>(); // Check if an ID was already set (this could have been provided by the caller) if (!context.TryGetValue("repository" + repositoryName, out Guid repoId)) { repo = gitClient.GetRepositoriesAsync(projectId).Result.FirstOrDefault(c => c.Name == repositoryName); } else { repo = gitClient.GetRepositoryAsync(repoId.ToString()).Result; } if (repo != null) { context.SetValue("repository" + repositoryName, repo); } else { // create a project here? throw new Exception("No repos available for running the sample."); } return(repo != null); }
public static bool FindDefaultProject(AzureDevOpsClientContext context, out TeamProjectReference project) { // Check if we already have a default project loaded if (!context.TryGetValue("$defautProject", out project)) { var connection = context.Connection; var projectClient = connection.GetClient <ProjectHttpClient>(); // Check if an ID was already set (this could have been provided by the caller) if (!context.TryGetValue("projectId", out Guid projectId)) { context.TryGetValue("projectName", out string projectName); var projects = projectClient.GetProjects(null, top: 10).Result; project = projects.OrderBy(c => c.Name == projectName ? 0 : 1).FirstOrDefault(); } else { // Get the details for this project project = projectClient.GetProject(projectId.ToString()).Result; } } if (project != null) { context.SetValue("$defautProject", project); } else { // create a project here? throw new Exception("No projects available for running the sample."); } return(project != null); }
public static bool FindAnyTeam(AzureDevOpsClientContext context, Guid?projectId, out WebApiTeamRef team) { if (!projectId.HasValue) { if (FindDefaultProject(context, out TeamProjectReference project)) { projectId = project.Id; } } // Check if we already have a team that has been cached for this project if (!context.TryGetValue <WebApiTeamRef>("$" + projectId + "Team", out team)) { TeamHttpClient teamClient = context.Connection.GetClient <TeamHttpClient>(); team = teamClient.GetTeamsAsync(projectId.ToString(), top: 1).Result.FirstOrDefault(); if (team != null) { context.SetValue <WebApiTeamRef>("$" + projectId + "Team", team); } else { // create a team? throw new Exception("No team available for running this sample."); } } return(team != null); }
public static GitRepository FindRepository(AzureDevOpsClientContext context, Guid projectId, string repositoryName) { if (!FindRepository(context, projectId, repositoryName, out GitRepository repo)) { throw new Exception("No repositories available. Create a repo in this project and run the sample again."); } return(repo); }
public static WebApiTeamRef FindAnyTeam(AzureDevOpsClientContext context, Guid?projectId) { if (!FindAnyTeam(context, projectId, out WebApiTeamRef team)) { throw new Exception("No sample teams available. Create a project/team in this collection and run the sample again."); } return(team); }
public static TeamProjectReference FindDefaultProject(AzureDevOpsClientContext context) { if (!FindDefaultProject(context, out TeamProjectReference project)) { throw new Exception("No sample projects available. Create a project in this collection and run the sample again."); } return(project); }
public static GitRepository FindRepository(AzureDevOpsClientContext context, string repositoryName) { var project = AzureProjectHelper.FindDefaultProject(context); if (!FindRepository(context, project.Id, repositoryName, out GitRepository repo)) { throw new Exception("No repositories available. Create a repo in this project and run the sample again."); } return(repo); }
protected void InitializeAzureContext() { AzureContext = CreateContext(); AddProperty("projectName", Context.Options.ProjectName); AddProperty("repository" + Context.Options.RepositoryName, Context.Options.RepositoryId); }
public static Guid?FindRepositoryId(AzureDevOpsClientContext context, Guid projectId, string repositoryName) { var repository = FindRepository(context, projectId, repositoryName); return(repository?.Id); }
public static Guid FindDefaultProjectId(AzureDevOpsClientContext context) { return(FindDefaultProject(context).Id); }
public static string GetCurrentUserDisplayName(AzureDevOpsClientContext context) { return(context.Connection.AuthorizedIdentity.ProviderDisplayName); }
public static Guid GetCurrentUserId(AzureDevOpsClientContext context) { return(context.Connection.AuthorizedIdentity.Id); }