Search in sources :

Example 1 with Repository

use of com.checkmarx.flow.dto.github.Repository in project cx-flow by checkmarx-ltd.

the class GitHubService method initConfigProviderOnPushEvent.

public void initConfigProviderOnPushEvent(String uid, PushEvent event) {
    if (properties != null) {
        try {
            ConfigProvider configProvider = ConfigProvider.getInstance();
            Repository repository = event.getRepository();
            // According to GitHub the recommended way to extract the branch name
            // is by using the 'ref' parameter which is in the following format: 'refs/heads/<branch>'
            configProvider.init(uid, new RepoReader(properties.getApiUrl(), repository.getOwner().getName(), repository.getName(), ScanUtils.getBranchFromRef(event.getRef()), properties.getToken(), SourceProviderType.GITHUB));
        } catch (ConfigurationException e) {
            log.warn("Failed to init config provider with the following error: {}", e.getMessage());
        }
    }
}
Also used : Repository(com.checkmarx.flow.dto.github.Repository) RepoReader(com.checkmarx.configprovider.readers.RepoReader) ConfigProvider(com.checkmarx.configprovider.ConfigProvider) ConfigurationException(javax.naming.ConfigurationException)

Example 2 with Repository

use of com.checkmarx.flow.dto.github.Repository in project cx-flow by checkmarx-ltd.

the class UpdatePullRequestCommentsSteps method buildGitHubPullRequest.

public void buildGitHubPullRequest() {
    PullEvent pullEvent = new PullEvent();
    Repository repo = new Repository();
    repo.setName("vb_test_udi");
    repo.setCloneUrl(gitHubProperties.getUrl());
    Owner owner = new Owner();
    owner.setName("");
    owner.setLogin("cxflowtestuser");
    Repo r = new Repo();
    r.setOwner(owner);
    repo.setOwner(owner);
    pullEvent.setRepository(repo);
    pullEvent.setAction("opened");
    PullRequest pullRequest = new PullRequest();
    pullRequest.setIssueUrl("");
    Head headBranch = new Head();
    headBranch.setRef(branchGitHub);
    headBranch.setRepo(r);
    pullRequest.setHead(headBranch);
    pullRequest.setBase(new Base());
    pullRequest.setStatusesUrl("");
    pullRequest.setIssueUrl(GITHUB_PR_BASE_URL + "/issues/" + GITHUB_PR_ID);
    pullEvent.setPullRequest(pullRequest);
    try {
        String pullEventStr = mapper.writeValueAsString(pullEvent);
        ControllerRequest controllerRequest = new ControllerRequest();
        controllerRequest.setApplication("VB");
        controllerRequest.setBranch(Collections.singletonList(branchGitHub));
        controllerRequest.setProject("VB");
        controllerRequest.setTeam("\\CxServer\\SP");
        controllerRequest.setPreset("default");
        controllerRequest.setIncremental(false);
        gitHubControllerSpy.pullRequest(pullEventStr, "SIGNATURE", "CX", controllerRequest);
    } catch (JsonProcessingException e) {
        fail("Unable to parse " + pullEvent);
    }
}
Also used : Repository(com.checkmarx.flow.dto.github.Repository) PullEvent(com.checkmarx.flow.dto.github.PullEvent) ControllerRequest(com.checkmarx.flow.dto.ControllerRequest) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with Repository

use of com.checkmarx.flow.dto.github.Repository in project cx-flow by checkmarx-ltd.

the class DeleteBranchSteps method sendGithubDeleteEvent.

private void sendGithubDeleteEvent() {
    DeleteEvent deleteEvent = new DeleteEvent();
    Repository repo = new Repository();
    repo.setName(repoName);
    repo.setCloneUrl(gitHubProperties.getUrl());
    Owner owner = new Owner();
    owner.setName(GITHUB_USER);
    owner.setLogin(GITHUB_USER);
    repo.setOwner(owner);
    deleteEvent.setRepository(repo);
    deleteEvent.setRefType(trigger);
    deleteEvent.setRef(githubBranch);
    try {
        String deleteEventStr = mapper.writeValueAsString(deleteEvent);
        gitHubControllerSpy.deleteBranchRequest(deleteEventStr, "SIGNATURE", "CX", null, null, TEAM);
    } catch (JsonProcessingException e) {
        fail("Unable to parse " + deleteEvent.toString());
    }
}
Also used : Repository(com.checkmarx.flow.dto.github.Repository) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 4 with Repository

use of com.checkmarx.flow.dto.github.Repository in project cx-flow by checkmarx-ltd.

the class GitHubService method initConfigProviderOnPullEvent.

public void initConfigProviderOnPullEvent(String uid, PullEvent event) {
    if (properties != null) {
        try {
            ConfigProvider configProvider = ConfigProvider.getInstance();
            Repository repository = event.getRepository();
            String branch = event.getPullRequest().getHead().getRef();
            configProvider.init(uid, new RepoReader(properties.getApiUrl(), repository.getOwner().getLogin(), repository.getName(), branch, properties.getToken(), SourceProviderType.GITHUB));
        } catch (ConfigurationException e) {
            log.warn("Failed to init config provider with the following error: {}", e.getMessage());
        }
    }
}
Also used : Repository(com.checkmarx.flow.dto.github.Repository) RepoReader(com.checkmarx.configprovider.readers.RepoReader) ConfigProvider(com.checkmarx.configprovider.ConfigProvider) ConfigurationException(javax.naming.ConfigurationException)

Aggregations

Repository (com.checkmarx.flow.dto.github.Repository)4 ConfigProvider (com.checkmarx.configprovider.ConfigProvider)2 RepoReader (com.checkmarx.configprovider.readers.RepoReader)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ConfigurationException (javax.naming.ConfigurationException)2 ControllerRequest (com.checkmarx.flow.dto.ControllerRequest)1 PullEvent (com.checkmarx.flow.dto.github.PullEvent)1