diff --git a/samples/linqpad-samples/1-introducing-octokit.linq b/samples/linqpad-samples/1-introducing-octokit.linq new file mode 100644 index 00000000..30ff533b --- /dev/null +++ b/samples/linqpad-samples/1-introducing-octokit.linq @@ -0,0 +1,36 @@ + + Octokit.Reactive + Rx-Main + Octokit + System.Reactive.Linq + System.Threading.Tasks + + +async Task Main(string[] args) +{ + var owner = string.Empty; + var reponame = string.Empty; + + #if CMD + owner = args[0]; + reponame = args[1]; + #else + owner = "octokit"; + reponame = "octokit.net"; + #endif + + var client = new GitHubClient(new Octokit.ProductHeaderValue("octokit.samples")); + + var repository = await client.Repository.Get(owner, reponame); + + Console.WriteLine(String.Format("Octokit.net can be found at {0}\n", repository.HtmlUrl)); + + Console.WriteLine("It currently has {0} watchers and {1} forks\n", + repository.StargazersCount, + repository.ForksCount); + + Console.WriteLine("It has {0} open issues\n", repository.OpenIssuesCount); + + Console.WriteLine("And GitHub thinks it is a {0} project", repository.Language); + +} diff --git a/samples/linqpad-samples/10-search-issues.linq b/samples/linqpad-samples/10-search-issues.linq new file mode 100644 index 00000000..24e470b1 --- /dev/null +++ b/samples/linqpad-samples/10-search-issues.linq @@ -0,0 +1,69 @@ + + Octokit.Reactive + Rx-Main + Octokit + Octokit.Reactive + System + System.Reactive.Linq + System.Threading.Tasks + + +async Task Main() +{ + var owner = string.Empty; + var reponame = string.Empty; + + //Search Issues with xamarin keyword and get the results + GitHubClient client = new GitHubClient( + new Octokit.ProductHeaderValue("Octokit.samples")); + #if CMD + owner = args[0]; + reponame = args[1]; + // For integration testing + client.Credentials = new Credentials( + Environment.GetEnvironmentVariable("OCTOKIT_GITHUBUSERNAME"), + Environment.GetEnvironmentVariable("OCTOKIT_GITHUBPASSWORD")); + #else + owner = "octokit"; + reponame = "octokit.net"; + // or if you don't want to give an app your creds + // you can use a token from an OAuth app + // Here is the URL to get tokens https://github.com/settings/tokens + // and save the token using Util.SetPassword("github","CHANGETHIS") + client.Credentials = new Credentials(Util.GetPassword("github")); + + #endif + + + var issue = new SearchIssuesRequest("xamarin"); + issue.Repos.Add(owner,reponame); + issue.SortField = IssueSearchSort.Updated; + var searchresults = await client.Search.SearchIssues(issue); + + //For every issue get the comments for it + var commentsclient = client.Issue.Comment; + var comments = searchresults.Items.Select(async i => + new { IssueNumber = i.Number, + Comments = await commentsclient + .GetAllForIssue(owner, reponame, i.Number)}); + + var issueComments = await Task.WhenAll( comments); + + + //Combine the comments with Issue and then dump it. + searchresults.Items.Select(i => new + { + Number = Util.RawHtml(new XElement("a", + new XAttribute("href", i.HtmlUrl.ToString()), i.Number)), + i.Title, + i.Body, + i.State, + Comments = issueComments.FirstOrDefault(c => c.IssueNumber == i.Number) + .Comments.Select(c => + new { User = c.User.Id, + Name = c.User.Login, + Content = c.Body, + Date = c.CreatedAt, + Id = c.Id, c.Body}) + } ).Dump(); +} \ No newline at end of file diff --git a/samples/linqpad-samples/2-releases.linq b/samples/linqpad-samples/2-releases.linq new file mode 100644 index 00000000..251ee8c2 --- /dev/null +++ b/samples/linqpad-samples/2-releases.linq @@ -0,0 +1,45 @@ + + Octokit.Reactive + Rx-Main + Octokit + System.Net + System.Threading.Tasks + + +async Task Main(string[] args) +{ + var owner = string.Empty; + var reponame = string.Empty; + + #if CMD + owner = args[0]; + reponame = args[1]; + #else + owner = "octokit"; + reponame = "octokit.net"; + #endif + + var client = new GitHubClient(new Octokit.ProductHeaderValue("octokit.samples")); + + //Get releases for the octokit + var releases = await client.Release.GetAll(owner, reponame); + releases.Select(r => new { r.Name, r.Body }).Dump("Releases"); + + //Don't want draft release and because we are using reactive the first one is the latest one. + var latestrelease = releases.First(r => r.Draft == false).Dump("Latest Octokit"); + + //Gets the assets for the latest relase + var assets = await client.Release.GetAllAssets(owner,reponame,latestrelease.Id); + assets.Dump("Assets"); + var latestreleaseassetid = assets.First(a => a.Name.Contains("Reactive")).Id; + var asset = await client.Release.GetAsset(owner,reponame,latestreleaseassetid); + asset.DownloadCount.Dump("Download Count for this release"); + + //Download the release + var wc = new WebClient(); + var filename = Path.Combine( Path.GetTempPath(),"Octokit-Reactive.nupkg"); + await wc.DownloadFileTaskAsync(asset.BrowserDownloadUrl,filename); + filename.Dump(); +} + +// Define other methods and classes here \ No newline at end of file diff --git a/samples/linqpad-samples/3-browse-repositories.linq b/samples/linqpad-samples/3-browse-repositories.linq new file mode 100644 index 00000000..d9384355 --- /dev/null +++ b/samples/linqpad-samples/3-browse-repositories.linq @@ -0,0 +1,39 @@ + + Octokit.Reactive + Rx-Main + Octokit + Octokit.Reactive + System.Threading.Tasks + + +async Task Main(string[] args) +{ + var userName = string.Empty; + GitHubClient client = new GitHubClient(new Octokit.ProductHeaderValue("octokit.samples")); + + #if CMD + userName = args[0]; + // For integration testing + client.Credentials = new Credentials( + Environment.GetEnvironmentVariable("OCTOKIT_GITHUBUSERNAME"), + Environment.GetEnvironmentVariable("OCTOKIT_GITHUBPASSWORD")); + + #else + userName = "naveensrinivasan"; + // basic authentication + //client.Credentials = new Credentials("username", "password"); + + // or if you don't want to give an app your creds + // you can use a token from an OAuth app + // Here is the URL to get tokens https://github.com/settings/tokens + // and save the token using Util.SetPassword("github","CHANGETHIS") + client.Credentials = new Credentials(Util.GetPassword("github")); + #endif + + var repositories = await client.Repository.GetAllForUser(userName); + repositories.Select(r => new { r.Name }).Dump(userName + "Repos"); + + // and then fetch the repositories for the current user + var repos = await client.Repository.GetAllForCurrent(); + repos.Select(r => r.Name).Dump("Your Repos"); +} \ No newline at end of file diff --git a/samples/linqpad-samples/4-observable-browse-repositories.linq b/samples/linqpad-samples/4-observable-browse-repositories.linq new file mode 100644 index 00000000..a5859986 --- /dev/null +++ b/samples/linqpad-samples/4-observable-browse-repositories.linq @@ -0,0 +1,22 @@ + + Octokit.Reactive + Rx-Main + Octokit + Octokit.Reactive + System + System.Reactive.Linq + + +void Main() +{ + var owner = string.Empty; + + #if CMD + owner = args[0]; + #else + owner = "octokit"; + #endif + + var client = new ObservableGitHubClient(new Octokit.ProductHeaderValue("Octokit.samples")); + client.Repository.GetAllForUser(owner).Select(r => r.Name).Dump(); +} \ No newline at end of file diff --git a/samples/linqpad-samples/5-interact-with-git-database.linq b/samples/linqpad-samples/5-interact-with-git-database.linq new file mode 100644 index 00000000..0dded972 --- /dev/null +++ b/samples/linqpad-samples/5-interact-with-git-database.linq @@ -0,0 +1,39 @@ + + Octokit + Rx-Main + Octokit + System.Threading.Tasks + + +async Task Main(string[] args) +{ + var owner = string.Empty; + var reponame = string.Empty; + + GitHubClient client = new GitHubClient(new Octokit.ProductHeaderValue("Octokit.samples")); + + #if CMD + owner = args[0]; + reponame = args[1]; + #else + owner = "octokit"; + reponame = "octokit.net"; + #endif + + + var releases = await client.Release.GetAll(owner, reponame); + + // we have to build up this tag because release tags + // are just lightweight tags. you can read more about + // the differences between lightweight tags and annotated tags + // here: http://git-scm.com/book/en/Git-Basics-Tagging#Creating-Tags + + // we can fetch the tag for this release + var reference = "tags/" + releases[0].TagName; + var tag = await client.GitDatabase.Reference.Get(owner, reponame, reference); + tag.Dump(); + + // and we can fetch the commit associated with this release + var commit = await client.GitDatabase.Commit.Get(owner, reponame, tag.Object.Sha); + commit.Dump(); +} \ No newline at end of file diff --git a/samples/linqpad-samples/6-create-repository.linq b/samples/linqpad-samples/6-create-repository.linq new file mode 100644 index 00000000..a658174a --- /dev/null +++ b/samples/linqpad-samples/6-create-repository.linq @@ -0,0 +1,99 @@ + + <RuntimeDirectory>\System.Net.Http.dll + <RuntimeDirectory>\System.Runtime.dll + Octokit + Octokit.Reactive + Rx-Main + System.Reactive.Linq + System.Net.Http.Headers + Octokit + System.Threading.Tasks + + +async Task Main(string[] args) +{ + var owner = string.Empty; + var reponame = string.Empty; + + GitHubClient client = new GitHubClient( + new Octokit.ProductHeaderValue("Octokit.samples")); + #if CMD + owner = args[0]; + reponame = args[1]; + // For integration testing + client.Credentials = new Credentials( + Environment.GetEnvironmentVariable("OCTOKIT_GITHUBUSERNAME"), + Environment.GetEnvironmentVariable("OCTOKIT_GITHUBPASSWORD")); + #else + owner = "naveensrinivasan"; + reponame = "my-awesome-repo-" + Environment.TickCount; + // or if you don't want to give an app your creds + // you can use a token from an OAuth app + // Here is the URL to get tokens https://github.com/settings/tokens + // and save the token using Util.SetPassword("github","CHANGETHIS") + client.Credentials = new Credentials(Util.GetPassword("github")); + + #endif + + var email = "person@cooldomain.com"; + + // 1 - create a repository through the API + var newRepo = new NewRepository(reponame) + { + AutoInit = true // very helpful! + }; + + var repository = await client.Repository.Create(newRepo); + Console.WriteLine("Browse the repository at: " + repository.HtmlUrl); + + // 2 - create a blob containing the contents of our README + var newBlob = new NewBlob() { + Content = "#MY AWESOME REPO\rthis is some code\rI made it on: " + + DateTime.Now.ToString(), + Encoding = EncodingType.Utf8 + }; + + var createdBlob = await client.GitDatabase.Blob + .Create(owner, reponame, newBlob); + createdBlob.Dump(); + + // 3 - create a tree which represents just the README file + var newTree = new NewTree(); + newTree.Tree.Add(new NewTreeItem() { + Path = "README.md", + Mode = Octokit.FileMode.File, + Sha = createdBlob.Sha, + Type = TreeType.Blob + }); + + var createdTree = await client.GitDatabase.Tree + .Create(owner, reponame, newTree); + + createdTree.Dump(); + + // 4 - this commit should build on the current master branch + var master = await client.GitDatabase.Reference + .Get(owner, reponame, "heads/master"); + + var newCommit = new NewCommit( + "Hello World!", + createdTree.Sha, + new[] { master.Object.Sha }) + { Author = new SignatureResponse(owner,email,DateTime.UtcNow)}; + + var createdCommit = await client.GitDatabase.Commit + .Create(owner, reponame, newCommit); + + createdCommit.Dump(); + + // 5 - create a reference for the master branch + var updateReference = new ReferenceUpdate(createdCommit.Sha); + var updatedReference = await client.GitDatabase + .Reference.Update(owner, reponame, "heads/master", updateReference); + updatedReference.Dump(); + + // Deleting a repository requires admin access. + //If OAuth is used, the `delete_repo` scope is required. + await client.Repository.Delete(owner, reponame); + "Repo Clean up!".Dump(reponame + " has been deleted"); +} \ No newline at end of file diff --git a/samples/linqpad-samples/7-search-for-repos.linq b/samples/linqpad-samples/7-search-for-repos.linq new file mode 100644 index 00000000..36f7c2f9 --- /dev/null +++ b/samples/linqpad-samples/7-search-for-repos.linq @@ -0,0 +1,31 @@ + + <RuntimeDirectory>\System.Net.Http.dll + <RuntimeDirectory>\System.Runtime.dll + Octokit + Octokit.Reactive + Rx-Main + System.Reactive.Linq + System.Net.Http.Headers + Octokit + System.Threading.Tasks + + +async Task Main() +{ + //This makes discovering code fun!! + var client = new GitHubClient(new Octokit.ProductHeaderValue("octokit")); + var gorepos = await client.Search.SearchRepo(new SearchRepositoriesRequest() + {Language = Language.Go}); + + gorepos.Items.OrderByDescending (i => i.CreatedAt) + .OrderByDescending (i => i.StargazersCount) + .Take(50) + .Select (i => new { + Name = i.Name, + Description = i.Description , + LastUpdated = i.UpdatedAt, + Url = i.HtmlUrl, + WatchCount = i.StargazersCount + }) + .Dump(); +} \ No newline at end of file diff --git a/samples/linqpad-samples/8-gists.linq b/samples/linqpad-samples/8-gists.linq new file mode 100644 index 00000000..9a9fcbf0 --- /dev/null +++ b/samples/linqpad-samples/8-gists.linq @@ -0,0 +1,42 @@ + + Octokit.Reactive + Rx-Main + Octokit + Octokit.Reactive + System + System.Reactive.Linq + System.Threading.Tasks + + +async Task Main(string[] args) +{ + var userName = string.Empty; + GitHubClient client = new GitHubClient(new Octokit.ProductHeaderValue("Octokit.Samples")); + #if CMD + userName = args[0]; + + // For integration testing + client.Credentials = new Credentials( + Environment.GetEnvironmentVariable("OCTOKIT_GITHUBUSERNAME"), + Environment.GetEnvironmentVariable("OCTOKIT_GITHUBPASSWORD")); + #else + userName = "naveensrinivasan"; + client.Credentials = new Credentials(Util.GetPassword("github")); + #endif + + var observableclient = new ObservableGitHubClient(client); + + var gists = await observableclient.Gist.GetAllForUser(userName).Dump(); + + //Create A gist + var gist = new NewGist() { Description = "Gist from LinqPad", Public = true}; + gist.Files.Add("test","Test file"); + + //Star a gist + var createdgist = await observableclient.Gist.Create(gist); + await observableclient.Gist.Star(createdgist.Id); + + // Add a comment to the gist + var comment = await observableclient.Gist + .Comment.Create(createdgist.Id,"Comment from linqpad").Dump(); +} \ No newline at end of file diff --git a/samples/linqpad-samples/9-issues.linq b/samples/linqpad-samples/9-issues.linq new file mode 100644 index 00000000..7bdcd682 --- /dev/null +++ b/samples/linqpad-samples/9-issues.linq @@ -0,0 +1,37 @@ + + Octokit.Reactive + Rx-Main + Octokit + Octokit.Reactive + System + System.Reactive.Linq + System.Threading.Tasks + + +async Task Main() +{ + var userName = string.Empty; + GitHubClient client = new GitHubClient(new Octokit.ProductHeaderValue("Octokit.Samples")); +#if CMD + userName = args[0]; + +#else + userName = "naveensrinivasan"; + client.Credentials = new Credentials(Util.GetPassword("github")); +#endif + client.Credentials = new Credentials(Util.GetPassword("github")); + IIssuesClient issuesclient = client.Issue; + var myissues = await issuesclient.GetAllForCurrent(); + myissues.Select(m => new { m.Title, m.Body}).Dump(); + + //var issue = new NewIssue("Test"); + + //var newissue = await issuesclient.Create(owner,reponame,new NewIssue("Test")); + // + //newissue.Dump(); + + var allissues = await issuesclient.GetAllForRepository("octokit", "octokit.net"); + allissues.Select(a => new { a.Title, a.Body}).Dump(); + +} +