Search in sources :

Example 41 with Repository

use of io.fabric8.agent.model.Repository in project fabric8-maven-plugin by fabric8io.

the class BaseBoosterIT method setupSampleTestRepository.

protected Repository setupSampleTestRepository(String repositoryUrl, String relativePomPath) throws IOException, GitAPIException, XmlPullParserException {
    openShiftClient = new DefaultOpenShiftClient(new ConfigBuilder().build());
    testsuiteNamespace = openShiftClient.getNamespace();
    Repository repository = cloneRepositoryUsingHttp(repositoryUrl);
    modifyPomFileToProjectVersion(repository, relativePomPath);
    return repository;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient)

Example 42 with Repository

use of io.fabric8.agent.model.Repository in project fabric8 by fabric8io.

the class DevOpsConnector method createWebhook.

protected boolean createWebhook(String url, String webhookSecret) {
    // e.g. we shouldn't try to register webhooks on public github with on premise services
    try {
        GitRepoClient gitRepoClient = getGitRepoClient();
        WebHooks.createGogsWebhook(gitRepoClient, getLog(), username, repoName, url, webhookSecret);
        return true;
    } catch (Exception e) {
        getLog().error("Failed to create webhook " + url + " on repository " + repoName + ". Reason: " + e, e);
        return false;
    }
}
Also used : GitRepoClient(io.fabric8.repo.git.GitRepoClient) SAXException(org.xml.sax.SAXException) WebApplicationException(javax.ws.rs.WebApplicationException) AuthenticationException(org.apache.http.auth.AuthenticationException) ConnectException(java.net.ConnectException) MalformedChallengeException(org.apache.http.auth.MalformedChallengeException) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 43 with Repository

use of io.fabric8.agent.model.Repository in project fabric8 by fabric8io.

the class WebHooks method createGogsWebhook.

/**
 * Creates a webook in the given gogs repo for the user and password if the webhook does not already exist
 */
public static boolean createGogsWebhook(GitRepoClient repoClient, Logger log, String gogsUser, String repoName, String webhookUrl, String webhookSecret) throws JsonProcessingException {
    if (repoClient == null) {
        log.info("Cannot create Gogs webhooks as no Gogs service could be found or created");
        return false;
    }
    String gogsAddress = repoClient.getAddress();
    log.info("Querying webhooks in gogs at address: " + gogsAddress + " for user " + gogsUser + " repoName: " + repoName);
    RepositoryDTO repository = repoClient.getRepository(gogsUser, repoName);
    if (repository == null) {
        log.info("No repository found for user: " + gogsUser + " repo: " + repoName + " so cannot create any web hooks");
    // return false;
    }
    List<WebHookDTO> webhooks = repoClient.getWebhooks(gogsUser, repoName);
    for (WebHookDTO webhook : webhooks) {
        String url = null;
        WebhookConfig config = webhook.getConfig();
        if (config != null) {
            url = config.getUrl();
            if (Objects.equal(webhookUrl, url)) {
                log.info("Already has webhook for: " + url + " so not creating again");
                return false;
            }
            log.info("Ignoring webhook " + url + " from: " + toJson(config));
        }
    }
    CreateWebhookDTO createWebhook = new CreateWebhookDTO();
    createWebhook.setType("gogs");
    WebhookConfig config = createWebhook.getConfig();
    config.setUrl(webhookUrl);
    config.setSecret(webhookSecret);
    WebHookDTO webhook = repoClient.createWebhook(gogsUser, repoName, createWebhook);
    if (log.isDebugEnabled()) {
        log.debug("Got created web hook: " + toJson(webhook));
    }
    log.info("Created webhook for " + webhookUrl + " for user: " + gogsUser + " repoName: " + repoName + " on gogs URL: " + gogsAddress);
    return true;
}
Also used : WebhookConfig(io.fabric8.repo.git.WebhookConfig) WebHookDTO(io.fabric8.repo.git.WebHookDTO) RepositoryDTO(io.fabric8.repo.git.RepositoryDTO) CreateWebhookDTO(io.fabric8.repo.git.CreateWebhookDTO)

Example 44 with Repository

use of io.fabric8.agent.model.Repository in project fabric8 by fabric8io.

the class BuildConfigHelper method importNewGitProject.

