@Override public void run() { List<User> orgs; try { orgs = cache.requestAndStore(persistedOrgs); syncResult.stats.numUpdates++; } catch (IOException | SQLException e) { syncResult.stats.numIoExceptions++; Log.d(TAG, "Exception requesting users and orgs", e); return; } Log.d(TAG, "Syncing " + orgs.size() + " users and orgs"); for (User org : orgs) { if (cancelled) return; Log.d(TAG, "Syncing repos for " + org.getLogin()); try { cache.requestAndStore(repos.under(org)); syncResult.stats.numUpdates++; } catch (IOException | SQLException e) { syncResult.stats.numIoExceptions++; Log.d(TAG, "Exception requesting repositories", e); } } Log.d(TAG, "Sync campaign finished"); }
private Map<Repository, List<RepositoryBranch>> getHeadRepositories( GitHubRepository repository, List<RepositoryBranch> baseBranches) { Map<Repository, List<RepositoryBranch>> myRepositories = new HashMap<>(); GitHubCache cache = GitHubCache.create(repository); final User mySelf = cache.getMySelf(); String repositoryAuthor = repository.getRepositoryAuthor(); if (repositoryAuthor.equals(mySelf.getLogin())) { myRepositories.put(repository.getRepository(), baseBranches); } else { if (repository.isCollaborator()) { myRepositories.put(repository.getRepository(), baseBranches); } List<Repository> forks = cache.getForks(); Repository myRepository = null; for (Repository fork : forks) { User owner = fork.getOwner(); if (owner.getLogin().equals(mySelf.getLogin())) { myRepository = fork; break; } } if (myRepository == null) { return Collections.emptyMap(); } // get my branches GitHubClient client = repository.createGitHubClient(); List<RepositoryBranch> myRepositoryBranches = getMyRepositoryBranches(client, myRepository); myRepositories.put(myRepository, myRepositoryBranches); } return myRepositories; }
/** * Create issue map for issue * * @param issue * @param newIssue * @return map */ protected Map<Object, Object> createIssueMap(Issue issue, boolean newIssue) { Map<Object, Object> params = new HashMap<Object, Object>(); if (issue != null) { params.put(FIELD_BODY, issue.getBody()); params.put(FIELD_TITLE, issue.getTitle()); User assignee = issue.getAssignee(); if (assignee != null) params.put(FILTER_ASSIGNEE, assignee.getName()); Milestone milestone = issue.getMilestone(); if (milestone != null) { int number = milestone.getNumber(); if (number > 0) params.put(FILTER_MILESTONE, Integer.toString(number)); else { if (!newIssue) params.put(FILTER_MILESTONE, null); } } List<Label> labels = issue.getLabels(); if (labels != null) { List<String> labelNames = new ArrayList<String>(labels.size()); for (Label label : labels) labelNames.add(label.getName()); params.put(FILTER_LABELS, labelNames); } } return params; }
private void fillData(List<User> organizations) { if (organizations != null && organizations.size() > 0) { for (User org : organizations) { mAdapter.add(org.getLogin()); } } mAdapter.notifyDataSetChanged(); }
@Override public String getValue() throws IllegalAccessException, InvocationTargetException { User user = getIssueData().getAssignee(); if (user == null) { return ""; // NOI18N } return user.getLogin(); }
@Override public void process(Exchange exchange) throws Exception { Message in = exchange.getIn(); RepositoryCommit commit = (RepositoryCommit) in.getBody(); User author = commit.getAuthor(); log.debug( "Got commit with author: " + author.getLogin() + ": " + author.getHtmlUrl() + " SHA " + commit.getSha()); }
@Override public void onOrganizationSelected(final User organization) { User previousOrg = org.get(); int previousOrgId = previousOrg != null ? previousOrg.getId() : -1; org.set(organization); if (recentRepos != null) recentRepos.saveAsync(); // Only hard refresh if view already created and org is changing if (previousOrgId != organization.getId()) { Activity activity = getActivity(); if (activity != null) recentRepos = new RecentRepositories(activity, organization); refreshWithProgress(); } }
@Override protected boolean viewUser(User user) { if (repo.getOwner().getId() != user.getId()) { startActivity(UserViewActivity.createIntent(user)); return true; } return false; }
private CreateIssueParams getCreateIssueParams(boolean isNew, GitHubIssuePanel p) { User assignee = p.getAssignee(); if (!isNew && assignee == null) { assignee = new User(); assignee.setLogin(""); // NOI18N } Milestone milestone = p.getMilestone(); if (milestone == null) { milestone = new Milestone(); } CreateIssueParams createIssueParams = new CreateIssueParams(p.getTitle()) .body(p.getDescription()) .milestone(milestone) .labels(p.getLabels()); if (assignee != null) { createIssueParams = createIssueParams.assignee(assignee); } return createIssueParams; }
/** Fill combobox with forks of repository */ public ComboBoxModel doFillForkItems(@QueryParameter String value, @QueryParameter String name) { ComboBoxModel aux = new ComboBoxModel(); if (this.githubClient.getUser() == null) { setGithubConfig(); } try { RepositoryService githubRepoSrv = new RepositoryService(this.githubClient); List<org.eclipse.egit.github.core.Repository> forks; try { // get parent repository if repository itself is forked org.eclipse.egit.github.core.Repository parent = githubRepoSrv.getRepository(value, name).getParent(); if (parent != null) { // get fork of parent repository forks = githubRepoSrv.getForks(parent); for (org.eclipse.egit.github.core.Repository fork : forks) { org.eclipse.egit.github.core.User user = fork.getOwner(); aux.add(user.getLogin()); } } if (aux.isEmpty()) { // add forks of repository forks = githubRepoSrv.getForks(new RepositoryId(value, name)); for (org.eclipse.egit.github.core.Repository fork : forks) { org.eclipse.egit.github.core.User user = fork.getOwner(); aux.add(user.getLogin()); } } aux.add(0, value); } catch (Exception ex) { } try { // try to use global githubLogin, find repository and add forks forks = githubRepoSrv.getForks(new RepositoryId(this.githubLogin, name)); for (org.eclipse.egit.github.core.Repository fork : forks) { org.eclipse.egit.github.core.User user = fork.getOwner(); if (!aux.contains(user.getLogin())) { aux.add(user.getLogin()); } } } catch (Exception ex) { } } catch (Exception ex) { // TODO: handle exception } Collections.sort(aux); return this.forkItems = aux; }
private void prepareData(GitData gitData, List<Repository> repositories, User user) throws IOException { UserDetail userDetail = new UserDetail(); userDetail.setName(user.getLogin()); userDetail.setAvatarUrl(user.getAvatarUrl()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy"); userDetail.setCreatedAt(simpleDateFormat.format(user.getCreatedAt())); userDetail.setEmail(user.getEmail()); userDetail.setFollower(user.getFollowers()); userDetail.setDiskUsage(user.getDiskUsage()); gitData.setUser(userDetail); Map<String, Integer> usedLanguages = new HashMap<>(); for (Repository repository : repositories) { String language = (repository.getLanguage() == null) ? "Unknown" : repository.getLanguage(); if (usedLanguages.containsKey(language)) { int count = usedLanguages.get(language); usedLanguages.replace(language, ++count); } else { usedLanguages.put(language, 1); } } gitData.setUsedLanguages(usedLanguages); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); User owner = repository.getOwner(); ActionBar actionBar = getSupportActionBar(); actionBar.setTitle(repository.getName()); actionBar.setSubtitle(owner.getLogin()); actionBar.setDisplayHomeAsUpEnabled(true); if (owner.getAvatarUrl() != null && RepositoryUtils.isComplete(repository)) configurePager(); else { avatars.bind(getSupportActionBar(), owner); ViewUtils.setGone(loadingBar, false); setGone(true); new RefreshRepositoryTask(this, repository) { @Override protected void onSuccess(Repository fullRepository) throws Exception { super.onSuccess(fullRepository); repository = fullRepository; configurePager(); } @Override protected void onException(Exception e) throws RuntimeException { super.onException(e); ToastUtils.show(RepositoryViewActivity.this, string.error_repo_load); ViewUtils.setGone(loadingBar, true); } }.execute(); } }
@Override protected void update(int position, User item) { setText(0, item.getLogin()); loader.bind(imageView(1), item); setChecked(2, selected == position); }
private void updateHeader(final Issue issue) { if (!isUsable()) return; boolean isPullRequest = IssueUtils.isPullRequest(issue); titleText.setText(issue.getTitle()); String body = issue.getBodyHtml(); if (!TextUtils.isEmpty(body)) bodyImageGetter.bind(bodyText, body, issue.getId()); else bodyText.setText(R.string.no_description_given); authorText.setText(issue.getUser().getLogin()); createdDateText.setText( new StyledText().append(getString(R.string.prefix_opened)).append(issue.getCreatedAt())); avatars.bind(creatorAvatar, issue.getUser()); if (isPullRequest && issue.getPullRequest().getCommits() > 0) { ViewUtils.setGone(commitsView, false); TextView icon = (TextView) headerView.findViewById(R.id.tv_commit_icon); TypefaceUtils.setOcticons(icon); icon.setText(TypefaceUtils.ICON_GIT_COMMIT); String commits = getString(R.string.pull_request_commits, issue.getPullRequest().getCommits()); ((TextView) headerView.findViewById(R.id.tv_pull_request_commits)).setText(commits); } else ViewUtils.setGone(commitsView, true); boolean open = STATE_OPEN.equals(issue.getState()); if (!open) { StyledText text = new StyledText(); if (isPullRequest && issue.getPullRequest().isMerged()) { text.bold(getString(R.string.merged)); stateText.setBackgroundResource(R.color.state_background_merged); } else { text.bold(getString(R.string.closed)); stateText.setBackgroundResource(R.color.state_background_closed); } Date closedAt = issue.getClosedAt(); if (closedAt != null) text.append(' ').append(closedAt); stateText.setText(text); } ViewUtils.setGone(stateText, open); User assignee = issue.getAssignee(); if (assignee != null) { StyledText name = new StyledText(); name.bold(assignee.getLogin()); name.append(' ').append(getString(R.string.assigned)); assigneeText.setText(name); assigneeAvatar.setVisibility(VISIBLE); avatars.bind(assigneeAvatar, assignee); } else { assigneeAvatar.setVisibility(GONE); assigneeText.setText(R.string.unassigned); } List<Label> labels = issue.getLabels(); if (labels != null && !labels.isEmpty()) { LabelDrawableSpan.setText(labelsArea, labels); labelsArea.setVisibility(VISIBLE); } else labelsArea.setVisibility(GONE); if (issue.getMilestone() != null) { Milestone milestone = issue.getMilestone(); StyledText milestoneLabel = new StyledText(); milestoneLabel.append(getString(R.string.milestone_prefix)); milestoneLabel.append(' '); milestoneLabel.bold(milestone.getTitle()); milestoneText.setText(milestoneLabel); float closed = milestone.getClosedIssues(); float total = closed + milestone.getOpenIssues(); if (total > 0) { ((LayoutParams) milestoneProgressArea.getLayoutParams()).weight = closed / total; milestoneProgressArea.setVisibility(VISIBLE); } else milestoneProgressArea.setVisibility(GONE); milestoneArea.setVisibility(VISIBLE); } else milestoneArea.setVisibility(GONE); String state = issue.getState(); if (state != null && state.length() > 0) state = state.substring(0, 1).toUpperCase(Locale.US) + state.substring(1); else state = ""; ViewUtils.setGone(progress, true); ViewUtils.setGone(list, false); updateStateItem(issue); }
/** Verify URI with name */ public void testUriWithTrailingSlashes() { User user = UserUriMatcher.getUser(Uri.parse("http://github.com/defunkt//")); assertNotNull(user); assertEquals("defunkt", user.getLogin()); }
/** Verify URI with name */ public void testHttpsUriWithName() { User user = UserUriMatcher.getUser(Uri.parse("https://github.com/mojombo")); assertNotNull(user); assertEquals("mojombo", user.getLogin()); }
/** Verify URI with name */ public void testHttpUriWithName() { User user = UserUriMatcher.getUser(Uri.parse("http://github.com/defunkt")); assertNotNull(user); assertEquals("defunkt", user.getLogin()); }