public GitHubRelease build(string releasesUrl, GitHubUpdateManifest manifest)
        {
            HtmlWeb      web = new HtmlWeb();
            HtmlDocument doc = web.Load(releasesUrl);

            HtmlNode nodeLatestRelease = null;
            bool     prerelease        = false;

            if (manifest.AllowPreRelease)
            {
                nodeLatestRelease = doc.DocumentNode.SelectSingleNode(XpathLatestPreRelease);

                if (nodeLatestRelease != null) // if the latest release is not a pre-release
                {
                    prerelease = true;
                }
                else
                {
                    nodeLatestRelease = doc.DocumentNode.SelectSingleNode(XpathLatestRelease);
                }
            }
            else
            {
                nodeLatestRelease = doc.DocumentNode.SelectSingleNode(XpathLatestRelease);
            }

            return(new XpathGitHubReleaseBuilder().build(nodeLatestRelease.InnerHtml, prerelease, manifest));
        }
Exemple #2
0
        public GitHubRelease build(string releaseHtml, bool preRelease, GitHubUpdateManifest manifest)
        {
            HtmlDocument releaseDocument = new HtmlDocument();

            releaseDocument.LoadHtml(releaseHtml);

            HtmlNode releaseNode = releaseDocument.DocumentNode;

            string tag      = releaseNode.SelectSingleNode("//span[@class='css-truncate-target']").InnerText;
            string name     = releaseNode.SelectSingleNode("//h1[@class='release-title']//a").InnerText;
            string htmlBody = releaseNode.SelectSingleNode("//div[@class='markdown-body']")?.InnerHtml;

            HtmlNodeCollection binariesNodes = releaseNode.SelectNodes("//ul[@class='release-downloads']//a[@href]");

            List <IVersionFile> releaseFiles = new List <IVersionFile>();

            foreach (string file in manifest.Repository.Files)
            {
                string theoricFileName = file.Replace("{version}", tag);

                foreach (HtmlNode node in binariesNodes)
                {
                    string href = node.GetAttributeValue("href", null);

                    if (href.Contains(theoricFileName))
                    {
                        //TODO: clean up this hard coded url
                        string binaryDownloadUrl = "https://github.com" + href;
                        string binaryName        = binaryDownloadUrl.Split('/').Last();
                        long   binarySize        = 0;

                        using (WebClient wc = new WebClient())
                        {
                            using (Stream stream = wc.OpenRead(binaryDownloadUrl))
                            {
                                binarySize = long.Parse(wc.ResponseHeaders["Content-Length"]);
                            }
                        }

                        releaseFiles.Add(new RemoteFile(binaryName, binarySize, binaryDownloadUrl));
                    }
                }
            }

            return(new GitHubRelease(manifest.Repository, tag, name, htmlBody, releaseFiles, preRelease));
        }