jenkins.scm.api.SCMSourceEvent Java Examples

The following examples show how to use jenkins.scm.api.SCMSourceEvent. 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: GitLabSystemHookListener.java    From gitlab-branch-source-plugin with MIT License 6 votes vote down vote up
@Override
public void onProjectEvent(ProjectSystemHookEvent projectSystemHookEvent) {
    LOGGER.log(Level.FINE, projectSystemHookEvent.toString());
    // TODO: implement handling `project_transfer` and `project_renamed`
    switch (projectSystemHookEvent.getEventName()) {
        case ProjectSystemHookEvent.PROJECT_CREATE_EVENT:
        case ProjectSystemHookEvent.PROJECT_DESTROY_EVENT:
        case ProjectSystemHookEvent.PROJECT_UPDATE_EVENT:
            GitLabProjectSCMEvent trigger = new GitLabProjectSCMEvent(projectSystemHookEvent,
                origin);
            SCMSourceEvent.fireLater(trigger, 5, TimeUnit.SECONDS);
            break;
        default:
            LOGGER.log(Level.INFO, String.format("unsupported System hook event: %s", projectSystemHookEvent.getEventName().toString()));
    }
}
 
Example #2
Source File: GitLabSCMSource.java    From gitlab-branch-source-plugin with MIT License 6 votes vote down vote up
@NonNull
@Override
protected List<Action> retrieveActions(SCMSourceEvent event, @NonNull TaskListener listener) {
    List<Action> result = new ArrayList<>();
    getGitlabProject();
    GitLabSCMSourceContext ctx = new GitLabSCMSourceContext(null, SCMHeadObserver.none()).withTraits(traits);
    String projectUrl = gitlabProject.getWebUrl();
    String name = StringUtils.isBlank(projectName) ? gitlabProject.getNameWithNamespace() : projectName;
    result.add(new ObjectMetadataAction(name, gitlabProject.getDescription(), projectUrl));
    String avatarUrl = gitlabProject.getAvatarUrl();
    if (!ctx.projectAvatarDisabled() && StringUtils.isNotBlank(avatarUrl)) {
        result.add(new GitLabAvatar(avatarUrl));
    }
    result.add(GitLabLink.toProject(projectUrl));
    return result;
}
 
Example #3
Source File: GiteaSCMSource.java    From gitea-plugin with MIT License 6 votes vote down vote up
@NonNull
@Override
protected List<Action> retrieveActions(SCMSourceEvent event, @NonNull TaskListener listener)
        throws IOException, InterruptedException {
    if (giteaRepository == null) {
        try (GiteaConnection c = gitea().open()) {
            listener.getLogger().format("Looking up repository %s/%s%n", repoOwner, repository);
            giteaRepository = c.fetchRepository(repoOwner, repository);
        }
    }
    List<Action> result = new ArrayList<>();
    result.add(new ObjectMetadataAction(null, giteaRepository.getDescription(), giteaRepository.getWebsite()));
    result.add(new GiteaLink("icon-gitea-repo", UriTemplate.buildFromTemplate(serverUrl)
            .path(UriTemplateBuilder.var("owner"))
            .path(UriTemplateBuilder.var("repository"))
            .build()
            .set("owner", repoOwner)
            .set("repository", repository)
            .expand()
    ));
    return result;
}
 
Example #4
Source File: AbstractMultiBranchCreateRequest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public BluePipeline create(@Nonnull BlueOrganization organization, @Nonnull Reachable parent) throws IOException {
    validateInternal(getName(), scmConfig, organization);
    MultiBranchProject project = createMultiBranchProject(organization);
    assignCredentialToProject(scmConfig, project);
    SCMSource source = createSource(project, scmConfig).withId("blueocean");
    project.setSourcesList(ImmutableList.of(new BranchSource(source)));
    source.afterSave();
    project.save();
    final boolean hasJenkinsfile = repoHasJenkinsFile(source);
    if(!hasJenkinsfile){
        sendMultibranchIndexingCompleteEvent(project, 5);
        AbstractScmSourceEvent scmSourceEvent = getScmSourceEvent(project, source);
        if(scmSourceEvent != null) {
            SCMSourceEvent.fireNow(scmSourceEvent);
        }
    }else{
        project.scheduleBuild(new Cause.UserIdCause());
    }
    return BluePipelineFactory.getPipelineInstance(project, OrganizationFactory.getInstance().getContainingOrg(project.getItemGroup()));
}
 
