Search in sources :

Example 1 with Repository

use of org.eclipse.egit.github.core.Repository in project camel by apache.

the class CreateIssueProducerTest method testCreateIssue.

@Test
public void testCreateIssue() throws Exception {
    Repository repository = new Repository();
    Endpoint issueProducerEndpoint = getMandatoryEndpoint("direct:createIssue");
    Exchange exchange = issueProducerEndpoint.createExchange();
    String issueBody = "There's an error";
    exchange.getIn().setBody(issueBody);
    template.send(issueProducerEndpoint, exchange);
    Thread.sleep(1 * 1000);
    // Verify that the mock pull request service received this comment.
    Issue issue = issueService.getIssue(repository, 1);
    assertEquals("Error", issue.getTitle());
    assertEquals("There's an error", issue.getBody());
}
Also used : Exchange(org.apache.camel.Exchange) Repository(org.eclipse.egit.github.core.Repository) Issue(org.eclipse.egit.github.core.Issue) Endpoint(org.apache.camel.Endpoint) Test(org.junit.Test)

Example 2 with Repository

use of org.eclipse.egit.github.core.Repository in project hubroid by EddieRingle.

the class GitHubApiService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null) {
        return;
    }
    mGitHubClient = new GitHubClient(sApiHostname, sApiPort, sApiScheme);
    mGitHubClient.setUserAgent(USER_AGENT);
    if (!intent.getBooleanExtra(ARG_ANONYMOUS, false)) {
        if (intent.hasExtra(ARG_OAUTH_TOKEN)) {
            mGitHubClient.setOAuth2Token(intent.getStringExtra(ARG_OAUTH_TOKEN));
        } else if (intent.hasExtra(ARG_BASIC_USERNAME) && intent.hasExtra(ARG_BASIC_PASSWORD)) {
            mGitHubClient.setCredentials(intent.getStringExtra(ARG_BASIC_USERNAME), intent.getStringExtra(ARG_BASIC_PASSWORD));
        } else if (intent.hasExtra(ARG_ACCOUNT) && intent.getParcelableExtra(ARG_ACCOUNT) != null) {
            final Account account = intent.getParcelableExtra(ARG_ACCOUNT);
            try {
                final String oauthToken = new OAuthUserProvider().getOAuthResponse(this, account).access_token;
                if (oauthToken != null) {
                    mGitHubClient.setOAuth2Token(oauthToken);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } catch (AccountsException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
        }
    }
    if (intent.getAction().equals(ACTION_GET_URI)) {
        final GitHubRequest request = new GitHubRequest();
        request.setUri(intent.getData().toString());
        GitHubResponse response;
        try {
            response = mGitHubClient.get(request);
        } catch (IOException e) {
            response = null;
            e.printStackTrace();
        }
        final Intent resultIntent = new Intent(ACTION_GET_URI, intent.getData());
        if (response != null) {
            resultIntent.putExtra(EXTRA_HAS_NEXT, response.getNext() != null);
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(response.getBody()));
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_EVENTS_LIST_USER_PUBLIC)) {
        final EventService es = new EventService(mGitHubClient);
        ArrayList<Event> result = null;
        PageIterator<Event> iterator = null;
        final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
        if (intent.hasExtra(PARAM_LOGIN)) {
            iterator = es.pageUserEvents(intent.getStringExtra(PARAM_LOGIN), true, startPage, REQUEST_PAGE_SIZE);
        }
        if (iterator != null && iterator.hasNext()) {
            result = new ArrayList<Event>();
            result.addAll(iterator.next());
        }
        final Intent resultIntent = new Intent(ACTION_EVENTS_LIST_USER_PUBLIC);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
            resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_EVENTS_LIST_USER_RECEIVED)) {
        final EventService es = new EventService(mGitHubClient);
        ArrayList<Event> result = null;
        PageIterator<Event> iterator = null;
        final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
        if (intent.hasExtra(PARAM_LOGIN)) {
            iterator = es.pageUserReceivedEvents(intent.getStringExtra(PARAM_LOGIN), false, startPage, REQUEST_PAGE_SIZE);
        }
        if (iterator != null && iterator.hasNext()) {
            result = new ArrayList<Event>();
            result.addAll(iterator.next());
        }
        final Intent resultIntent = new Intent(ACTION_EVENTS_LIST_USER_RECEIVED);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
            resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_EVENTS_LIST_TIMELINE)) {
        final EventService es = new EventService(mGitHubClient);
        ArrayList<Event> result = null;
        PageIterator<Event> iterator;
        final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
        iterator = es.pagePublicEvents(startPage, REQUEST_PAGE_SIZE);
        if (iterator != null && iterator.hasNext()) {
            result = new ArrayList<Event>();
            result.addAll(iterator.next());
        }
        final Intent resultIntent = new Intent(ACTION_EVENTS_LIST_TIMELINE);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
            resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_ISSUES_LIST_SELF)) {
        final IssueService is = new IssueService(mGitHubClient);
        final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
        ArrayList<RepositoryIssue> result = null;
        PageIterator<RepositoryIssue> iterator;
        HashMap<String, String> params = new HashMap<String, String>();
        if (intent.hasExtra(PARAM_FILTER)) {
            params.put("filter", intent.getStringExtra(PARAM_FILTER));
        }
        if (intent.hasExtra(PARAM_STATE)) {
            params.put("state", intent.getStringExtra(PARAM_STATE));
        }
        if (intent.hasExtra(PARAM_LABELS)) {
            params.put("labels", intent.getStringExtra(PARAM_LABELS));
        }
        if (intent.hasExtra(PARAM_SORT)) {
            params.put("sort", intent.getStringExtra(PARAM_SORT));
        }
        if (intent.hasExtra(PARAM_DIRECTION)) {
            params.put("direction", intent.getStringExtra(PARAM_DIRECTION));
        }
        if (intent.hasExtra(PARAM_SINCE)) {
            params.put("since", intent.getStringExtra(PARAM_SINCE));
        }
        iterator = is.pageIssues(params, startPage, REQUEST_PAGE_SIZE);
        if (iterator != null && iterator.hasNext()) {
            result = new ArrayList<RepositoryIssue>();
            result.addAll(iterator.next());
        }
        final Intent resultIntent = new Intent(ACTION_ISSUES_LIST_SELF);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
            resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_ORGS_SELF_MEMBERSHIPS)) {
        final OrganizationService os = new OrganizationService(mGitHubClient);
        List<User> result;
        try {
            result = os.getOrganizations();
        } catch (IOException e) {
            result = null;
            e.printStackTrace();
        }
        final Intent resultIntent = new Intent(ACTION_ORGS_SELF_MEMBERSHIPS);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_REPOS_GET_REPO)) {
        final RepositoryService rs = new RepositoryService(mGitHubClient);
        Repository result;
        try {
            result = rs.getRepository(intent.getStringExtra(PARAM_REPO_OWNER), intent.getStringExtra(PARAM_REPO_NAME));
        } catch (IOException e) {
            result = null;
            e.printStackTrace();
        }
        final Intent resultIntent = new Intent(ACTION_REPOS_GET_REPO);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_REPOS_LIST_ORG_OWNED)) {
        final RepositoryService rs = new RepositoryService(mGitHubClient);
        ArrayList<Repository> result = null;
        PageIterator<Repository> iterator;
        final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
        iterator = rs.pageOrgRepositories(intent.getStringExtra(PARAM_LOGIN), startPage, REQUEST_PAGE_SIZE);
        if (iterator != null && iterator.hasNext()) {
            result = new ArrayList<Repository>();
            result.addAll(iterator.next());
        }
        final Intent resultIntent = new Intent(ACTION_REPOS_LIST_ORG_OWNED);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
            resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_REPOS_LIST_SELF_OWNED)) {
        final RepositoryService rs = new RepositoryService(mGitHubClient);
        ArrayList<Repository> result = null;
        PageIterator<Repository> iterator;
        final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
        Map<String, String> filter = new HashMap<String, String>();
        filter.put("type", "owner");
        filter.put("sort", "pushed");
        iterator = rs.pageRepositories(filter, startPage, REQUEST_PAGE_SIZE);
        if (iterator != null && iterator.hasNext()) {
            result = new ArrayList<Repository>();
            result.addAll(iterator.next());
        }
        final Intent resultIntent = new Intent(ACTION_REPOS_LIST_SELF_OWNED);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
            resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_REPOS_LIST_USER_OWNED)) {
        final RepositoryService rs = new RepositoryService(mGitHubClient);
        ArrayList<Repository> result = null;
        PageIterator<Repository> iterator;
        final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
        iterator = rs.pageRepositories(intent.getStringExtra(PARAM_LOGIN), startPage, REQUEST_PAGE_SIZE);
        if (iterator != null && iterator.hasNext()) {
            result = new ArrayList<Repository>();
            result.addAll(iterator.next());
        }
        final Intent resultIntent = new Intent(ACTION_REPOS_LIST_USER_OWNED);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
            resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_REPOS_LIST_USER_WATCHED)) {
        final WatcherService ws = new WatcherService(mGitHubClient);
        ArrayList<Repository> result = null;
        PageIterator<Repository> iterator;
        final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
        try {
            iterator = ws.pageWatched(intent.getStringExtra(PARAM_LOGIN), startPage, REQUEST_PAGE_SIZE);
        } catch (IOException e) {
            iterator = null;
        }
        if (iterator != null && iterator.hasNext()) {
            result = new ArrayList<Repository>();
            result.addAll(iterator.next());
        }
        final Intent resultIntent = new Intent(ACTION_REPOS_LIST_USER_WATCHED);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
            resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_USERS_GET_USER)) {
        final UserService us = new UserService(mGitHubClient);
        User result;
        try {
            result = us.getUser(intent.getStringExtra(PARAM_LOGIN));
        } catch (IOException e) {
            result = null;
            e.printStackTrace();
        }
        final Intent resultIntent = new Intent(ACTION_USERS_GET_USER);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_USERS_LIST_FOLLOWERS)) {
        final UserService us = new UserService(mGitHubClient);
        ArrayList<User> result = null;
        PageIterator<User> iterator;
        final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
        iterator = us.pageFollowers(intent.getStringExtra(PARAM_LOGIN), startPage, REQUEST_PAGE_SIZE);
        if (iterator != null && iterator.hasNext()) {
            result = new ArrayList<User>();
            result.addAll(iterator.next());
        }
        final Intent resultIntent = new Intent(ACTION_USERS_LIST_FOLLOWERS);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
            resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    } else if (intent.getAction().equals(ACTION_USERS_LIST_FOLLOWING)) {
        final UserService us = new UserService(mGitHubClient);
        ArrayList<User> result = null;
        PageIterator<User> iterator;
        final int startPage = intent.getIntExtra(ARG_START_PAGE, 1);
        iterator = us.pageFollowing(intent.getStringExtra(PARAM_LOGIN), startPage, REQUEST_PAGE_SIZE);
        if (iterator != null && iterator.hasNext()) {
            result = new ArrayList<User>();
            result.addAll(iterator.next());
        }
        final Intent resultIntent = new Intent(ACTION_USERS_LIST_FOLLOWING);
        if (result != null) {
            resultIntent.putExtra(EXTRA_RESULT_JSON, GsonUtils.toJson(result));
            resultIntent.putExtra(EXTRA_HAS_NEXT, iterator.hasNext());
            resultIntent.putExtra(EXTRA_NEXT_PAGE, iterator.getNextPage());
        } else {
            resultIntent.putExtra(EXTRA_ERROR, true);
        }
        sendBroadcast(resultIntent);
    }
}
Also used : IssueService(org.eclipse.egit.github.core.service.IssueService) Account(android.accounts.Account) User(org.eclipse.egit.github.core.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AccountsException(android.accounts.AccountsException) GitHubRequest(org.eclipse.egit.github.core.client.GitHubRequest) RepositoryIssue(org.eclipse.egit.github.core.RepositoryIssue) GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryService(org.eclipse.egit.github.core.service.RepositoryService) GitHubResponse(org.eclipse.egit.github.core.client.GitHubResponse) UserService(org.eclipse.egit.github.core.service.UserService) Intent(android.content.Intent) EventService(org.eclipse.egit.github.core.service.EventService) IOException(java.io.IOException) OrganizationService(org.eclipse.egit.github.core.service.OrganizationService) Repository(org.eclipse.egit.github.core.Repository) OAuthUserProvider(net.idlesoft.android.apps.github.authenticator.OAuthUserProvider) PageIterator(org.eclipse.egit.github.core.client.PageIterator) WatcherService(org.eclipse.egit.github.core.service.WatcherService) Event(org.eclipse.egit.github.core.event.Event)

Example 3 with Repository

use of org.eclipse.egit.github.core.Repository in project hubroid by EddieRingle.

the class RepositoryListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.repository_list_item, null);
        holder = new ViewHolder();
        holder.owner = (TextView) convertView.findViewById(R.id.tv_repository_owner);
        holder.name = (TextView) convertView.findViewById(R.id.tv_repository_name);
        holder.description = (TextView) convertView.findViewById(R.id.tv_repository_description);
        holder.forks = (TextView) convertView.findViewById(R.id.tv_repository_forks);
        holder.stars = (TextView) convertView.findViewById(R.id.tv_repository_stars);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    final Repository r = getItem(position);
    holder.owner.setText(r.getOwner().getLogin());
    holder.name.setText(r.getName());
    holder.description.setText(r.getDescription());
    holder.forks.setText(Integer.toString(r.getForks()));
    holder.stars.setText(Integer.toString(r.getWatchers()));
    return convertView;
}
Also used : Repository(org.eclipse.egit.github.core.Repository)

