Esempio n. 1
0
        /// <summary>
        /// Fetch things from Github, returning a complete CkanModule document.
        /// </summary>
        private static JObject GitHub(JObject orig_metadata, string repo, NetFileCache cache)
        {
            // Find the release on github and download.
            GithubRelease release = GithubAPI.GetLatestRelease(repo);

            if (release == null)
            {
                log.Error("Downloaded releases for " + repo + " but there were none");
                return null;
            }
            string filename = release.Download((string) orig_metadata["identifier"], cache);

            // Extract embedded metadata, or use what we have.
            JObject metadata = MetadataFromFileOrDefault(filename, orig_metadata);

            // Check if we should auto-inflate.

            string kref = (string)metadata[expand_token];

            if (kref == (string)orig_metadata[expand_token] || kref == "#/ckan/github")
            {
                log.InfoFormat("Inflating from github metadata... {0}", metadata[expand_token]);
                release.InflateMetadata(metadata, filename, repo);
                metadata.Remove(expand_token);
            }
            else
            {
                log.WarnFormat("Not inflating metadata for {0}", orig_metadata["identifier"]);
            }

            return metadata;

        }
Esempio n. 2
0
        /// <summary>
        /// Repository is in the form "Author/Repo". Eg: "pjf/DogeCoinFlag".
        /// </summary>
        public static GithubRelease GetLatestRelease(string repository, bool prerelease)
        {
            string assetFilter = ".zip";

            int asset_match_index = repository.IndexOf(asset_match);

            if (asset_match_index > -1)
            {
                assetFilter = repository.Substring(asset_match_index + asset_match.Length);
                repository  = repository.Substring(0, asset_match_index);
                log.DebugFormat("Asset Filter: '{0}'", assetFilter);
            }

            string json = Call("repos/" + repository + "/releases");

            log.Debug("Parsing JSON...");
            JArray releases    = JArray.Parse(json);
            string releaseType = prerelease ? "pre-" : "stable";

            log.Debug("Parsed, finding most recent " + releaseType + " release");

            // Finding the most recent *stable* release means filtering
            // out on pre-releases.
            GithubRelease result = null;

            foreach (JObject release in releases)
            {
                // First, check for prerelease status...
                if (prerelease == (bool)release ["prerelease"])
                {
                    JArray assets = (JArray)release ["assets"];
                    foreach (JObject asset in assets)
                    {
                        // Then, check against the regex, which might default to ".zip"
                        if (Regex.IsMatch((string)asset ["name"], assetFilter, RegexOptions.IgnoreCase))
                        {
                            log.DebugFormat("Hit on {0}", asset.ToString());
                            result = new GithubRelease(release, asset);
                            return(result);
                        }
                    }
                }
            }

            return(result);
        }