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

The following examples show how to use org.kohsuke.github.GitHub#connectAnonymously() . 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: gh_fetch_release_assets.java    From jbang with MIT License 6 votes vote down vote up
@Override
public Integer call() throws Exception { // your business logic goes here...
    GitHub github = GitHub.connectAnonymously();

    var ghRepo = github.getRepository(repo);
    ghRepo.archive();

    PagedIterator<GHRelease> releases = ghRepo.listReleases().iterator();
    if(releases.hasNext()) {
        var release = releases.next();
        for(GHAsset asset: release.getAssets()) {
            if(assetPattern.matcher(asset.getName()).matches()) {
                System.out.println(asset.getBrowserDownloadUrl());
                //System.out.println(asset.getName());
            }
        }
    } else {
        System.err.println("No releases found.");
        return CommandLine.ExitCode.SOFTWARE;
    }

    return CommandLine.ExitCode.OK;
}
 
Example 2
Source File: Updater.java    From PYX-Reloaded with Apache License 2.0 6 votes vote down vote up
public static void update() throws IOException, SQLException {
    logger.info("Checking for a newer version...");
    Updater updater = new Updater(GitHub.connectAnonymously());
    if (updater.checkVersion()) {
        File backupDir = updater.doBackup();
        logger.info("Files have been backed up into " + backupDir.getAbsolutePath());

        File updateDir = new File(updater.currentFiles, ".update");
        if (!updateDir.exists() && !updateDir.mkdir())
            throw new IllegalStateException("Cannot create update directory: " + updateDir.getAbsolutePath());

        FileUtils.cleanDirectory(updateDir);

        File updateFiles = updater.downloadLatest(updateDir);
        updater.copyPreferences(updateFiles);
        updater.copyDatabase(updateFiles);

        updater.moveUpdatedFiles(updateFiles);
        FileUtils.deleteDirectory(updateDir);
        logger.info("The server has been updated successfully!");
        System.exit(0);
    }
}
 
Example 3
Source File: GithubConnector.java    From apollo with Apache License 2.0 6 votes vote down vote up
@Inject
public GithubConnector(ApolloConfiguration apolloConfiguration) {
    try {
        logger.info("Initializing Github Connector");

        // If no user or oauth was provided, attempt to go anonymous
        if (StringUtils.isEmpty(apolloConfiguration.getScm().getGithubLogin()) || StringUtils.isEmpty(apolloConfiguration.getScm().getGithubOauthToken())) {
            logger.info("Trying to connect anonymously to GitHub");
            gitHub = GitHub.connectAnonymously();
            logger.info("Succeeded to connect anonymously to GitHub");
        } else {
            logger.info("Trying to connect to GitHub");
            gitHub = GitHub.connect(apolloConfiguration.getScm().getGithubLogin(), apolloConfiguration.getScm().getGithubOauthToken());
            logger.info("Succeeded to connect to GitHub");
        }
    } catch (IOException e) {
        throw new RuntimeException("Could not open connection to Github!", e);
    }
}
 
Example 4
Source File: ArchetypeBuilder.java    From ipaas-quickstarts with Apache License 2.0 6 votes vote down vote up
/**
 * Iterates through all projects in the given github organisation and generates an archetype for it
 */
public void generateArchetypesFromGithubOrganisation(String githubOrg, File outputDir, List<String> dirs) throws IOException {
    GitHub github = GitHub.connectAnonymously();
    GHOrganization organization = github.getOrganization(githubOrg);
    Objects.notNull(organization, "No github organisation found for: " + githubOrg);
    Map<String, GHRepository> repositories = organization.getRepositories();
    Set<Map.Entry<String, GHRepository>> entries = repositories.entrySet();

    File cloneParentDir = new File(outputDir, "../git-clones");
    if (cloneParentDir.exists()) {
        Files.recursiveDelete(cloneParentDir);
    }
    for (Map.Entry<String, GHRepository> entry : entries) {
        String repoName = entry.getKey();
        GHRepository repo = entry.getValue();
        String url = repo.getGitTransportUrl();

        generateArchetypeFromGitRepo(outputDir, dirs, cloneParentDir, repoName, url, null);
    }
}
 
Example 5
Source File: LauncherUpdater.java    From TerasologyLauncher with Apache License 2.0 6 votes vote down vote up
/**
 * This method indicates if a new launcher version is available.
 * <br>
 * Compares the current launcher version number to the upstream version number if an internet connection is available.
 *
 * @return a {@link GHRelease} if an update is available, null otherwise
 */
//TODO: return Option<GitHubRelease>
public GHRelease updateAvailable() {
    //TODO: only check of both version are defined and valid semver?
    try {
        final GitHub github = GitHub.connectAnonymously();
        final GHRepository repository = github.getRepository("MovingBlocks/TerasologyLauncher");
        final GHRelease latestRelease = repository.getLatestRelease();
        final Semver latestVersion = versionOf(latestRelease);

        if (latestVersion.isGreaterThan(currentVersion)) {
            return latestRelease;
        }
    } catch (IOException e) {
        logger.warn("Update check failed: {}", e.getMessage());
    }
    return null;
}
 
Example 6
Source File: NotesBuilder.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates the connection to the remote repository.
 *
 * @param authToken the authorization token.
 * @param remoteRepoPath path to remote git repository.
 * @return the remote repository object.
 * @throws IOException if an I/O error occurs.
 */
private static GHRepository createRemoteRepo(String authToken, String remoteRepoPath)
        throws IOException {
    final GitHub connection;
    if (authToken == null) {
        connection = GitHub.connectAnonymously();
    }
    else {
        connection = GitHub.connectUsingOAuth(authToken);
    }

    return connection.getRepository(remoteRepoPath);
}