public void FixtureSetup() { _config = new Dictionary <string, string>() { { "url", this.PostUrl }, { "content-type", "json" } }; _events = new[] { SupportedEvents.Push }; Api = GitHubApi.Create(); Authorize(new[] { Scopes.Repo }) .ContinueWith(t => this.ClearHooks()) .ContinueWith( t => { Task.Delay(10000); _tempHook = Api.Hooks.Create( _testUsername, _testRepo, new HookBase() { Name = HookName.Web, IsActive = true, Events = _events, Config = _config }).Result; }).Wait(); }
private static async Task TransferIssues(string githubRepo) { var issues = await GitlabApi.GetProjectIssues(); // var issues = new JArray(await GitlabApi.GetIssue(80)); int count = 1, tot = issues.Count; foreach (var issue in issues) { Console.Write($"\rissue {count} of {tot}"); var issueId = issue["iid"].ToObject <int>(); var comments = await GitlabApi.GetIssueComments(issueId); var githubId = await GitHubApi.CreateIssue(new { Title = issue["title"].Value <string>(), Body = $"{issue["description"].Value<string>()}\n\n > Created By: {issue["author"]["name"].Value<string>()}", Labels = issue["labels"].ToObject <string[]>() }, githubRepo); foreach (var comment in comments) { await GitHubApi.AddCommentToIssue(new { Body = $@"{comment["body"].ToObject<string>()} > Created By: {comment["author"]["name"].ToObject<string>()} > Created At: {DateTime.Parse(comment["created_at"].ToObject<string>()):MM/dd/yyyy hh:mm tt}" }, githubRepo, githubId);
async public Task PatchGist() { var files = new Dictionary <string, string> { { "theAnswer", "42" }, { "the Question", "I dunno" } }; var api = GitHubApi.Create(); await api.in2bitstest(new[] { Scopes.Gist }); var gist = await api.Gists.New(files); Assert.AreEqual("42", gist.Files["theAnswer"].Content); var patch = new Gist.EditGistPost(gist); var patchFile = patch.Files["theAnswer"]; patchFile.Filename = "theWrongAnswer"; patchFile.Content = "43"; patch.Files["the Question"] = null; var patchedGist = await api.Gists.Edit(patch); Assert.AreEqual(1, patchedGist.Files.Count); var file = patchedGist.Files["theWrongAnswer"]; Assert.IsNotNull(file); Assert.AreEqual("43", file.Content); Assert.AreEqual(gist.Id, patchedGist.Id); }
async public Task GetGist() { const long id = 5731704; var api = GitHubApi.Create(); await api.in2bitstest(); var gist = await api.Gists.Get(id); Assert.AreEqual("https://api.github.com/gists/5731704/comments", gist.CommentsUrl); Assert.AreEqual("https://api.github.com/gists/5731704/commits", gist.CommitsUrl); Assert.AreEqual(new DateTime(2013, 6, 7, 19, 22, 52, DateTimeKind.Utc), gist.CreatedAt); Assert.IsNull(gist.Description); Assert.AreEqual(2, gist.Files.Count); Assert.IsTrue(gist.Files.ContainsKey("theAnswer")); var file = gist.Files["theAnswer"]; Assert.AreEqual("42", file.Content); Assert.AreEqual("theAnswer", file.Filename); Assert.IsNull(file.Language); Assert.AreEqual("https://gist.github.com/raw/5731704/f70d7bba4ae1f07682e0358bd7a2068094fc023b/theAnswer", file.RawUrl); Assert.AreEqual(2, file.Size); Assert.AreEqual("text/plain", file.Type); Assert.AreEqual(0, gist.Forks.Count()); Assert.AreEqual("https://api.github.com/gists/5731704/forks", gist.ForksUrl); Assert.AreEqual("https://gist.github.com/5731704.git", gist.GitPullUrl); Assert.AreEqual("https://gist.github.com/5731704.git", gist.GitPushUrl); Assert.AreEqual(1, gist.History.Count()); Assert.AreEqual("https://gist.github.com/5731704", gist.HtmlUrl); Assert.AreEqual(id, gist.Id); Assert.AreEqual(true, gist.Public); Assert.IsTrue(gist.CreatedAt <= gist.UpdatedAt); Assert.AreEqual("https://api.github.com/gists/5731704", gist.Url); Assert.IsNull(gist.User); }
public void AllSteps() { var update = new Update(); update.PropertyChanged += Update_PropertyChanged; var assembly = Assembly.GetExecutingAssembly(); var version = assembly.GetName().Version; var tempDir = Path.Combine(Path.GetTempPath(), nameof(AutoUpdateViaGitHubRelease)); Stopwatch time = Stopwatch.StartNew(); var newVersion = update.CheckDownloadNewVersionAsync(GitHubApiTest.User , GitHubApiTest.Repo, version, tempDir); Assert.IsFalse(update.Available); var gitHub = new GitHubApi(); var latestReleaseJson = gitHub.GetLatestReleaseJSONAsync(GitHubApiTest.User , GitHubApiTest.Repo).Result; var latestVersion = GitHubApi.ParseVersion(latestReleaseJson); Assert.AreEqual(newVersion.Result, update.Available); Assert.AreEqual(update.Available, version < latestVersion); if (update.Available) { var destinationDir = Path.Combine(tempDir, "install"); var installProcess = update.StartInstall(destinationDir); installProcess.WaitForExit(); Assert.AreEqual(0, installProcess.ExitCode); } }
public MainWindow() { InitializeComponent(); _gitHubApi = new GitHubApi(); SetupObservable(); }
async public Task GetAuthenticatedUser() { var api = GitHubApi.Create(); await api.in2bitstest(); var user = await api.Users.GetAuthenticatedUser(); }
private void NewIssue() { var issue = new NewIssue(Title); issue.Body = Body; if (Assignee != null) { issue.Assignee = Assignee.Login; } if (Milestone != null) { issue.Milestone = Milestone.Number; } foreach (var label in SelectedLabels) { issue.Labels.Add(label.Name); } GitHubApi.SaveIssue(_repository, issue); if (_portedTfsItem != null) { // Resolve and close the TFS issue. GitHubApi.GetIssuesAndResolvePortedTfsIssue(_portedTfsItem, issue.Title); } }
public CreateIssueViewModel(GitHubApi githubApi, IGitHubSettings settings) { this.githubApi = githubApi; this.settings = settings; Repositories = new ObservableCollection <RepositoryModel>(); CreateIssueCommand = new DelegateCommand(CreateIssue); }
async public Task SearchUsers() { var api = GitHubApi.Create(); await api.in2bitstest(); var userList = await api.Search.Users("timerickson"); var user = userList.Users.FirstOrDefault(x => x.Id == "user-57726"); Assert.IsNotNull(user); Assert.AreEqual(new DateTime(2009, 2, 25, 3, 57, 50, DateTimeKind.Utc), user.Created); Assert.AreEqual(new DateTime(2009, 2, 25, 3, 57, 50, DateTimeKind.Utc), user.CreatedAt); Assert.AreEqual(4, user.Followers); Assert.AreEqual(4, user.FollowersCount); Assert.AreEqual("Tim Erickson", user.FullName); Assert.AreEqual("e9fbbfd2de96fdb0cec592a4b6792f0e", user.GravatarId); Assert.AreEqual("user-57726", user.Id); Assert.AreEqual("JavaScript", user.Language); Assert.AreEqual("Seattle, WA", user.Location); Assert.AreEqual("timerickson", user.Login); Assert.AreEqual("Tim Erickson", user.Name); Assert.AreEqual(4, user.PublicRepoCount); Assert.AreEqual(4, user.Repos); Assert.IsTrue(0 < user.Score); Assert.AreEqual("user", user.Type); Assert.AreEqual("timerickson", user.Username); }
async public Task SearchIssues() { var api = GitHubApi.Create(); await api.in2bitstest(); var text = "TEST Open Issue"; var issueList = await api.Search.Issues("in2bits", "IronGitHub", IssueStates.Open, text); Assert.IsTrue(1 <= issueList.Issues.Count(x => x.Title == text)); var issue = issueList.Issues.First(); Assert.AreEqual("This is a test issue that should remain open.", issue.Body); Assert.AreEqual(1, issue.Comments); Assert.AreEqual(new DateTime(2013, 6, 17, 23, 30, 44, DateTimeKind.Utc), issue.CreatedAt); Assert.AreEqual("e9fbbfd2de96fdb0cec592a4b6792f0e", issue.GravatarId); Assert.AreEqual("https://github.com/in2bits/IronGitHub/issues/2", issue.HtmlUrl); Assert.AreEqual(2, issue.Labels.Count()); Assert.AreEqual("TEST", issue.Labels.ElementAt(0)); Assert.AreEqual("TEST2", issue.Labels.ElementAt(1)); Assert.AreEqual(2, issue.Number); Assert.AreEqual(1, issue.Position); Assert.AreEqual(IssueStates.Open, issue.State); Assert.AreEqual(text, issue.Title); Assert.AreEqual(new DateTime(2013, 6, 19, 19, 42, 0, DateTimeKind.Utc), issue.UpdatedAt); Assert.AreEqual("timerickson", issue.User); Assert.AreEqual(0, issue.Votes); }
// Creates a HTTP request to access the specified URI. private static HttpWebRequest CreateRequest(ListParameters p, Uri uri) { HttpWebRequest request = GitHubApi.CreateRequest(uri, p.UserName, p.Password); request.Accept = "application/vnd.github-commitcomment.html+json"; return(request); }
public void Postbuild(ImmutableList <FileModel> models, IHostService host) { foreach (var model in models) { if (model.Type == DocumentType.Article) { string transformedFilePathFromRoot = model.LocalPathFromRoot.Replace("/", "%2F"); List <Commits> gitCommits = GitHubApi.GetCommits(models, transformedFilePathFromRoot); if (gitCommits != null) { var commits = gitCommits .GroupBy(x => x.Author.Login) .OrderByDescending(x => x.Count()) .Select(x => x.FirstOrDefault()) .Take(5); var content = (Dictionary <string, object>)model.Content; int index = 1; foreach (var commit in commits) { content["gitPageContributor" + index + "Login"] = commit.Author.Login; content["gitPageContributor" + index + "AvatarUrl"] = commit.Author.AvatarUrl; content["gitPageContributor" + index + "HtmlUrl"] = commit.Author.HtmlUrl; index++; } content["gitPageDate"] = System.DateTime.Parse(gitCommits[0].Commit.Author.Date).ToShortDateString(); } } } }
async public Task SearchRepositories() { var api = GitHubApi.Create(); await api.in2bitstest(); var repoList = await api.Search.Repositories("IronGitHub"); var repo = repoList.Repositories.FirstOrDefault(x => x.Name == "IronGitHub"); Assert.IsNotNull(repo); Assert.AreEqual(new DateTime(2013, 5, 26, 2, 25, 58, DateTimeKind.Utc), repo.Created); Assert.AreEqual(new DateTime(2013, 5, 26, 2, 25, 58, DateTimeKind.Utc), repo.CreatedAt); Assert.AreEqual("C# GitHub Api", repo.Description); Assert.AreEqual(1, repo.Followers); Assert.AreEqual(false, repo.Fork); Assert.AreEqual(0, repo.Forks); Assert.AreEqual(true, repo.HasDownloads); Assert.AreEqual(true, repo.HasIssues); Assert.AreEqual(true, repo.HasWiki); Assert.AreEqual(null, repo.Homepage); Assert.AreEqual("C#", repo.Language); Assert.AreEqual("IronGitHub", repo.Name); Assert.AreEqual(2, repo.OpenIssues); Assert.AreEqual("in2bits", repo.Owner); Assert.AreEqual(false, repo.Private); Assert.IsTrue(new DateTime(2013, 6, 4, 0, 13, 8, DateTimeKind.Utc) <= repo.Pushed); Assert.IsTrue(new DateTime(2013, 6, 4, 0, 13, 8, DateTimeKind.Utc) <= repo.PushedAt); Assert.IsTrue(0 < repo.Score); Assert.IsTrue(260 <= repo.Size); Assert.AreEqual("repo", repo.Type); Assert.AreEqual("https://github.com/in2bits/IronGitHub", repo.Url); Assert.AreEqual("in2bits", repo.Username); Assert.IsTrue(1 <= repo.Watchers); }
public Project FindProject(string username, string projectName) { var gitHubApi = new GitHubApi(username, projectName); var request = new RestRequest(@"repos/{username}/{repository}"); try { var responseData = gitHubApi.Execute<GitHubRepo>(request); string masterBranch = "master"; if (!string.IsNullOrEmpty(responseData.Master_Branch)) { masterBranch = responseData.Master_Branch; } return new Project { Name = responseData.Full_Name, DownloadPackageUrl = new Uri(string.Format(@"https://github.com/{0}/{1}/zipball/{2}", username, projectName, masterBranch)), LastModified = DateTime.UtcNow, Description = responseData.Description }; } catch (Exception ex) { this.logger.Error(ex, "An error has occured when finding project {0}/{1}", username, projectName); return null; } }
async public Task SearchEmail() { var api = GitHubApi.Create(); await api.in2bitstest(); var email = "*****@*****.**"; var results = await api.Search.Email(email); Assert.IsTrue(results.Users.Any()); var user = results.Users.First(); Assert.AreEqual("http://myxls.in2bits.org", user.Blog); Assert.AreEqual("", user.Company); Assert.AreEqual(new DateTime(2009, 2, 25, 3, 57, 50, DateTimeKind.Utc), user.Created); Assert.AreEqual(new DateTime(2009, 2, 25, 3, 57, 50, DateTimeKind.Utc), user.CreatedAt); Assert.AreEqual("*****@*****.**", user.Email); Assert.AreEqual(4, user.FollowersCount); Assert.AreEqual(3, user.FollowingCount); Assert.AreEqual("e9fbbfd2de96fdb0cec592a4b6792f0e", user.GravatarId); Assert.AreEqual(57726, user.Id); Assert.AreEqual("Seattle, WA", user.Location); Assert.AreEqual("timerickson", user.Login); Assert.AreEqual("Tim Erickson", user.Name); Assert.IsTrue(1 <= user.PublicGistCount); Assert.AreEqual(4, user.PublicRepoCount); Assert.AreEqual("User", user.Type); }
async public Task AuthorizeWithGistAndUserEmailScopes() { var api = GitHubApi.Create(); await api.in2bitstest(new[] { Scopes.Gist, Scopes.UserEmail }); Assert.IsTrue(api.Context.Authorization.Scopes.Matches(new[] { Scopes.Gist, Scopes.UserEmail })); }
private void DownloadButton_Click(object sender, EventArgs e) { DownloadButton.Enabled = false; ChangesTextBox.AppendText(Environment.NewLine); ChangesTextBox.AppendText("Downloading..." + Environment.NewLine); var downloadAction = new Action(() => { Parallel.ForEach(m_newPatches, patch => { var localPath = PatchManager.GetPatchFilePath(m_definition, patch.Name); var directory = PatchManager.GetPatchDirectoryPath(m_definition); Paths.EnsureDirectoryExists(directory); GitHubApi.DownloadFile(patch.DownloadUrl, localPath); this.UpdateUI(() => ChangesTextBox.AppendText(patch.Name + " done." + Environment.NewLine)); }); this.UpdateUI(() => { DialogResult = DialogResult.OK; }); }); downloadAction.BeginInvoke(null, null); }
private void DownloadButton_Click(object sender, EventArgs e) { DownloadButton.Enabled = false; ChangesTextBox.AppendText(Environment.NewLine); ChangesTextBox.AppendText("Downloading..." + Environment.NewLine); var downloadAction = new Action(() => { Parallel.ForEach(m_newDefinitions, definition => { var localPath = Path.Combine(NFEPaths.DefinitionsDirectory, definition.Name); NFEPaths.EnsureDirectoryExists(NFEPaths.DefinitionsDirectory); GitHubApi.DownloadFile(definition.DownloadUrl, localPath); UpdateUI(() => ChangesTextBox.AppendText(definition.Name + " done." + Environment.NewLine)); }); UpdateUI(() => { DialogResult = DialogResult.OK; }); }); downloadAction.BeginInvoke(null, null); }
public async void Logon(object parameter) { Message = "Logging in..."; // This breaks MVVM, but you can't bind to the password in a password // box for security reasons var pass = parameter as PasswordBox; if (pass == null) { return; } _view.IsEnabled = false; try { // This will throw if authentication fails await GitHubApi.Login(Username, pass.Password, AccessToken); _view.Close(); } catch (Exception e) { _view.IsEnabled = true; Message = "Logon failed. " + e.Message; } }
public void ParseDownloadUrl() { var gitHub = new GitHubApi(); var task = Task.Run(() => gitHub.GetLatestReleaseJSONAsync(User, Repo)); var json = task.Result; var url = GitHubApi.ParseDownloadUrl(json); Assert.AreNotEqual(0, url.Length); }
public void ParseVersion() { var gitHub = new GitHubApi(); var task = Task.Run(() => gitHub.GetLatestReleaseJSONAsync(User, Repo)); var json = task.Result; var version = GitHubApi.ParseVersion(json); Assert.AreNotEqual(0, version.Build); }
/// <summary> /// Initializes the release creator. /// <para> /// The target GitHub repository is determined by the remotes of the local /// repository found in <paramref name="repositoryRootDirectory"/>. /// </para> /// </summary> /// <param name="repositoryRootDirectory">The root directory of the local git repository.</param> /// <param name="githubToken">A token used for GitHub API authentication.</param> public Releaser(DirectoryInfo repositoryRootDirectory, string githubToken) { using var localRepository = new LocalGitRepository(repositoryRootDirectory.FullName); _gitHubApi = new GitHubApi( GitHubRepository.FindByRemotes(localRepository.Remotes), githubToken); }
public SettingsViewModel(GitHubApi githubApi, IGitHubSettings settings) { this.githubApi = githubApi; this.settings = settings; LoginCommand = new DelegateCommand <PasswordBox>(Login, p => !LoggingIn); CancelCommand = new DelegateCommand(() => OnClose()); ClearLoginDetailsCommand = new DelegateCommand(ClearLoginDetails); }
public IActionResult Owner() { GitHubApi api = new GitHubApi(); var result = api.GetOwner(); HttpContext.Session.Set("repositorio", result); return(View("Owner", result)); }
public void CustomContext() { var context = new GitHubApiContext(); var api = new GitHubApi(context); api.Context.Should().BeSameAs(context); }
public IActionResult Buscar(string buscar) { GitHubApi api = new GitHubApi(); var result = api.GetUsuarios(buscar); HttpContext.Session.Set("usuarios", result); return(View("Index", result)); }
public async Task <IActionResult> Index(string url) { GitHubApi api = new GitHubApi(); var result = api.GetRepositorios(url); HttpContext.Session.Set("repositorios", result); return(View("Index", result)); }
private Task <HttpWebResponse> MakeApiRequest(AboutViewModel model) { // get the root API URI, which will return the X-RateLimit-Remaining HTTP header Uri uri = new Uri("https://api.github.com"); HttpWebRequest request = GitHubApi.CreateRequest(uri); return(request.GetHttpResponseAsync()); }
private List <GitHubApi.GitHubFileInfo> CheckForUpdates() { var patchesInRepository = GitHubApi.GetFiles("Patches/" + m_firmware.Definition.Name); return(patchesInRepository != null ? patchesInRepository.Where(FileExtensionPredicate).Where(UpdatedFilePredicate).ToList() : null); }
async public Task ListRepositores() { var api = GitHubApi.Create(); await api.in2bitstest(); var repos = await api.Repositories.List(); Assert.IsTrue(1 < repos.Count()); }