com.cloudbees.jenkins.GitHubRepositoryName Java Examples

The following examples show how to use com.cloudbees.jenkins.GitHubRepositoryName. 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: GitHubPluginRepoProvider2.java    From github-integration-plugin with MIT License 6 votes vote down vote up
@CheckForNull
@Override
public synchronized GHRepository getGHRepository(GitHubSCMSource source) {
    if (isTrue(cacheConnection) && nonNull(remoteRepository)) {
        return remoteRepository;
    }

    final GitHubRepositoryName name = source.getRepoFullName();
    try {
        remoteRepository = getGitHub(source)
                .getRepository(name.getUserName() + "/" + name.getRepositoryName());
    } catch (IOException ex) {
        LOG.error("Shouldn't fail because getGitHub() expected to provide working repo.", ex);
    }

    return remoteRepository;
}
 
Example #2
Source File: GitHubPRRepositoryFactoryTest.java    From github-integration-plugin with MIT License 6 votes vote down vote up
/**
 * Requires @PrepareForTest({GithubProjectProperty.class, GithubUrl.class}) in class usig it.
 *
 * @param filePath job's root directory.
 * @param job      mock job.
 * @param trigger  mock trigger that is expected to be returned via job.getTrigger(GitHubPRTrigger.class).
 */
public static void createForCommonExpectations(String filePath,
                                               Job job,
                                               GitHubPRTrigger trigger) {
    GithubUrl githubUrl = PowerMockito.mock(GithubUrl.class);
    when(githubUrl.toString()).thenReturn("http://blaur");
    GithubProjectProperty projectProperty = PowerMockito.mock(GithubProjectProperty.class);

    File file = new File(filePath);
    when(job.getRootDir()).thenReturn(file);
    when(job.getFullName()).thenReturn("jobFullName");

    PowerMockito.mockStatic(JobHelper.class);
    given(ghPRTriggerFromJob(job))
            .willReturn(trigger);
    when(trigger.getJob()).thenReturn(job);

    when(trigger.getRepoFullName(job)).thenReturn(mock(GitHubRepositoryName.class));
    when(job.getProperty(GithubProjectProperty.class)).thenReturn(projectProperty);
    when(projectProperty.getProjectUrl()).thenReturn(githubUrl);
}
 
Example #3
Source File: GitHubPluginRepoProvider2.java    From github-integration-plugin with MIT License 6 votes vote down vote up
private NullSafePredicate<GitHub> withPermission(final GitHubRepositoryName name, GHPermission permission) {
    return new NullSafePredicate<GitHub>() {
        @Override
        protected boolean applyNullSafe(@Nonnull GitHub gh) {
            try {
                final GHRepository repo = gh.getRepository(name.getUserName() + "/" + name.getRepositoryName());
                if (permission == GHPermission.ADMIN) {
                    return repo.hasAdminAccess();
                } else if (permission == GHPermission.PUSH) {
                    return repo.hasPushAccess();
                } else {
                    return repo.hasPullAccess();
                }
            } catch (IOException e) {
                return false;
            }
        }
    };
}
 
Example #4
Source File: GitHubPluginRepoProvider2.java    From github-integration-plugin with MIT License 6 votes vote down vote up
@Nonnull
@Override
public synchronized GitHub getGitHub(GitHubSCMSource source) {
    if (isTrue(cacheConnection) && nonNull(gitHub)) {
        return gitHub;
    }

    final GitHubRepositoryName repoFullName = source.getRepoFullName();

    Optional<GitHub> client = from(
            GitHubPlugin.configuration().findGithubConfig(GitHubServerConfig.withHost(repoFullName.getHost()))
    ).firstMatch(withPermission(repoFullName, getRepoPermission()));
    if (client.isPresent()) {
        gitHub = client.get();
        return gitHub;
    }

    throw new GHPluginConfigException("GitHubPluginRepoProvider can't find appropriate client for github repo " +
            "<%s>. Probably you didn't configure 'GitHub Plugin' global 'GitHub Server Settings' or there is no tokens" +
            "with %s access to this repository.",
            repoFullName.toString(), getRepoPermission());
}
 
