public void Can_create_gist()
        {
            var gateway = new GitHubGateway(AccessToken);

            var gist = gateway.CreateGithubGist(
                description: "Hello World Examples",
                isPublic: true,
                textFiles: new Dictionary <string, string> {
                ["hello_world_ruby.txt"]   = "Run `ruby hello_world.rb` to print Hello World",
                ["hello_world_python.txt"] = "Run `python hello_world.py` to print Hello World",
            });

            gist.PrintDump();

            Assert.That(gist.Owner.Login, Is.EqualTo("gistlyn"));
            Assert.That(gist.Owner.Url, Is.EqualTo("https://api.github.com/users/gistlyn"));
            Assert.That(gist.Owner.Html_Url, Is.EqualTo("https://github.com/gistlyn"));

            var file = gist.Files["hello_world_ruby.txt"];

            Assert.That(file.Filename, Is.EqualTo("hello_world_ruby.txt"));
            Assert.That(file.Type, Is.EqualTo("text/plain"));
            Assert.That(file.Language, Is.EqualTo("Text"));
            Assert.That(file.Raw_Url, Does.EndWith("/hello_world_ruby.txt"));
            Assert.That(file.Size, Is.GreaterThan(0));
            Assert.That(file.Content, Does.Contain("Run `ruby hello_world.rb` to print Hello World"));

            file = gist.Files["hello_world_python.txt"];
            Assert.That(file.Filename, Is.EqualTo("hello_world_python.txt"));
            Assert.That(file.Type, Is.EqualTo("text/plain"));
            Assert.That(file.Language, Is.EqualTo("Text"));
            Assert.That(file.Raw_Url, Does.EndWith("/hello_world_python.txt"));
            Assert.That(file.Size, Is.GreaterThan(0));
            Assert.That(file.Content, Does.Contain("Run `python hello_world.py` to print Hello World"));
        }
Esempio n. 2
0
        public void Can_get_rate_limits()
        {
            var gateway = new GitHubGateway(Environment.GetEnvironmentVariable("GITHUB_TOKEN"));
            var result  = gateway.GetRateLimits();

            result.PrintDump();
        }
Esempio n. 3
0
        // TODO: Maybe expose api rate info per connection?
        // TODO: Add SyncResult (BranchCreated, PullRequestCreated, PullRequestMerged) + url
        public Syncer(
            IEnumerable<Tuple<Credentials, string>> credentialsPerRepos,
            IWebProxy proxy = null,
            Action<LogEntry> loggerCallback = null)
        {
            logCallBack = loggerCallback ?? NullLogger;

            gw = new GitHubGateway(credentialsPerRepos, proxy, logCallBack);
        }
Esempio n. 4
0
        public Syncer(
            Credentials defaultCredentials,
            IWebProxy proxy = null,
            Action<LogEntry> loggerCallback = null)
        {
            logCallBack = loggerCallback ?? NullLogger;

            gw = new GitHubGateway(defaultCredentials, proxy, logCallBack);
        }
Esempio n. 5
0
    public Syncer(
        Credentials credentials,
        IWebProxy proxy     = null,
        Action <string> log = null)
    {
        this.log = log ?? nullLogger;

        this.credentials = credentials;
        gateway          = new GitHubGateway(credentials, proxy, log);
    }
        public void Can_GetSourceTagZipUrl()
        {
            var user = "******";
            var repo = "web";
            var tag  = "v28";

            var gateway = new GitHubGateway(AccessToken);

            var zipUrlForTag = gateway.GetSourceZipUrl(user, repo, tag);

            Assert.That(zipUrlForTag, Is.EqualTo("https://github.com/NetCoreTemplates/web/archive/refs/tags/v28.zip"));
        }
        public void Can_GetSourceTagZipUrl_InvalidTag()
        {
            var user = "******";
            var repo = "web";
            var tag  = "invalid-tag";

            var gateway = new GitHubGateway(AccessToken);

            var exception = Assert.Throws <WebException>(() =>
            {
                var zipBytes = gateway.GetSourceZipUrl(user, repo, tag).GetBytesFromUrl();
            });

            Assert.That(exception, Is.Not.Null);
            Assert.That(exception.Message, Does.Contain("(404) Not Found"));
        }
        public void Can_download_public_gist()
        {
            var gateway = new GitHubGateway();
            var result  = gateway.GetGist(GistId);
            var gist    = (GithubGist)result;

            Assert.That(gist.Owner.Login, Is.EqualTo("gistlyn"));
            Assert.That(gist.Owner.Url, Is.EqualTo("https://api.github.com/users/gistlyn"));
            Assert.That(gist.Owner.Html_Url, Is.EqualTo("https://github.com/gistlyn"));

            var file = gist.Files["main.cs"];

            Assert.That(file.Filename, Is.EqualTo("main.cs"));
            Assert.That(file.Type, Is.EqualTo("text/plain"));
            Assert.That(file.Language, Is.EqualTo("C#"));
            Assert.That(file.Raw_Url, Does.EndWith("/main.cs"));
            Assert.That(file.Size, Is.GreaterThan(0));
            Assert.That(file.Content, Does.Contain("Hello, {name}!"));
        }
        public void Can_add_and_delete_gist_file()
        {
            var gateway = new GitHubGateway(AccessToken);

            var newFile = "new.txt";

            gateway.WriteGistFile(GistId, newFile, "this is a new file");

            var gist = gateway.GetGist(GistId);
            var file = gist.Files[newFile];

            Assert.That(file.Filename, Is.EqualTo(newFile));
            Assert.That(file.Type, Is.EqualTo("text/plain"));
            Assert.That(file.Content, Is.EqualTo("this is a new file"));

            gateway.DeleteGistFiles(GistId, newFile);

            gist = gateway.GetGist(GistId);
            Assert.That(gist.Files.TryGetValue(newFile, out file), Is.False);
        }
