Github最后提交? [英] Github Last Commit?

查看:80
本文介绍了Github最后提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以iv一直在四处寻找试图找到我如何可以转到指定的github页面并获取最后的提交值并将其绑定到我的应用程序中的值的方法,似乎没有任何意义,并且没有多少(如果有的话)一切都基于的好例子.似乎没有人愿意分享他们在这个主题上的知识.

So iv been looking around trying to find out how i can go to a specified github page and get the last commit value and bind this into a value in my application, nothing seems to make sense and there aren't many if any good examples to base anything on. As well as noone seeming to want to share their knowledge on this topic.

我试图仅从github页面获取最后的提交值,并将其用作我的应用程序中的值,有人可以给我一个如何执行此操作的示例吗?我正在使用带有WPF项目类型的C#.

Im trying to get the last commit value only from a github page, and use that as a value in my application, can someone give me an example of how to do this? I am using C# with a WPF project type.

推荐答案

如果要在本地克隆存储库并进行检查,可以使用 libgit2sharp .如果那不是您的选择,则可以使用github API.您需要的网址是:

If you want to clone the repository locally and inspect it, you could use GitSharp libgit2sharp. If that is not an option for you then you can use the github API. The url you are after is:

https://api.github.com/repos/<repo_path>/commits

例如 https://api.github.com/repos/NancyFx/Nancy/commits

using (var client = new HttpClient())
{
    client.DefaultRequestHeaders.Add("User-Agent",
        "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");

    using (var response = client.GetAsync("https://api.github.com/repos/NancyFx/Nancy/commits").Result)
    {
        var json = response.Content.ReadAsStringAsync().Result;

        dynamic commits = JArray.Parse(json);
        string lastCommit = commits[0].commit.message;
    }
}

如评论中所述,这会将您的实现耦合到github,因此,如果选择第二个选项,请确保将来您的应用无需与其他git主机一起使用.

As mentioned in comments, this will couple your implementation to github, so be sure that your app doesn't need to work with other git hosts in the future if you choose the 2nd option.

这篇关于Github最后提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