Example #5
Source File: GitHubSCMSourceRepositoryNameContributor.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@Override
public void parseAssociatedNames(Item item, Collection<GitHubRepositoryName> result) {
    if (item instanceof SCMSourceOwner) {
        SCMSourceOwner mp = (SCMSourceOwner) item;
        for (Object o : mp.getSCMSources()) {
            if (o instanceof GitHubSCMSource) {
                GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) o;
                result.add(new GitHubRepositoryName(
                        RepositoryUriResolver.hostnameFromApiUri(gitHubSCMSource.getApiUri()),
                        gitHubSCMSource.getRepoOwner(),
                        gitHubSCMSource.getRepository()));

            }
        }
    }
}
 
Example #6
Source File: GitHubSCMSourceTest.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@Test
@Issue("JENKINS-48035")
public void testGitHubRepositoryNameContributor() throws IOException {
    WorkflowMultiBranchProject job = r.createProject(WorkflowMultiBranchProject.class);
    job.setSourcesList(Arrays.asList(new BranchSource(source)));
    Collection<GitHubRepositoryName> names = GitHubRepositoryNameContributor.parseAssociatedNames(job);
    assertThat(names, contains(allOf(
            hasProperty("userName", equalTo("cloudbeers")),
            hasProperty("repositoryName", equalTo("yolo"))
    )));
    //And specifically...
    names = new ArrayList<>();
    ExtensionList.lookup(GitHubRepositoryNameContributor.class).get(GitHubSCMSourceRepositoryNameContributor.class).parseAssociatedNames(job, names);
    assertThat(names, contains(allOf(
            hasProperty("userName", equalTo("cloudbeers")),
            hasProperty("repositoryName", equalTo("yolo"))
    )));
}
 
Example #7
Source File: GitHubPluginRepoProvider.java    From github-integration-plugin with MIT License 6 votes vote down vote up
@CheckForNull
@Override
public synchronized GHRepository getGHRepository(GitHubTrigger trigger) {
    if (isTrue(cacheConnection) && nonNull(remoteRepository)) {
        return remoteRepository;
    }

    final GitHubRepositoryName name = trigger.getRepoFullName();
    try {
        remoteRepository = getGitHub(trigger).getRepository(name.getUserName() + "/" + name.getRepositoryName());
    } catch (IOException ex) {
        LOG.error("Shouldn't fail because getGitHub() expected to provide working repo.", ex);
    }

    return remoteRepository;
}
 
Example #8
Source File: GitHubPluginRepoProvider.java    From github-integration-plugin with MIT License 6 votes vote down vote up
private NullSafePredicate<GitHub> withPermission(final GitHubRepositoryName name, GHPermission permission) {
    return new NullSafePredicate<GitHub>() {
        @Override
        protected boolean applyNullSafe(@Nonnull GitHub gh) {
            try {
                final GHRepository repo = gh.getRepository(name.getUserName() + "/" + name.getRepositoryName());
                if (permission == GHPermission.ADMIN) {
                    return repo.hasAdminAccess();
                } else if (permission == GHPermission.PUSH) {
                    return repo.hasPushAccess();
                } else {
                    return repo.hasPullAccess();
                }
            } catch (IOException e) {
                return false;
            }
        }
    };
}
 
Example #9
Source File: GitHubPluginRepoProvider.java    From github-integration-plugin with MIT License 6 votes vote down vote up
@Nonnull
@Override
public synchronized GitHub getGitHub(GitHubTrigger trigger) {
    if (isTrue(cacheConnection) && nonNull(gitHub)) {
        return gitHub;
    }

    final GitHubRepositoryName repoFullName = trigger.getRepoFullName();

    Optional<GitHub> client = from(GitHubPlugin.configuration().findGithubConfig(withHost(repoFullName.getHost())))
            .firstMatch(withPermission(repoFullName, getRepoPermission()));
    if (client.isPresent()) {
        gitHub = client.get();
        return gitHub;
    }

    throw new GHPluginConfigException("GitHubPluginRepoProvider can't find appropriate client for github repo " +
            "<%s>. Probably you didn't configure 'GitHub Plugin' global 'GitHub Server Settings' or there is no tokens" +
            "with %s access to this repository.",
            repoFullName.toString(), getRepoPermission());
}
 
