public ActionResult Results(string loginName) { var user = new GithubUser(); var languages = new Dictionary<string, int>(); var repos = new List<GithubRepository>(); try { user = GithubService.GetUser(loginName); languages = GithubService.GetLanguages(loginName); repos = GithubService.GetRepositories(loginName); repos.Sort((x, y) => String.CompareOrdinal(x.name, y.name)); } catch { ViewBag.ErrorMessage = "Sorry, that user doesn't exist on Github, please try again."; return View("Index"); } ViewBag.User = user; ViewBag.Repositories = repos; ViewBag.OriginalRepositories = repos.Where(r => r.fork == false); ViewBag.ForkedRepositories = repos.Where(r => r.fork == true); ViewBag.Languages = languages; return View(); }
public static API_GitHub_Issues login(this API_GitHub_Issues gitHubIssues, string name, string apiToken) { try { //var userAPI = new Api.User(Cache, Log); //var user = new GithubUser { Name = gitHubLogin.username(), APIToken = gitHubLogin.password() }; //userAPI.Authenticate(user); var Cache = new BasicCacher.BasicCacher(); var Log = new SimpleLogProvider(); var user = new GithubUser { Name = name, APIToken = apiToken }; gitHubIssues.IssuesAPI = new Issues(Cache, Log); gitHubIssues.IssuesAPI.Authenticate(user); gitHubIssues.LoggedIn = true; } catch (Exception ex) { "Error while logging in to GitHub using user {0}".info(name); ex.log("in API_GitHub_Issues.login"); } return(gitHubIssues); }
public GithubUser addRemoveRepos(GithubUser user, IEnumerable <dtoGithubRepoContent> githubContent) { IEnumerable <int> dbReposIds = user.Repo.Select(x => x.GithubId).ToList(); IEnumerable <int> githubReposIds = githubContent.Select(x => x.GithubId).ToList(); // If this check returns true a repo has been added or removed if (dbReposIds.Count() != githubReposIds.Count()) { IEnumerable <int> addReposList = githubReposIds.Except(dbReposIds); IEnumerable <int> removeRepoList = dbReposIds.Except(githubReposIds); foreach (var githubID in addReposList) { var resRepo = _mapper.Map <GithubRepo>(githubContent.Where(x => x.GithubId == githubID).FirstOrDefault()); user.Repo.Add(resRepo); } foreach (var githubID in removeRepoList) { user.Repo.Remove(user.Repo.Where(x => x.GithubId == githubID).FirstOrDefault()); } } return(user); }
private void btnQuery_Click(object sender, EventArgs e) { if (!String.IsNullOrWhiteSpace(queryText)) { Cursor.Current = Cursors.WaitCursor; //the database is checked... using (DatabaseContext db = new DatabaseContext()) { lblStatus.Text = "Checking the database..."; List <GithubUser> result = (from i in db.GithubUser where i.Login == queryText select i).ToList(); status = result.Count; // it is true if it is not zero. } if (status != 0) { lblStatus.Text = "Getting data from the database..."; GetUserAndRepo(); } else { lblStatus.Text = "Getting data from Github ..."; //insert from api to db. using (DatabaseContext db = new DatabaseContext()) { try { string repoUrl = "https://api.github.com/users/" + queryText + "/repos"; List <GithubRepoForJson> repos = Global.GetDeserializeJson <List <GithubRepoForJson> >(repoUrl); lblStatus.Text = "Saving data to the database..."; List <GithubRepository> reposForUser = new List <GithubRepository>(); foreach (GithubRepoForJson repo in repos) { GithubRepository r = new GithubRepository(); r.FullName = repo.full_name; r.CreatedAt = repo.created_at; r.DownloadUrl = "https://github.com/" + repo.full_name + "/archive/master.zip"; reposForUser.Add(r); } // string userUrl = "https://api.github.com/users/" + queryText; GithubUserForJson user = Global.GetDeserializeJson <GithubUserForJson>(userUrl); GithubUser u = new GithubUser(); u.Login = user.login; u.HtmlUrl = user.html_url; u.Name = user.name; u.AvatarUrl = user.avatar_url; u.Followers = user.followers; u.Following = user.following; u.Repository = reposForUser; db.GithubUser.Add(u); db.SaveChanges(); //select from db lblStatus.Text = "Getting data from the database..."; GetUserAndRepo(); } catch { MessageBox.Show("Error! Github user was not found. Please try again..."); lblStatus.Text = "Unsuccessful..."; } } } } else { MessageBox.Show("Warning! Please enter a Github \"Login Name\"..."); } }
public async Task <GithubUser> Get(string username) { GithubUser user = await githubProcessor.GetUser(username); return(user); }
public void Update(GithubUser user) { _context.Entry(user).State = EntityState.Modified; }
public async Task GetUserAsync_Success_Returns_User_With_Top5Repositories() { // Arrange var username = "******"; var githubUserUrl = string.Format("https://api.github.com/users/{0}", username); var githubUserRepoUrl = string.Format("https://api.github.com/users/{0}/repos", username); var userRepos = new List <GithubUserRepo> { new GithubUserRepo { RepositoryName = "one", Stars = 0 }, new GithubUserRepo { RepositoryName = "two", Stars = 1 }, new GithubUserRepo { RepositoryName = "three", Stars = 5 }, new GithubUserRepo { RepositoryName = "four", Stars = 3 }, new GithubUserRepo { RepositoryName = "five", Stars = 10 }, new GithubUserRepo { RepositoryName = "six", Stars = 8 } }; var userResult = new GithubUser { UserName = "******", Name = "User", RepoUrl = githubUserRepoUrl }; var githubApiClientMock = new Mock <IGithubApiClient>(MockBehavior.Strict); githubApiClientMock.Setup(client => client.GetAsync <GithubUser>(githubUserUrl)).ReturnsAsync(userResult); githubApiClientMock.Setup(client => client.GetAsync <IEnumerable <GithubUserRepo> >(githubUserRepoUrl)).ReturnsAsync(userRepos); GithubUsersService githubUsersService = new GithubUsersService(githubApiClientMock.Object); // Act GithubUser result = await githubUsersService.GetUserAsync(username); // Assert Assert.NotNull(result); Assert.IsType <GithubUser>(result); var user = result as GithubUser; Assert.Equal(user.UserName, userResult.UserName); Assert.Equal(user.Name, userResult.Name); Assert.IsAssignableFrom <IEnumerable <GithubUserRepo> >(user.Repositories); var repos = user.Repositories.ToArray(); Assert.Equal(5, repos.Length); Assert.Equal(userRepos[4].RepositoryName, repos[0].RepositoryName); Assert.Equal(userRepos[4].Stars, repos[0].Stars); Assert.Equal(userRepos[5].RepositoryName, repos[1].RepositoryName); Assert.Equal(userRepos[5].Stars, repos[1].Stars); Assert.Equal(userRepos[2].RepositoryName, repos[2].RepositoryName); Assert.Equal(userRepos[2].Stars, repos[2].Stars); Assert.Equal(userRepos[3].RepositoryName, repos[3].RepositoryName); Assert.Equal(userRepos[3].Stars, repos[3].Stars); Assert.Equal(userRepos[1].RepositoryName, repos[4].RepositoryName); Assert.Equal(userRepos[1].Stars, repos[4].Stars); }
public async Task SaveGithubUser(GithubUser user) { await Task.Delay(100); Store.AddOrUpdate(user.Login, user, (oldKey, oldUser) => user); }
public async void GetUserByLogin_InputExisting_ReturnGithubUser() { var expectedContent = new { login = "******", id = 6240204, node_id = "", avatar_url = "https://avatars0.githubusercontent.com/u/6240204?v=4", gravatar_id = "", url = "https://api.github.com/users/destiny07", html_url = "https://github.com/destiny07", followers_url = "https://api.github.com/users/destiny07/followers", following_url = "https://api.github.com/users/destiny07/following{/other_user}", gists_url = "https://api.github.com/users/destiny07/gists{/gist_id}", starred_url = "https://api.github.com/users/destiny07/starred{/owner}{/repo}", subscriptions_url = "https://api.github.com/users/destiny07/subscriptions", organizations_url = "https://api.github.com/users/destiny07/orgs", repos_url = "https://api.github.com/users/destiny07/repos", events_url = "https://api.github.com/users/destiny07/events{/privacy}", received_events_url = "https://api.github.com/users/destiny07/received_events", type = "User", site_admin = false, name = "Destiny Awbelisk", company = (string)null, blog = "", location = "", email = "", hireable = "", bio = "", public_repos = 4, public_gists = 1, followers = 2, following = 5, created_at = "2013-12-22T08:06:40Z", updated_at = "2020-02-10T07:14:32Z" }; var configuration = new HttpConfiguration(); var clientHandlerStub = new DelegatingHandlerStub((request, cancellationToken) => { request.SetConfiguration(configuration); var response = request.CreateResponse( HttpStatusCode.OK, expectedContent ); return(Task.FromResult(response)); }); var client = new HttpClient(clientHandlerStub); client.BaseAddress = new Uri("https://api.github.com/"); var githubClient = new GithubClient(client); var githubUser = await githubClient.GetUserByLogin("destiny07"); var expectedGithubUser = new GithubUser { Name = "Destiny Awbelisk", Company = null, Login = "******", PublicRepos = 4, Followers = 2 }; githubUser.Should().BeEquivalentTo(expectedGithubUser); }
void OnGUI() { GUI.Label(new Rect(5, 5, 100, Screen.height / 10), "Search for user:"******"Search")) { searchResult = null; selectedUser = null; // Send search request ti Github HTTPRequest request = new HTTPRequest(new System.Uri(string.Format(Api_SearchUser, searchFor)), OnSearchForUsersFinished); request.UseAlternateSSL = true; request.Send(); searchStarted = true; searchText = "Searching"; } GUI.Box(new Rect(10, 5 + Screen.height / 10, Screen.width / 2, Screen.height - 35), string.Empty); if (!string.IsNullOrEmpty(searchText)) { GUI.Label(new Rect(10, 5 + Screen.height / 10, Screen.width / 2, Screen.height - 35), searchText); } if (searchResult != null && searchResult.users != null) { GUI.Label(new Rect(), "Users found:"); scrollPosition = GUI.BeginScrollView(new Rect(10, 5 + Screen.height / 10, Screen.width / 2, Screen.height - 35), scrollPosition, new Rect(10, 30, Screen.width / 2, searchResult.users.Count * 30), false, true); for (int i = 0; i < searchResult.users.Count; ++i) { if (GUI.Button(new Rect(10, i * 30, (Screen.width / 2) - 20, 25), searchResult.users[i].fullname)) { // Button pressed: change the selected user, and start download the avartar_url selectedUser = searchResult.users[i]; if (selectedUser.texture == null) { selectedUser.StartGetAvatarUrl(); } } } GUI.EndScrollView(); if (selectedUser != null) { float userinfoLeft = (Screen.width / 2) + 20; float userinfoWidth = (Screen.width / 2) - 35; GUI.Box(new Rect(userinfoLeft, 5 + Screen.height / 10, userinfoWidth, Screen.height - (Screen.height / 10) - 205), string.Empty); GUI.Label(new Rect(userinfoLeft + 5, 8 + Screen.height / 10, userinfoWidth, 25), selectedUser.fullname + "'s GitHub Profile"); // Draw user's profile picture if it's downloaded if (selectedUser.texture != null) { GUI.DrawTexture(new Rect(userinfoLeft + 3, 45 + Screen.height / 10, 128, 128), selectedUser.texture, ScaleMode.ScaleToFit); } else { GUI.Box(new Rect(userinfoLeft + 3, 45 + Screen.height / 10, 128, 128), "Loading..."); } GUI.Label(new Rect(userinfoLeft + 3, 180 + Screen.height / 10, userinfoWidth - 6, 25), string.Format("Username: {0}", selectedUser.username)); GUI.Label(new Rect(userinfoLeft + 3, 210 + Screen.height / 10, userinfoWidth - 6, 25), string.Format("Full name: {0}", selectedUser.fullname)); GUI.Label(new Rect(userinfoLeft + 3, 230 + Screen.height / 10, userinfoWidth - 6, 50), string.Format("Location: {0}", selectedUser.location)); } } // Go back to the demo selector if (GUI.Button(new Rect(20 + Screen.width / 2, Screen.height - 200, -30 + Screen.width / 2, 195), "Back")) { Application.LoadLevel(0); } }
public async Task <IActionResult> GetUserByUserName(string userName) { GithubUser user = await _githubService.GetUserByUsernameAsync(userName); return(user != null ? (IActionResult)Ok(user) : NotFound()); }
private ReleaseUser MapUser(GithubUser user) { return new ReleaseUser { AvatarUrl = user.Avatar_Url, HtmlUrl = user.Html_Url, Id = user.Id, Login = user.Login }; }
public async Task <IEnumerable <dtoGithubRepoContent> > getUserRepoDataFromGithub(GithubUser user) { IEnumerable <dtoGithubRepo> newdtoRepos = await getReposData(user.UserName); IEnumerable <dtoGithubRepoContent> reposEntity = _mapper.Map <IEnumerable <dtoGithubRepoContent> >(newdtoRepos); IList <dtoGithubRepoContent> finalRepoEntity = new List <dtoGithubRepoContent>(); foreach (dtoGithubRepoContent repoEntity in reposEntity) { try { var readme = await getReadMeData(user.UserName, repoEntity.Name); // Remove Repos that have no content AKA no README adds unneccasary proccessing to handle them _mapper.Map(readme, repoEntity); finalRepoEntity.Add(repoEntity); } catch { // NO readme file existis for this repo } } return(finalRepoEntity); }