如何使存储库搜索在主题中运行



搜索"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 + " *** rn"); 
        }
        catch (Exception)
        {
            richTextBox1.AppendText(
                " Сontent `readme` -  empty ххх" +  " rn"); // url
            // return;
            // throw;
        }                   
    }
}

有一个主题 github.com/topics/chrome-extensions

问题
如何使代码看起来 github.com/topics/chrome-extensions 内部?

我会补充。
"Chrome 扩展程序"(github.com/topics/chrome-extensions) 包含 95 个存储库。

如何在"自述文件"中搜索我需要的单词。MD"在包含"Chrome 扩展程序"github.com/topics/chrome-extensions 的 95 个存储库中?

不幸的是,它看起来 Octokit.NET 目前根本不支持主题。所以似乎没有一个好而简单的方法。

但是,有一种方法...通过 API 访问主题目前仅提供预览版。请参阅列出存储库的所有主题,并特别注意预览版的警告和限制。

因此,您可以像这样自己构造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类如下所示:

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 个存储库!

相关内容

  • 没有找到相关文章

最新更新