Example #10
Source File: GitHubTrigger.java    From github-integration-plugin with MIT License 6 votes vote down vote up
public GitHubRepositoryName getRepoFullName(Job item) {
    Job<?, ?> job = (Job) item;
    if (isNull(repoName)) {
        checkNotNull(job, "job object is null, race condition?");
        GithubProjectProperty ghpp = job.getProperty(GithubProjectProperty.class);

        checkNotNull(ghpp, "GitHub project property is not defined. Can't setup GitHub trigger for job %s",
                job.getName());
        checkNotNull(ghpp.getProjectUrl(), "A GitHub project url is required");

        GitHubRepositoryName repo = GitHubRepositoryName.create(ghpp.getProjectUrl().baseUrl());

        checkNotNull(repo, "Invalid GitHub project url: %s", ghpp.getProjectUrl().baseUrl());

        setRepoName(repo);
    }

    return repoName;
}
 
Example #11
Source File: GitHubPRTriggerTest.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Test
public void shouldParseRepoNameFromProp() throws IOException, ANTLRException {
    FreeStyleProject p = j.createFreeStyleProject();
    String org = "org";
    String repo = "repo";
    p.addProperty(new GithubProjectProperty(format("https://github.com/%s/%s", org, repo)));

    GitHubRepositoryName fullName = defaultGitHubPRTrigger().getRepoFullName(p);
    assertThat(fullName.getUserName(), equalTo(org));
    assertThat(fullName.getRepositoryName(), equalTo(repo));
}
 
Example #12
Source File: GitHubScmHeadEvent.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@CheckForNull
protected String getSourceRepo(@Nonnull SCMSource source) {
    GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
    String projectUrlStr = gitHubSCMSource.getProjectUrlStr();
    GitHubRepositoryName repo = GitHubRepositoryName.create(projectUrlStr);
    return isNull(repo) ? null : String.format("%s/%s", repo.getUserName(), repo.getRepositoryName());
}
 
Example #13
Source File: GitHubScmSourceRepositoryNameContributor.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Override
public void parseAssociatedNames(Item item, Collection<GitHubRepositoryName> result) {
    if (item instanceof SCMSourceOwner) {
        SCMSourceOwner sourceOwner = (SCMSourceOwner) item;
        for (SCMSource source : sourceOwner.getSCMSources()) {
            if (source instanceof GitHubSCMSource) {
                GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
                result.add(gitHubSCMSource.getRepoFullName());
            }
        }
    }
}
 
Example #14
Source File: GitHubBranchRepositoryNameContributor.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Override
public void parseAssociatedNames(Item item, Collection<GitHubRepositoryName> result) {
    if (!(item instanceof Job)) {
        return;
    }

    Job job = (Job) item;
    final GitHubBranchTrigger gitHubBranchTrigger = ghBranchTriggerFromJob(job);
    if (nonNull(gitHubBranchTrigger)) {
        result.add(gitHubBranchTrigger.getRepoFullName(job));
    }
}
 
Example #15
Source File: GitHubPRRepositoryNameContributor.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Override
public void parseAssociatedNames(Job<?, ?> job, Collection<GitHubRepositoryName> result) {
    final GitHubPRTrigger gitHubPRTrigger = ghPRTriggerFromJob(job);
    if (nonNull(gitHubPRTrigger)) {
        result.add(gitHubPRTrigger.getRepoFullName(job));
    }
}
 
