public async Task <List <RepoFile> > FindFiles(RepositorySlug repositorySlug, string filePattern = null) { Regex regex = new Regex(filePattern); var files = await _repository.GetRepoFiles(repositorySlug); return(files.Where(f => regex.IsMatch(f.RelativePath)).Select(f => f)?.ToList()); }
public async Task <string> GetFileContent(RepositorySlug repositorySlug, string path) { var response = await _httpClient.GetAsync($"{_configuration.BaseBitBucketUrl}/rest/api/1.0/projects/{repositorySlug.ContainingProject.Name}/repos/{repositorySlug.Name}/raw/{path}"); if (response.IsSuccessStatusCode) { return(await response.Content.ReadAsStringAsync()); } return(string.Empty); }
public async Task <List <RepoFile> > GetRepoFiles(RepositorySlug repositorySlug) { var response = await _httpClient.GetAsync($"{_configuration.BaseBitBucketUrl}/rest/api/1.0/projects/{repositorySlug.ContainingProject.Name}/repos/{repositorySlug.Name}/files/?limit={_configuration.MaxFilesReturned}"); if (!response.IsSuccessStatusCode) { throw new InvalidOperationException($"Call to get files failed: {response.StatusCode}"); } var content = response.Content.ReadAsStringAsync(); var result = new List <RepoFile>(); dynamic json = JsonConvert.DeserializeObject <ExpandoObject>(await content); foreach (dynamic path in json.values) { result.Add(new RepoFile { RelativePath = path, ContainingRepositorySlug = repositorySlug }); } return(result); }