private boolean isFilteredBuild(Pullrequest pullRequest) {
    BitbucketCause cause =
        new BitbucketCause(
            pullRequest.getSource().getBranch().getName(),
            pullRequest.getDestination().getBranch().getName(),
            pullRequest.getSource().getRepository().getOwnerName(),
            pullRequest.getSource().getRepository().getRepositoryName(),
            pullRequest.getId(),
            pullRequest.getDestination().getRepository().getOwnerName(),
            pullRequest.getDestination().getRepository().getRepositoryName(),
            pullRequest.getTitle(),
            pullRequest.getSource().getCommit().getHash(),
            pullRequest.getDestination().getCommit().getHash());

    // @FIXME: Way to iterate over all available SCMSources
    List<SCMSource> sources = new LinkedList<SCMSource>();
    for (SCMSourceOwner owner : SCMSourceOwners.all())
      for (SCMSource src : owner.getSCMSources()) sources.add(src);

    BitbucketBuildFilter filter =
        !this.trigger.getBranchesFilterBySCMIncludes()
            ? BitbucketBuildFilter.InstanceByString(this.trigger.getBranchesFilter())
            : BitbucketBuildFilter.InstanceBySCM(sources, this.trigger.getBranchesFilter());

    return filter.approved(cause);
  }
Example #2
0
    @Override
    public List<GitStatus.ResponseContributor> onNotifyCommit(URIish uri, String... branches) {
      List<GitStatus.ResponseContributor> result = new ArrayList<GitStatus.ResponseContributor>();
      boolean notified = false;
      // run in high privilege to see all the projects anonymous users don't see.
      // this is safe because when we actually schedule a build, it's a build that can
      // happen at some random time anyway.
      Authentication old = SecurityContextHolder.getContext().getAuthentication();
      SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM);
      try {
        for (final SCMSourceOwner owner : SCMSourceOwners.all()) {
          for (SCMSource source : owner.getSCMSources()) {
            if (source instanceof GitSCMSource) {
              GitSCMSource git = (GitSCMSource) source;
              URIish remote;
              try {
                remote = new URIish(git.getRemote());
              } catch (URISyntaxException e) {
                // ignore
                continue;
              }
              if (GitStatus.looselyMatches(uri, remote)) {
                LOGGER.info("Triggering the indexing of " + owner.getFullDisplayName());
                owner.onSCMSourceUpdated(source);
                result.add(
                    new GitStatus.ResponseContributor() {
                      @Override
                      public void addHeaders(StaplerRequest req, StaplerResponse rsp) {
                        rsp.addHeader("Triggered", owner.getAbsoluteUrl());
                      }

                      @Override
                      public void writeBody(PrintWriter w) {
                        w.println("Scheduled indexing of " + owner.getFullDisplayName());
                      }
                    });
                notified = true;
              }
            }
          }
        }
      } finally {
        SecurityContextHolder.getContext().setAuthentication(old);
      }
      if (!notified) {
        result.add(
            new GitStatus.MessageResponseContributor("No git consumers for URI " + uri.toString()));
      }
      return result;
    }
 /** {@inheritDoc} */
 @Override
 public boolean onNotify(UUID uuid, long revision, Set<String> paths) {
   final String id = uuid.toString();
   synchronized (recentUpdates) {
     Long recentUpdate = recentUpdates.get(id);
     if (recentUpdate != null && revision == recentUpdate) {
       LOGGER.log(
           Level.FINE,
           "Received duplicate post-commit hook from {0} for revision {1} on paths {2}",
           new Object[] {uuid, revision, paths});
       return false;
     }
     recentUpdates.put(id, revision);
   }
   LOGGER.log(
       Level.INFO,
       "Received post-commit hook from {0} for revision {1} on paths {2}",
       new Object[] {uuid, revision, paths});
   boolean notified = false;
   // run in high privilege to see all the projects anonymous users don't see.
   // this is safe because when we actually schedule a build, it's a build that can
   // happen at some random time anyway.
   Authentication old = SecurityContextHolder.getContext().getAuthentication();
   SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM);
   try {
     for (SCMSourceOwner owner : SCMSourceOwners.all()) {
       for (SCMSource source : owner.getSCMSources()) {
         if (source instanceof SubversionSCMSource) {
           if (id.equals(((SubversionSCMSource) source).getUuid())) {
             LOGGER.log(
                 Level.INFO,
                 "SCM changes detected relevant to {0}. Notifying update",
                 owner.getFullDisplayName());
             owner.onSCMSourceUpdated(source);
             notified = true;
           }
         }
       }
     }
   } finally {
     SecurityContextHolder.getContext().setAuthentication(old);
   }
   if (!notified) {
     LOGGER.log(Level.INFO, "No subversion consumers for UUID {0}", uuid);
   }
   return notified;
 }