Example #16
Source File: GitHubSCMSourceTest.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
@Test
@Issue("JENKINS-48035")
public void testGitHubRepositoryNameContributor_When_not_MultiBranch() throws IOException {
    FreeStyleProject job = r.createProject(FreeStyleProject.class);
    Collection<GitHubRepositoryName> names = GitHubRepositoryNameContributor.parseAssociatedNames((Item) job);
    assertThat(names, Matchers.empty());
    //And specifically...
    names = new ArrayList<>();
    ExtensionList.lookup(GitHubRepositoryNameContributor.class).get(GitHubSCMSourceRepositoryNameContributor.class).parseAssociatedNames((Item) job, names);
    assertThat(names, Matchers.empty());
}
 
Example #17
Source File: GitHubSCMSourceTest.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
@Test
@Issue("JENKINS-48035")
public void testGitHubRepositoryNameContributor_When_not_GitHub() throws IOException {
    WorkflowMultiBranchProject job = r.createProject(WorkflowMultiBranchProject.class);
    job.setSourcesList(Arrays.asList(new BranchSource(new GitSCMSource("file://tmp/something"))));
    Collection<GitHubRepositoryName> names = GitHubRepositoryNameContributor.parseAssociatedNames(job);
    assertThat(names, Matchers.empty());
    //And specifically...
    names = new ArrayList<>();
    ExtensionList.lookup(GitHubRepositoryNameContributor.class).get(GitHubSCMSourceRepositoryNameContributor.class).parseAssociatedNames(job, names);
    assertThat(names, Matchers.empty());
}
 
Example #18
Source File: GitHubRepositoryEventSubscriber.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
public NewSCMSourceEvent(long timestamp, String origin, GHEventPayload.Repository event,
                         GitHubRepositoryName repo) {
    super(Type.CREATED, timestamp, event, origin);
    this.repoHost = repo.getHost();
    this.repoOwner = event.getRepository().getOwnerName();
    this.repository = event.getRepository().getName();
}
 
Example #19
Source File: PushGHEventSubscriber.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
public SCMHeadEventImpl(Type type, long timestamp, GHEventPayload.Push pullRequest, GitHubRepositoryName repo,
                        String origin) {
    super(type, timestamp, pullRequest, origin);
    this.repoHost = repo.getHost();
    this.repoOwner = pullRequest.getRepository().getOwnerName();
    this.repository = pullRequest.getRepository().getName();
}
 
Example #20
Source File: PullRequestGHEventSubscriber.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
public SCMHeadEventImpl(Type type, long timestamp, GHEventPayload.PullRequest pullRequest, GitHubRepositoryName repo,
                        String origin) {
    super(type, timestamp, pullRequest, origin);
    this.repoHost = repo.getHost();
    this.repoOwner = pullRequest.getRepository().getOwnerName();
    this.repository = pullRequest.getRepository().getName();
}
 
Example #21
Source File: GitHubBranchRepositoryFactory.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Nonnull
private static GitHubBranchRepository forProject(@Nonnull Job<?, ?> job) throws IOException {
    XmlFile configFile = new XmlFile(new File(job.getRootDir(), GitHubBranchRepository.FILE));

    GitHubBranchTrigger trigger = ghBranchTriggerFromJob(job);
    requireNonNull(trigger, "Can't extract Branch trigger from " + job.getFullName());

    final GitHubRepositoryName repoFullName = trigger.getRepoFullName(job); // ask with job because trigger may not yet be started
    GithubProjectProperty property = job.getProperty(GithubProjectProperty.class);
    String githubUrl = property.getProjectUrl().toString();

    GitHubBranchRepository localRepository;
    boolean created = false;
    if (configFile.exists()) {
        try {
            localRepository = (GitHubBranchRepository) configFile.read();
        } catch (IOException e) {
            LOGGER.info("Can't read saved repository, re-creating new one", e);
            localRepository = new GitHubBranchRepository(repoFullName.toString(), new URL(githubUrl));
            created = true;
        }
    } else {
        LOGGER.info("Creating new Branch Repository for '{}'", job.getFullName());
        localRepository = new GitHubBranchRepository(repoFullName.toString(), new URL(githubUrl));
        created = true;
    }

    // set transient cached fields
    localRepository.setJob(job);
    localRepository.setConfigFile(configFile);


    GitHubPRTrigger.DescriptorImpl prTriggerDescriptor = GitHubPRTrigger.DescriptorImpl.get();
    if (prTriggerDescriptor.isActualiseOnFactory()) {
        try {
            localRepository.actualise(trigger.getRemoteRepository(), TaskListener.NULL);
            created = true;
        } catch (Throwable ignore) {
            //silently try actualise
        }
    }

    if (created) localRepository.save();

    return localRepository;
}
 
