如何在主题中进行存储库搜索 运行?
How do I make the repository search run within the topic?
搜索 "github.com" 个存储库的代码:
public async void searchReposit_GitHub()
{
var client = new GitHubClient(new ProductHeaderValue("my-cool-app"));
var basicAuth = new Credentials("username", "password");
client.Credentials = basicAuth;
var request = new SearchRepositoriesRequest("mvc client side framework")
{
// or go all out and search the readme, name or description?
In = new[] { InQualifier.Readme, InQualifier.Description, InQualifier.Name },
};
var result = await client.Search.SearchRepo(request);
for (int s = 0; s < 3; s++)
{
var vr = result.Items[s];
string readme_content;
string readme_name;
string readme_descript;
string readme_Html_url;
readme_name = vr.Name;
readme_descript = vr.Description;
readme_Html_url = vr.HtmlUrl;
try
{
var readme = await client.Repository.Content.GetReadme(vr.Id);
var rawText = readme.Content;
readme_content = rawText.ToString();
richTextBox1.AppendText(
" Сontent `readme` *** " + readme_content + " *** \r\n");
}
catch (Exception)
{
richTextBox1.AppendText(
" Сontent `readme` - empty ххх" + " \r\n"); // url
// return;
// throw;
}
}
}
有主题github.com/topics/chrome-extensions
问题
如何让代码看起来在github.com/topics/chrome-extensions里面?
我会补充的。
"Chrome extension" (github.com/topics/chrome-extensions) 包含 95 个存储库。
如何在包含 "Chrome extension" github.com/topics/chrome-extensions 的 95 个存储库中搜索 "README.MD" 中我需要的词?
不幸的是,Octokit.NET 目前似乎根本不支持主题。所以似乎没有一个好的和简单的方法。
但是,有一种方法...通过 API 访问主题目前仅作为预览提供。请参阅 List all topics for a repository 并特别注意预览版的警告和限制。
因此您可以像这样自己构建 HTTP 请求:
private static async Task<Topics> GetTopics(string repoFullName)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/vnd.github.mercy-preview+json"));
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(
Encoding.ASCII.GetBytes(
string.Format("{0}:{1}", "username", "password"))));
client.DefaultRequestHeaders.Add("User-Agent", "my-cool-app");
var stringTask = client.GetStringAsync(
$"https://api.github.com/repos/{repoFullName}/topics");
var response = await stringTask;
var topics = JsonConvert.DeserializeObject<Topics>(response);
return topics;
}
我正在使用 Newtonsoft.Json 库反序列化响应,我的 Topics
class 看起来像这样:
public class Topics
{
public List<string> names { get; set; }
}
然后在你的循环中你可以这样使用:
var topics = await GetTopics(vr.FullName);
if (!topics.names.Contains("chrome-extensions"))
{
continue;
}
您可能还想检查单数主题 chrome-extension
。它似乎更常用,因为目前有超过 3000 个存储库!
搜索 "github.com" 个存储库的代码:
public async void searchReposit_GitHub()
{
var client = new GitHubClient(new ProductHeaderValue("my-cool-app"));
var basicAuth = new Credentials("username", "password");
client.Credentials = basicAuth;
var request = new SearchRepositoriesRequest("mvc client side framework")
{
// or go all out and search the readme, name or description?
In = new[] { InQualifier.Readme, InQualifier.Description, InQualifier.Name },
};
var result = await client.Search.SearchRepo(request);
for (int s = 0; s < 3; s++)
{
var vr = result.Items[s];
string readme_content;
string readme_name;
string readme_descript;
string readme_Html_url;
readme_name = vr.Name;
readme_descript = vr.Description;
readme_Html_url = vr.HtmlUrl;
try
{
var readme = await client.Repository.Content.GetReadme(vr.Id);
var rawText = readme.Content;
readme_content = rawText.ToString();
richTextBox1.AppendText(
" Сontent `readme` *** " + readme_content + " *** \r\n");
}
catch (Exception)
{
richTextBox1.AppendText(
" Сontent `readme` - empty ххх" + " \r\n"); // url
// return;
// throw;
}
}
}
有主题github.com/topics/chrome-extensions
问题
如何让代码看起来在github.com/topics/chrome-extensions里面?
我会补充的。
"Chrome extension" (github.com/topics/chrome-extensions) 包含 95 个存储库。
如何在包含 "Chrome extension" github.com/topics/chrome-extensions 的 95 个存储库中搜索 "README.MD" 中我需要的词?
不幸的是,Octokit.NET 目前似乎根本不支持主题。所以似乎没有一个好的和简单的方法。
但是,有一种方法...通过 API 访问主题目前仅作为预览提供。请参阅 List all topics for a repository 并特别注意预览版的警告和限制。
因此您可以像这样自己构建 HTTP 请求:
private static async Task<Topics> GetTopics(string repoFullName)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/vnd.github.mercy-preview+json"));
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(
Encoding.ASCII.GetBytes(
string.Format("{0}:{1}", "username", "password"))));
client.DefaultRequestHeaders.Add("User-Agent", "my-cool-app");
var stringTask = client.GetStringAsync(
$"https://api.github.com/repos/{repoFullName}/topics");
var response = await stringTask;
var topics = JsonConvert.DeserializeObject<Topics>(response);
return topics;
}
我正在使用 Newtonsoft.Json 库反序列化响应,我的 Topics
class 看起来像这样:
public class Topics
{
public List<string> names { get; set; }
}
然后在你的循环中你可以这样使用:
var topics = await GetTopics(vr.FullName);
if (!topics.names.Contains("chrome-extensions"))
{
continue;
}
您可能还想检查单数主题 chrome-extension
。它似乎更常用,因为目前有超过 3000 个存储库!