Example #5
Source File: HookHandler.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
private void handleSystemHook(String id, HttpServletRequest request, String requestBody) throws IOException {
    try {
        SystemHook hook = readHook(SystemHook.class, requestBody);
        SCMSourceEvent.fireNow(GitLabSCMSourceEvent.create(id, hook, originOf(request)));
    } catch (IllegalArgumentException e) {
        LOGGER.warning("ignoring system hook: " + e.getMessage());
    }
}
 
Example #6
Source File: SourceActions.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Nonnull
List<Action> retrieve(@CheckForNull SCMSourceEvent event, @Nonnull TaskListener listener) throws IOException {
    GitLabProject project = source.getProject();
    return asList(
            new ObjectMetadataAction(project.getNameWithNamespace(), project.getDescription(), project.getWebUrl()),
            new GitLabProjectAvatarMetadataAction(project.getId(), source.getSourceSettings().getConnectionName()),
            GitLabLinkAction.toProject(project));
}
 
Example #7
Source File: GitHubSCMSource.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@NonNull
@Override
protected List<Action> retrieveActions(@CheckForNull SCMSourceEvent event,
                                       @NonNull TaskListener listener) throws IOException {
    // TODO when we have support for trusted events, use the details from event if event was from trusted source
    List<Action> result = new ArrayList<>();
    result.add(new GitHubRepoMetadataAction());
    String repository = this.repository;

    StandardCredentials credentials = Connector.lookupScanCredentials((Item) getOwner(), apiUri, credentialsId);
    GitHub hub = Connector.connect(apiUri, credentials);
    try {
        Connector.checkConnectionValidity(apiUri, listener, credentials, hub);
        try {
            ghRepository = hub.getRepository(getRepoOwner() + '/' + repository);
            resolvedRepositoryUrl = ghRepository.getHtmlUrl();
        } catch (FileNotFoundException e) {
            throw new AbortException(
                    String.format("Invalid scan credentials when using %s to connect to %s/%s on %s",
                            credentials == null ? "anonymous access" : CredentialsNameProvider.name(credentials), repoOwner, repository, apiUri));
        }
        result.add(new ObjectMetadataAction(null, ghRepository.getDescription(), Util.fixEmpty(ghRepository.getHomepage())));
        result.add(new GitHubLink("icon-github-repo", ghRepository.getHtmlUrl()));
        if (StringUtils.isNotBlank(ghRepository.getDefaultBranch())) {
            result.add(new GitHubDefaultBranch(getRepoOwner(), repository, ghRepository.getDefaultBranch()));
        }
        return result;
    } finally {
        Connector.release(hub);
    }
}
 
Example #8
Source File: GiteaRepositorySCMEvent.java    From gitea-plugin with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void process(GiteaRepositorySCMEvent event) {
    SCMSourceEvent.fireNow(event);
}
 
Example #9
Source File: GitLabSCMSource.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 4 votes vote down vote up
@Nonnull
@Override
protected List<Action> retrieveActions(@CheckForNull SCMSourceEvent event, @Nonnull TaskListener listener) throws IOException {
    return actions.retrieve(event, listener);
}
 
Example #10
Source File: EventsTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
public void onSCMSourceEvent(SCMSourceEvent<?> event) {
    receiveEvent(event.getType(), event.getOrigin());
}
 
Example #11
Source File: GitHubSCMSource.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Nonnull
@Override
protected List<Action> retrieveActions(@CheckForNull SCMSourceEvent event, @Nonnull TaskListener listener)
        throws IOException, InterruptedException {
    return Collections.singletonList(new GitHubRepoAction(getRemoteRepo()));
}