Example #22
Source File: GHMockRule.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Override
public void parseAssociatedNames(Job<?, ?> job, Collection<GitHubRepositoryName> result) {
    result.add(GHMockRule.REPO);
}
 
Example #23
Source File: GitHubPRTriggerMockTest.java    From github-integration-plugin with MIT License 4 votes vote down vote up
/**
 * loading old local state data, running trigger and checking that old disappeared and new appeared
 */
@LocalData
@Test
public void actualiseRepo() throws Exception {
    Thread.sleep(1000);

    FreeStyleProject project = (FreeStyleProject) jRule.getInstance().getItem("project");
    assertThat(project, notNullValue());

    GitHubPRTrigger trigger = project.getTrigger(GitHubPRTrigger.class);
    assertThat(trigger, notNullValue());

    GitHubRepositoryName repoFullName = trigger.getRepoFullName();
    assertThat(repoFullName.getHost(), is("localhost"));
    assertThat(repoFullName.getUserName(), is("org"));
    assertThat(repoFullName.getRepositoryName(), is("old-repo"));

    GitHubPRRepository prRepository = project.getAction(GitHubPRRepository.class);
    assertThat(project, notNullValue());

    assertThat(prRepository.getFullName(), is("org/old-repo"));
    assertThat(prRepository.getGithubUrl(), notNullValue());
    assertThat(prRepository.getGithubUrl().toString(), is("https://localhost/org/old-repo/"));
    assertThat(prRepository.getGitUrl(), is("git://localhost/org/old-repo.git"));
    assertThat(prRepository.getSshUrl(), is("git@localhost:org/old-repo.git"));

    final Map<Integer, GitHubPRPullRequest> pulls = prRepository.getPulls();
    assertThat(pulls.size(), is(1));

    final GitHubPRPullRequest pullRequest = pulls.get(1);
    assertThat(pullRequest, notNullValue());
    assertThat(pullRequest.getNumber(), is(1));
    assertThat(pullRequest.getHeadSha(), is("65d0f7818009811e5d5eb703ebad38bbcc816b49"));
    assertThat(pullRequest.isMergeable(), is(true));
    assertThat(pullRequest.getBaseRef(), is("master"));
    assertThat(pullRequest.getHtmlUrl().toString(), is("https://localhost/org/old-repo/pull/1"));

    // now new
    project.addProperty(new GithubProjectProperty("http://localhost/org/repo"));

    GitHubPluginRepoProvider repoProvider = new GitHubPluginRepoProvider();
    repoProvider.setManageHooks(false);
    repoProvider.setRepoPermission(GHPermission.PULL);

    trigger.setRepoProvider(repoProvider);
    project.addTrigger(trigger);
    project.save();

    // activate trigger
    jRule.configRoundtrip(project);

    trigger = ghPRTriggerFromJob(project);

    trigger.doRun();

    jRule.waitUntilNoActivity();

    assertThat(project.getBuilds(), hasSize(1));

    repoFullName = trigger.getRepoFullName();
    assertThat(repoFullName.getHost(), Matchers.is("localhost"));
    assertThat(repoFullName.getUserName(), Matchers.is("org"));
    assertThat(repoFullName.getRepositoryName(), Matchers.is("repo"));


    GitHubPRPollingLogAction logAction = project.getAction(GitHubPRPollingLogAction.class);
    assertThat(logAction, notNullValue());
    assertThat(logAction.getLog(),
            containsString("Repository full name changed from 'org/old-repo' to 'org/repo'.\n"));

    assertThat(logAction.getLog(),
            containsString("Changing GitHub url from 'https://localhost/org/old-repo/' " +
                    "to 'http://localhost/org/repo'.\n"));
    assertThat(logAction.getLog(),
            containsString("Changing Git url from 'git://localhost/org/old-repo.git' " +
                    "to 'git://localhost/org/repo.git'.\n"));
    assertThat(logAction.getLog(),
            containsString("Changing SSH url from 'git@localhost:org/old-repo.git' " +
                    "to 'git@localhost:org/repo.git'.\n"));
    assertThat(logAction.getLog(),
            containsString("Local settings changed, removing PRs in repository!"));

}
 
