Java Code Examples for org.kohsuke.github.GitHub#connectUsingPassword()

The following examples show how to use org.kohsuke.github.GitHub#connectUsingPassword() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestGitHubRepository.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
public static void deleteAllRepos(String repoPrefix, String gitHubUsername, String gitHubPassword)
    throws IOException {
  GitHub gitHub = GitHub.connectUsingPassword(gitHubUsername, gitHubPassword);

  gitHub
      .getMyself()
      .getAllRepositories()
      .keySet()
      .stream()
      .filter(repoName -> repoName.startsWith(repoPrefix))
      .forEach(
          repoName -> {
            String repoAddress = gitHubUsername + "/" + repoName;
            LOG.info("Removing repo " + repoAddress + "...");
            try {
              gitHub.getRepository(repoAddress).delete();
            } catch (IOException e) {
              e.printStackTrace();
            }
          });
}
 
Example 2
Source File: GithubApi.java    From karamel with Apache License 2.0 6 votes vote down vote up
public synchronized static void removeRepo(String owner, String repoName) throws KaramelException {

    try {
      GitHub gitHub = GitHub.connectUsingPassword(GithubApi.getUser(), GithubApi.getPassword());
      if (!gitHub.isCredentialValid()) {
        throw new KaramelException("Invalid GitHub credentials");
      }
      GHRepository repo = null;
      if (owner.compareToIgnoreCase(GithubApi.getUser()) != 0) {
        GHOrganization org = gitHub.getOrganization(owner);
        repo = org.getRepository(repoName);
      } else {
        repo = gitHub.getRepository(owner + "/" + repoName);
      }
      repo.delete();

    } catch (IOException ex) {
      throw new KaramelException("Problem authenticating with gihub-api when trying to remove a repository");
    }
  }
 
Example 3
Source File: GitHubProvider.java    From gocd-build-status-notifier with Apache License 2.0 6 votes vote down vote up
GitHub createGitHubClient(String usernameToUse, String passwordToUse, String oauthAccessTokenToUse, String endPointToUse) throws Exception {
    LOGGER.info("Creating GitHub client"); 

    GitHub github = null;
    if (usernameAndPasswordIsAvailable(usernameToUse, passwordToUse)) {
        if (endPointIsAvailable(endPointToUse)) {
            github = GitHub.connectToEnterprise(endPointToUse, usernameToUse, passwordToUse);
        } else {
            github = GitHub.connectUsingPassword(usernameToUse, passwordToUse);
        }
    }
    if (oAuthTokenIsAvailable(oauthAccessTokenToUse)) {
        if (endPointIsAvailable(endPointToUse)) {
            github = GitHub.connectUsingOAuth(endPointToUse, oauthAccessTokenToUse);
        } else {
            github = GitHub.connectUsingOAuth(oauthAccessTokenToUse);
        }
    }
    if (github == null) {
        github = GitHub.connect();
    }
    return github;
}
 
Example 4
Source File: GitHubProvider.java    From gocd-oauth-login with Apache License 2.0 5 votes vote down vote up
private GitHub connectToPublicGitHub(GithubPluginSettings pluginSettings) throws IOException {
    if (pluginSettings.containsUsernameAndPassword()) {
        LOGGER.debug("Create GitHub connection to public GitHub using username and password");
        return GitHub.connectUsingPassword(pluginSettings.getUsername(), pluginSettings.getPassword());
    } else if (pluginSettings.containsOAuthToken()) {
        LOGGER.debug("Create GitHub connection to public GitHub with token");
        return GitHub.connectUsingOAuth(pluginSettings.getOauthToken());
    }
    return null;
}
 
Example 5
Source File: TestGitHubRepository.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates repository with semi-random name on GitHub for certain {@code gitHubUsername}. Waits
 * until repository is really created.
 *
 * @param gitHubUsername github user name
 * @param gitHubPassword github user password
 * @throws IOException
 */
@Inject
public TestGitHubRepository(
    @Named("github.username") String gitHubUsername,
    @Named("github.password") String gitHubPassword)
    throws IOException {
  gitHub = GitHub.connectUsingPassword(gitHubUsername, gitHubPassword);
  ghRepo = create();

  this.gitHubUsername = gitHubUsername;
  this.gitHubPassword = gitHubPassword;
}
 
Example 6
Source File: TestGitHubRepository.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Gets repository on GitHub with predefined name for certain {@code gitHubUsername}.
 *
 * @param gitHubUsername github user name
 * @param gitHubPassword github user password
 * @param repoName name of repo on GitHub
 * @throws IOException
 */
