public void loadData() { GitHubClient client = new GitHubClient(); client.setOAuth2Token(getAuthToken()); CommitService commitService = new CommitService(client); mDataIterator = commitService.pageCommits(new RepositoryId(mRepoOwner, mRepoName), mRef, mFilePath); }
@Override public void doLoadInBackground(HashMap<Integer, Object> result) throws IOException { Gh4Application app = (Gh4Application) getContext().getApplicationContext(); GitHubClient client = new GitHubClient(); client.setOAuth2Token(app.getAuthToken()); RepositoryService repoService = new RepositoryService(client); result.put(LoaderResult.DATA, repoService.getRepository(mRepoOwner, mRepoName)); }
@Override public void doLoadInBackground(HashMap<Integer, Object> result) throws IOException { Gh4Application app = (Gh4Application) getContext().getApplicationContext(); GitHubClient client = new DefaultClient(); client.setOAuth2Token(app.getAuthToken()); IssueService issueService = new IssueService(client); result.put(LoaderResult.DATA, issueService.getComments(mRepoOwner, mRepoName, mIssueNumber)); }
@BeforeClass public static void setup() { GitHubClient gitHubClient = new GitHubClient(GITHUB_URL); gitHubClient.setUserAgent(USER_AGENT); gitHubClient.setCredentials(DVCS_REPO_OWNER, DVCS_REPO_PASSWORD); githubRepositoriesREST = new GithubRepositoriesRemoteRestpoint(gitHubClient); }
@Bean public GitHubClient gitHubClient() { GitHubClient client = new GitHubClient(); client.setCredentials( env.getRequiredProperty(USUARIO_GIT), env.getRequiredProperty(PASSWORD_GIT)); client.setOAuth2Token(TOKEN_GIT); return client; }
@RequestMapping("/output") public String func(HttpServletRequest req, HttpServletResponse resp) throws Exception { String outputURL = "first"; try { String path = req.getParameter("path"); // System.out.println(path); String arr[] = path.split("/"); String repoName = arr[arr.length - 1]; String user = arr[arr.length - 2]; // System.out.println(user+" - " +path); Set<Issue> lessSeven = new LinkedHashSet<Issue>(); Set<Issue> between24and7 = new LinkedHashSet<Issue>(); Set<Issue> greaterSeven = new LinkedHashSet<Issue>(); Date yesterday = new Date(System.currentTimeMillis() - (24 * 60 * 60 * 1000)); // String yesterdayDate=sdf.format(yesterday); Date DaysAgo7Date = new Date(System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000); // String DaysAgo7=sdf.format(DaysAgo7Date); GitHubClient git = new GitHubClient(); // git.setOAuth2Token("39de076299133c5c995ee00b1573f9826887e5bd"); git.setCredentials("TheMask", "sugandh4"); RepositoryService repoService = new RepositoryService(git); IssueService issueService = new IssueService(git); Repository repo = null; repo = repoService.getRepository(user, repoName); System.out.println(repo.getName()); System.out.println(repo.getOpenIssues()); Map<String, String> paramIssue = new HashMap<String, String>(); paramIssue.put("state", "open"); // paramIssue.put("sort", "created"); List<Issue> issueList = issueService.getIssues(repo, paramIssue); for (Issue issue : issueList) { // System.out.println(issue.getCreatedAt()); if (issue.getCreatedAt().after(yesterday)) lessSeven.add(issue); else if ((issue.getCreatedAt().before(yesterday)) && (issue.getCreatedAt().after(DaysAgo7Date))) between24and7.add(issue); else greaterSeven.add(issue); } HttpSession session = req.getSession(); session.setAttribute("firstList", lessSeven); session.setAttribute("secondList", between24and7); session.setAttribute("thirdList", greaterSeven); } catch (Exception e) { System.out.println(e.getMessage()); outputURL = "error"; } System.out.println(outputURL); return outputURL; }
public static GitHubClient createGitHubClientFromCredentials(Credentials credentials) { GitHubClient gitHubClient = new GitHubClient(); String user = credentials.getUser(); String password = credentials.getPassword(); String oauthToken = credentials.getOauthToken(); if (oauthToken != null && !oauthToken.isEmpty()) { return gitHubClient.setOAuth2Token(oauthToken); } else if (user != null && !user.isEmpty() && password != null && !password.isEmpty()) { return gitHubClient.setCredentials(user, password); } else { throw new RuntimeException("Unable to initialize GitHubClient: missing credentials!"); } }
/** * Configure credentials from configured OAuth2 token * * @param client * @param oauth2Token * @return true if configured, false otherwise */ protected boolean configureOAuth2Token(final GitHubClient client, final String oauth2Token) { if (StringUtils.isEmpty(oauth2Token)) return false; if (isDebug()) debug("Using OAuth2 access token authentication"); client.setOAuth2Token(oauth2Token); return true; }
/** * Delete repository with given id * * @param gitHubClient * @param repository * @throws IOException */ public static void deleteRepository(GitHubClient gitHubClient, IRepositoryIdProvider repository) throws IOException { String repoId = getId(repository); StringBuilder uri = new StringBuilder(SEGMENT_REPOS); uri.append('/').append(repoId); gitHubClient.delete(uri.toString()); }
/** * Configure credentials from configured username/password combination * * @param client * @param userName * @param password * @return true if configured, false otherwise */ protected boolean configureUsernamePassword( final GitHubClient client, final String userName, final String password) { if (StringUtils.isEmpty(userName, password)) return false; if (isDebug()) debug("Using basic authentication with username: " + userName); client.setCredentials(userName, password); return true; }
/* * (non-Javadoc) * @see android.os.AsyncTask#doInBackground(Params[]) */ @Override protected List<User> doInBackground(Void... arg0) { if (mTarget.get() != null) { try { GitHubClient client = new GitHubClient(); client.setOAuth2Token(mTarget.get().getAuthToken()); OrganizationService orgService = new OrganizationService(client); return orgService.getOrganizations(mTarget.get().mUserLogin); } catch (IOException e) { Log.e(Constants.LOG_TAG, e.getMessage(), e); if (e.getCause() != null && e.getCause() .getMessage() .equalsIgnoreCase("Received authentication challenge is null")) { isAuthError = true; } mException = true; return null; } } else { return null; } }
@BeforeMethod public void before() throws IOException { user = new User(); user.setLogin("login"); user.setPassword("password"); service = mock(GistService.class); gc = mock(GitHubClient.class); gist = new Gist(); gist.setDescription(DESCRIPTION); list = new ArrayList<Gist>(); for (int i = 0; i < 5; i++) { list.add(new Gist()); } when(service.getGist("test")).thenReturn(gist); when(service.updateGist(gist)).thenReturn(gist); when(service.getGists(user.getLogin())).thenReturn(list); when(service.createGist(gist)).thenReturn(gist); // when(service.deleteGist("test")).thenThrow(); when(service.getClient()).thenReturn(gc); when(gc.setCredentials(user.getLogin(), user.getPassword())).thenReturn(gc); gf = new GistFetcher(service); }
/** * Configure client with credentials from given server id * * @param client * @param serverId * @param settings * @param session * @return true if configured, false otherwise * @throws MojoExecutionException */ protected boolean configureServerCredentials( final GitHubClient client, final String serverId, final Settings settings, final MavenSession session) throws MojoExecutionException { if (StringUtils.isEmpty(serverId)) return false; String serverUsername = null; String serverPassword = null; // Maven 3.1.0 - It's now impossible to retrieve the username and password from the remote // repository. // if (session != null) { // RepositorySystemSession systemSession = session // .getRepositorySession(); // if (systemSession != null) { // RemoteRepository.Builder builder = new RemoteRepository.Builder(serverId, "", // ""); // Authentication authInfo = // systemSession.getAuthenticationSelector().getAuthentication // (builder.build()); // if (authInfo != null) { // serverUsername = authInfo.getUsername(); // serverPassword = authInfo.getPassword(); // } // } // } // Always true. // if (StringUtils.isEmpty(serverPassword)) { Server server = getServer(settings, serverId); if (server == null) throw new MojoExecutionException( MessageFormat.format("Server ''{0}'' not found in settings", serverId)); if (isDebug()) debug(MessageFormat.format("Using ''{0}'' server credentials", serverId)); serverUsername = server.getUsername(); serverPassword = server.getPassword(); // } if (!StringUtils.isEmpty(serverUsername, serverPassword)) { if (isDebug()) debug("Using basic authentication with username: "******"Using OAuth2 access token authentication"); client.setOAuth2Token(serverPassword); return true; } if (isDebug()) debug( MessageFormat.format( "Server ''{0}'' is missing username/password credentials", serverId)); return false; }
/** * Create client for repository * * @param repository * @return client */ public static GitHubClient createClient(TaskRepository repository) { GitHubClient client = GitHubClient.createClient(repository.getRepositoryUrl()); return configureClient(client, repository); }