Example #24
Source File: PRUpdateGHEventSubscriber.java    From github-pr-comment-build-plugin with MIT License 4 votes vote down vote up
/**
 * Handles updates of pull requests.
 * @param event only PULL_REQUEST events
 * @param payload payload of gh-event. Never blank
 */
@Override
protected void onEvent(GHEvent event, String payload) {
    JSONObject json = JSONObject.fromObject(payload);

    // Since we receive both pull request and issue comment events in this same code,
    //  we check first which one it is and set values from different fields
    JSONObject pullRequest = json.getJSONObject("pull_request");
    final String pullRequestUrl = pullRequest.getString("html_url");
    Integer pullRequestId = pullRequest.getInt("number");

    // Make sure the action is edited
    String action = json.getString("action");
    if (!ACTION_EDITED.equals(action)) {
        LOGGER.log(Level.FINER, "Pull request action is not edited ({0}) for PR {1}, ignoring",
                new Object[] { action, pullRequestUrl }
        );
        return;
    }

    // Set some values used below
    final Pattern pullRequestJobNamePattern = Pattern.compile("^PR-" + pullRequestId + "\\b.*$",
            Pattern.CASE_INSENSITIVE);

    // Make sure the repository URL is valid
    String repoUrl = json.getJSONObject("repository").getString("html_url");
    Matcher matcher = REPOSITORY_NAME_PATTERN.matcher(repoUrl);
    if (!matcher.matches()) {
        LOGGER.log(Level.WARNING, "Malformed repository URL {0}", repoUrl);
        return;
    }
    final GitHubRepositoryName changedRepository = GitHubRepositoryName.create(repoUrl);
    if (changedRepository == null) {
        LOGGER.log(Level.WARNING, "Malformed repository URL {0}", repoUrl);
        return;
    }

    LOGGER.log(Level.FINE, "Received update on PR {1} for {2}", new Object[] { pullRequestId, repoUrl });
    ACL.impersonate(ACL.SYSTEM, new Runnable() {
        @Override
        public void run() {
            boolean jobFound = false;
            for (final SCMSourceOwner owner : SCMSourceOwners.all()) {
                for (SCMSource source : owner.getSCMSources()) {
                    if (!(source instanceof GitHubSCMSource)) {
                        continue;
                    }
                    GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
                    if (gitHubSCMSource.getRepoOwner().equalsIgnoreCase(changedRepository.getUserName()) &&
                            gitHubSCMSource.getRepository().equalsIgnoreCase(changedRepository.getRepositoryName())) {
                        for (Job<?, ?> job : owner.getAllJobs()) {
                            if (pullRequestJobNamePattern.matcher(job.getName()).matches()) {
                                if (!(job.getParent() instanceof MultiBranchProject)) {
                                    continue;
                                }
                                boolean propFound = false;
                                for (BranchProperty prop : ((MultiBranchProject) job.getParent()).getProjectFactory().
                                        getBranch(job).getProperties()) {
                                    if (!(prop instanceof TriggerPRUpdateBranchProperty)) {
                                        continue;
                                    }
                                    propFound = true;
                                    ParameterizedJobMixIn.scheduleBuild2(job, 0,
                                            new CauseAction(new GitHubPullRequestUpdateCause(pullRequestUrl)));
                                    break;
                                }

                                if (!propFound) {
                                    LOGGER.log(Level.FINE,
                                            "Job {0} for {1}:{2}/{3} does not have a trigger PR update branch property",
                                            new Object[] {
                                                    job.getFullName(),
                                                    changedRepository.getHost(),
                                                    changedRepository.getUserName(),
                                                    changedRepository.getRepositoryName()
                                            }
                                    );
                                }

                                jobFound = true;
                            }
                        }
                    }
                }
            }
            if (!jobFound) {
                LOGGER.log(Level.FINE, "PR update on {0}:{1}/{2} did not match any job",
                        new Object[] {
                                changedRepository.getHost(), changedRepository.getUserName(),
                                changedRepository.getRepositoryName()
                        }
                );
            }
        }
    });
}
 