public TestGitHubRepository(String gitHubUsername, String gitHubPassword, String repoName)
    throws IOException {
  gitHub = GitHub.connectUsingPassword(gitHubUsername, gitHubPassword);
  ghRepo = gitHub.getRepository(gitHubUsername + "/" + repoName);

  this.gitHubUsername = gitHubUsername;
  this.gitHubPassword = gitHubPassword;
}
 
Example 7
Source File: Utility.java    From iBioSim with Apache License 2.0 4 votes vote down vote up
public static void submitBugReport(String message) {
		JPanel reportBugPanel = new JPanel(new GridLayout(4,1));
		JLabel typeLabel = new JLabel("Type of Report:");
		JComboBox reportType = new JComboBox(Utility.bugReportTypes);
		
		if (!message.equals("")) {
			typeLabel.setEnabled(false);
			reportType.setEnabled(false);
		}
		
		JPanel typePanel = new JPanel(new GridLayout(1,2));
		typePanel.add(typeLabel);
		typePanel.add(reportType);
		JLabel emailLabel = new JLabel("Email address:");
		JTextField emailAddr = new JTextField(30);
		JPanel emailPanel = new JPanel(new GridLayout(1,2));
		emailPanel.add(emailLabel);
		emailPanel.add(emailAddr);
		JLabel bugSubjectLabel = new JLabel("Brief Description:");
		JTextField bugSubject = new JTextField(30);
		JPanel bugSubjectPanel = new JPanel(new GridLayout(1,2));
		bugSubjectPanel.add(bugSubjectLabel);
		bugSubjectPanel.add(bugSubject);
		JLabel bugDetailLabel = new JLabel("Detailed Description:");
		JTextArea bugDetail = new JTextArea(5,30);
		bugDetail.setLineWrap(true);
		bugDetail.setWrapStyleWord(true);
		JScrollPane scroll = new JScrollPane();
		scroll.setMinimumSize(new Dimension(100, 100));
		scroll.setPreferredSize(new Dimension(100, 100));
		scroll.setViewportView(bugDetail);
		JPanel bugDetailPanel = new JPanel(new GridLayout(1,2));
		bugDetailPanel.add(bugDetailLabel);
		bugDetailPanel.add(scroll);
		reportBugPanel.add(typePanel);
		reportBugPanel.add(emailPanel);
		reportBugPanel.add(bugSubjectPanel);
		reportBugPanel.add(bugDetailPanel);
		Object[] options = { "Send", "Cancel" };
		
		int value = JOptionPane.showOptionDialog(Gui.frame, reportBugPanel, "Bug Report",
				JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
		
		if (value == 0) {
			try {
                // Split the token in two to fool GitHub
				GitHub github = GitHub.connectUsingPassword("buggsley", "ibiosim3280");
				//GitHub github = new GitHubBuilder().withOAuthToken("79da2a9510ebdfa5fa2a" + "80416e1598b2ad05190f").build(); 
				GHRepository iBioSimRepository = github.getRepository("MyersResearchGroup/iBioSim");
				GHIssueBuilder issue = iBioSimRepository.createIssue(bugSubject.getText().trim());
				issue.body(System.getProperty("software.running") + "\n\nOperating system: " + 
						System.getProperty("os.name") + "\n\nBug reported by: " + emailAddr.getText().trim() + 
						"\n\nDescription:\n"+bugDetail.getText().trim()+message);
				issue.label(reportType.getSelectedItem().toString());
				issue.create();
			} catch (IOException e) {
				JOptionPane.showMessageDialog(Gui.frame, "Bug report failed, please submit manually.",
						"Bug Report Failed", JOptionPane.ERROR_MESSAGE);
				e.printStackTrace();
				Preferences biosimrc = Preferences.userRoot();
				String command = biosimrc.get("biosim.general.browser", "");
				command = command + " http://www.github.com/MyersResearchGroup/iBioSim/issues";
				Runtime exec = Runtime.getRuntime();
				
				try
				{
					exec.exec(command);
				}
				catch (IOException e1)
				{
					JOptionPane.showMessageDialog(Gui.frame, "Unable to open bug database.", "Error", JOptionPane.ERROR_MESSAGE);
				}
			}
		}
		
//		JOptionPane.showMessageDialog(Gui.frame, "Please verify that your bug report is in the incoming folder.\n" +
//				"If not, please submit your bug report manually using the web interface.\n", 
//				"Bug Report", JOptionPane.ERROR_MESSAGE);
//		submitBugReportTemp(message);
	}