Example 4 with Repository

use of org.eclipse.egit.github.core.Repository in project hubroid by EddieRingle.

the class RepositoryListFragment method onItemClick.

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    /*
         * Send the user off to the Repository activity
         */
    final Repository target = getListAdapter().getWrappedAdapter().getItem(position);
    final Bundle args = new Bundle();
    args.putString(ARG_TARGET_REPO, GsonUtils.toJson(target));
/* TODO: Send the user off to the Repository activity */
}
Also used : Repository(org.eclipse.egit.github.core.Repository) Bundle(android.os.Bundle)

Example 5 with Repository

use of org.eclipse.egit.github.core.Repository in project Bitocle by mthli.

the class AddTask method doInBackground.

@Override
protected Boolean doInBackground(Void... params) {
    String[] arr = query.split("/");
    if (arr.length < 2) {
        return false;
    }
    String owner = arr[0].toLowerCase();
    String name = arr[1].toLowerCase();
    Repository r;
    try {
        r = service.getRepository(owner, name);
    } catch (IOException i) {
        return false;
    }
    if (isCancelled()) {
        return false;
    }
    RAction action = new RAction(context);
    try {
        action.openDatabase(true);
    } catch (SQLException s) {
        action.closeDatabase();
        return false;
    }
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    if (!action.checkRepo(r.getGitUrl())) {
        Repo repo = new Repo();
        repo.setName(r.getName());
        repo.setDate(format.format(r.getCreatedAt()));
        repo.setDescription(r.getDescription());
        repo.setLang(r.getLanguage());
        repo.setStar(r.getWatchers());
        repo.setFork(r.getForks());
        repo.setOwner(r.getOwner().getLogin());
        repo.setGit(r.getGitUrl());
        git = r.getGitUrl();
        action.addRepo(repo);
    }
    action.closeDatabase();
    if (isCancelled()) {
        return false;
    }
    return true;
}
Also used : Repository(org.eclipse.egit.github.core.Repository) Repo(io.github.mthli.Bitocle.Database.Repo.Repo) SQLException(android.database.SQLException) IOException(java.io.IOException) RAction(io.github.mthli.Bitocle.Database.Repo.RAction) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Repository (org.eclipse.egit.github.core.Repository)10 SimpleDateFormat (java.text.SimpleDateFormat)4 IOException (java.io.IOException)3 SQLException (android.database.SQLException)2 RAction (io.github.mthli.Bitocle.Database.Repo.RAction)2 Repo (io.github.mthli.Bitocle.Database.Repo.Repo)2 RepositoryService (org.eclipse.egit.github.core.service.RepositoryService)2 Account (android.accounts.Account)1 AccountsException (android.accounts.AccountsException)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 OAuthUserProvider (net.idlesoft.android.apps.github.authenticator.OAuthUserProvider)1