Example #25
Source File: GitHubSCMSource.java    From github-integration-plugin with MIT License 4 votes vote down vote up
public GitHubRepositoryName getRepoFullName() {
    return GitHubRepositoryName.create(projectUrlStr);
}
 
Example #26
Source File: GitHubTrigger.java    From github-integration-plugin with MIT License 4 votes vote down vote up
public GitHubRepositoryName getRepoFullName() {
    return getRepoFullName(getJob());
}
 
Example #27
Source File: GitHubTrigger.java    From github-integration-plugin with MIT License 4 votes vote down vote up
public void setRepoName(GitHubRepositoryName repoName) {
    this.repoName = repoName;
}
 
Example #28
Source File: GitHubTrigger.java    From github-integration-plugin with MIT License 4 votes vote down vote up
public GitHubRepositoryName getRepoName() {
    return repoName;
}
 
Example #29
Source File: GitHubPRRepositoryFactory.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Nonnull
private static GitHubPRRepository forProject(Job<?, ?> job) throws IOException {
    XmlFile configFile = new XmlFile(new File(job.getRootDir(), GitHubPRRepository.FILE));

    GitHubPRTrigger trigger = ghPRTriggerFromJob(job);
    requireNonNull(trigger, "Can't extract PR trigger from " + job.getFullName());

    final GitHubRepositoryName repoFullName = trigger.getRepoFullName(job); // ask with job because trigger may not yet be started
    GithubProjectProperty property = job.getProperty(GithubProjectProperty.class);
    String githubUrl = property.getProjectUrl().toString();

    boolean save = false;
    GitHubPRRepository localRepository;
    if (configFile.exists()) {
        try {
            localRepository = (GitHubPRRepository) configFile.read();
        } catch (IOException e) {
            LOGGER.info("Can't read saved repository, re-creating new one", e);
            localRepository = new GitHubPRRepository(repoFullName.toString(), new URL(githubUrl));
            save = true;
        }
    } else {
        localRepository = new GitHubPRRepository(repoFullName.toString(), new URL(githubUrl));
        save = true;
    }

    localRepository.setJob(job);
    localRepository.setConfigFile(configFile);

    GitHubPRTrigger.DescriptorImpl prTriggerDescriptor = GitHubPRTrigger.DescriptorImpl.get();
    if (prTriggerDescriptor.isActualiseOnFactory()) {
        try {
            localRepository.actualise(trigger.getRemoteRepository(), TaskListener.NULL);
            save = true;
        } catch (Throwable ignore) {
            //silently try actualise
        }
    }

    if (save) localRepository.save();

    return localRepository;
}
 
Example #30
Source File: PRHelperFunctions.java    From github-integration-plugin with MIT License 4 votes vote down vote up
public static String asFullRepoName(GitHubRepositoryName repo) {
    checkNotNull(repo, "Can't get full name from null repo name");
    return String.format("%s/%s", repo.getUserName(), repo.getRepositoryName());
}