Esempio n. 10
0
        public static Dictionary <string, string> GetGistFiles(this GitHubGateway gateway, string gistId)
        {
            return(GistFilesCache.GetOrAdd(gistId, gistKey => {
                var json = gateway.GetJson($"/gists/{gistKey}");
                var response = JSON.parse(json);
                if (response is Dictionary <string, object> obj &&
                    obj.TryGetValue("files", out var oFiles) &&
                    oFiles is Dictionary <string, object> files)
                {
                    var to = new Dictionary <string, string>();
                    foreach (var entry in files)
                    {
                        var meta = (Dictionary <string, object>)entry.Value;
                        to[entry.Key] = (string)meta["content"];
                    }

                    return to;
                }

                throw new NotSupportedException($"Invalid gist response returned for '{gistKey}'");
            }));
Esempio n. 11
0
 public IgnoreResult githubWriteGistFile(GitHubGateway gateway, string gistId, string filePath, string contents)
 {
     gateway.WriteGistFile(gistId, filePath, contents);
     return(IgnoreResult.Value);
 }
Esempio n. 12
0
 public string githubSourceZipUrl(GitHubGateway gateway, string orgNames, string name) =>
 gateway.GetSourceZipUrl(orgNames, name);
Esempio n. 13
0
 public Task <object> githubSourceRepos(GitHubGateway gateway, string orgName) =>
 Task.FromResult <object>(gateway.GetSourceReposAsync(orgName));
Esempio n. 14
0
 public Task <object> githubUserAndOrgRepos(GitHubGateway gateway, string githubOrgOrUser) =>
 Task.FromResult <object>(gateway.GetUserAndOrgReposAsync(githubOrgOrUser));
Esempio n. 15
0
 public List <GithubRepo> githubUserRepos(GitHubGateway gateway, string githubUser) =>
 gateway.GetUserRepos(githubUser);
Esempio n. 16
0
 public List <GithubRepo> githubOrgRepos(GitHubGateway gateway, string githubOrg) =>
 gateway.GetOrgRepos(githubOrg);
Esempio n. 17
0
 public IgnoreResult githuDeleteGistFiles(GitHubGateway gateway, string gistId, IEnumerable <string> filePaths)
 {
     gateway.DeleteGistFiles(gistId, filePaths.ToArray());
     return(IgnoreResult.Value);
 }
Esempio n. 18
0
 public GithubGist githubCreatePrivateGist(GitHubGateway gateway, string description, Dictionary <string, string> files) =>
 gateway.CreateGithubGist(description: description, isPublic: false, files: files);
Esempio n. 19
0
 public GithubGist githubGist(GitHubGateway gateway, string gistId) =>
 gateway.GetGithubGist(gistId);
Esempio n. 20
0
 public IgnoreResult githubWriteGistFiles(GitHubGateway gateway, string gistId, Dictionary <string, string> gistFiles)
 {
     gateway.WriteGistFiles(gistId, gistFiles);
     return(IgnoreResult.Value);
 }
Esempio n. 21
0
 public IgnoreResult githuDeleteGistFiles(GitHubGateway gateway, string gistId, string filePath)
 {
     gateway.DeleteGistFiles(gistId, filePath);
     return(IgnoreResult.Value);
 }
Esempio n. 22
0
 public GithubGist githubCreateGist(GitHubGateway gateway, string description, Dictionary <string, string> files) =>
 gateway.CreateGithubGist(description: description, isPublic: true, textFiles: files);