public static CreateGitProjectResults importNewGitProject(KubernetesClient kubernetesClient, UserDetails userDetails, File basedir, String namespace, String projectName, String origin, String message, boolean apply, boolean useLocalGitAddress) throws GitAPIException, JsonProcessingException {
    GitUtils.disableSslCertificateChecks();
    InitCommand initCommand = Git.init();
    initCommand.setDirectory(basedir);
    Git git = initCommand.call();
    LOG.info("Initialised an empty git configuration repo at {}", basedir.getAbsolutePath());
    PersonIdent personIdent = userDetails.createPersonIdent();
    String user = userDetails.getUser();
    String address = userDetails.getAddress();
    String internalAddress = userDetails.getInternalAddress();
    String branch = userDetails.getBranch();
    // lets create the repository
    GitRepoClient repoClient = userDetails.createRepoClient();
    CreateRepositoryDTO createRepository = new CreateRepositoryDTO();
    createRepository.setName(projectName);
    String fullName = null;
    RepositoryDTO repository = repoClient.createRepository(createRepository);
    if (repository != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Got repository: " + toJson(repository));
        }
        fullName = repository.getFullName();
    }
    if (Strings.isNullOrBlank(fullName)) {
        fullName = user + "/" + projectName;
    }
    String htmlUrl = URLUtils.pathJoin(resolveToRoot(address), user, projectName);
    String localCloneUrl = URLUtils.pathJoin(resolveToRoot(internalAddress), user, projectName + ".git");
    String cloneUrl = htmlUrl + ".git";
    String defaultCloneUrl = cloneUrl;
    // lets default to using the local git clone URL
    if (useLocalGitAddress && Strings.isNotBlank(internalAddress)) {
        defaultCloneUrl = localCloneUrl;
    }
    // now lets import the code and publish
    GitUtils.configureBranch(git, branch, origin, defaultCloneUrl);
    GitUtils.addDummyFileToEmptyFolders(basedir);
    LOG.info("About to git commit and push to: " + defaultCloneUrl + " and remote name " + origin);
    GitUtils.doAddCommitAndPushFiles(git, userDetails, personIdent, branch, origin, message, true);
    Map<String, String> annotations = new HashMap<>();
    annotations.put(Annotations.Builds.GIT_CLONE_URL, cloneUrl);
    annotations.put(Annotations.Builds.LOCAL_GIT_CLONE_URL, localCloneUrl);
    BuildConfig buildConfig;
    if (apply) {
        buildConfig = createAndApplyBuildConfig(kubernetesClient, namespace, projectName, defaultCloneUrl, annotations);
    } else {
        buildConfig = createBuildConfig(kubernetesClient, namespace, projectName, defaultCloneUrl, annotations);
    }
    return new CreateGitProjectResults(buildConfig, fullName, htmlUrl, localCloneUrl, cloneUrl);
}
Also used : Git(org.eclipse.jgit.api.Git) CreateRepositoryDTO(io.fabric8.repo.git.CreateRepositoryDTO) PersonIdent(org.eclipse.jgit.lib.PersonIdent) HashMap(java.util.HashMap) InitCommand(org.eclipse.jgit.api.InitCommand) GitRepoClient(io.fabric8.repo.git.GitRepoClient) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) RepositoryDTO(io.fabric8.repo.git.RepositoryDTO) CreateRepositoryDTO(io.fabric8.repo.git.CreateRepositoryDTO)

Example 45 with Repository

use of io.fabric8.agent.model.Repository in project che by eclipse.

the class OpenShiftConnector method pull.

/**
     * Creates an ImageStream that tracks the repository.
     *
     * <p>Note: This method does not cause the relevant image to actually be pulled to the local
     * repository, but creating the ImageStream is necessary as it is used to obtain
     * the address of the internal Docker registry later.
     *
     * @see DockerConnector#pull(PullParams, ProgressMonitor)
     */
@Override
public void pull(final PullParams params, final ProgressMonitor progressMonitor) throws IOException {
    // image to be pulled
    String repo = params.getFullRepo();
    // e.g. latest, usually
    String tag = params.getTag();
    String imageStreamName = KubernetesStringUtils.convertPullSpecToImageStreamName(repo);
    ImageStream existingImageStream = openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).withName(imageStreamName).get();
    if (existingImageStream == null) {
        openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).createNew().withNewMetadata().withName(// imagestream id
        imageStreamName).endMetadata().withNewSpec().addNewTag().withName(tag).endTag().withDockerImageRepository(// tracking repo
        repo).endSpec().withNewStatus().withDockerImageRepository("").endStatus().done();
    }
    // Wait for Image metadata to be obtained.
    ImageStream createdImageStream;
    for (int waitCount = 0; waitCount < OPENSHIFT_IMAGESTREAM_MAX_WAIT_COUNT; waitCount++) {
        try {
            Thread.sleep(OPENSHIFT_IMAGESTREAM_WAIT_DELAY);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        createdImageStream = openShiftClient.imageStreams().inNamespace(openShiftCheProjectName).withName(imageStreamName).get();
        if (createdImageStream != null && createdImageStream.getStatus().getDockerImageRepository() != null) {
            LOG.info(String.format("Created ImageStream %s.", imageStreamName));
            return;
        }
    }
    throw new OpenShiftException(String.format("Failed to create ImageStream %s.", imageStreamName));
}
Also used : OpenShiftException(org.eclipse.che.plugin.openshift.client.exception.OpenShiftException) ImageStream(io.fabric8.openshift.api.model.ImageStream)

Aggregations

File (java.io.File)49 Test (org.junit.Test)32 Git (org.eclipse.jgit.api.Git)30 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)27 IOException (java.io.IOException)24 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)20 HashMap (java.util.HashMap)15 ObjectId (org.eclipse.jgit.lib.ObjectId)13 MalformedURLException (java.net.MalformedURLException)11 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 PatchException (io.fabric8.patch.management.PatchException)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 Bundle (org.osgi.framework.Bundle)8 Version (org.osgi.framework.Version)8 MavenResolver (io.fabric8.maven.MavenResolver)7 HashSet (java.util.HashSet)7 Repository (io.fabric8.agent.model.Repository)6 BundleContext (org.osgi.framework.BundleContext)6 Feature (io.fabric8.agent.model.Feature)5