/** * Can be used to convert given login and password to GH personal token as more secured way to interact with api * * @param username gh login * @param password gh password * @param apiUrl gh api url. Can be null or empty to default * * @return personal token with requested scope * @throws IOException when can't create token with given creds */ public GHAuthorization createToken(@Nonnull String username, @Nonnull String password, @Nullable String apiUrl) throws IOException { GitHub gitHub = new GitHubBuilder() .withEndpoint(defaultIfBlank(apiUrl, GITHUB_URL)) .withPassword(username, password) .build(); return gitHub.createToken( GH_PLUGIN_REQUIRED_SCOPE, format("Jenkins GitHub Plugin token (%s)", Jenkins.getInstance().getRootUrl()), Jenkins.getInstance().getRootUrl() ); }
GHAuthorization token = gh.createToken(Arrays.asList(GHAuthorization.REPO_STATUS, GHAuthorization.REPO), "Jenkins GitHub Pull Request Builder", null); String tokenId;