Permalink
Browse files

Merge pull request #50 from recena/case-sensitive

[JENKINS-34410] Improved the search procedure of through SCMSourceCriteria
  • Loading branch information...
recena committed Apr 27, 2016
2 parents 93b6b9e + 7f3c4b6 commit a10e869ec3b653b05eb188bd1e4054211d32294f
Showing with 20 additions and 6 deletions.
  1. +20 −6 src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java
@@ -51,6 +51,7 @@
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.github.GHBranch;
import org.kohsuke.github.GHContent;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHMyself;
import org.kohsuke.github.GHOrganization;
@@ -340,13 +341,26 @@ private void doRetrieve(SCMHeadObserver observer, TaskListener listener, GHRepos
}
@Override public boolean exists(@Nonnull String path) throws IOException {
try {
repo.getFileContent(path, ref);
listener.getLogger().format(" %s exists in this %s%n", path, thing);
return true;
} catch (FileNotFoundException x) {
listener.getLogger().format(" %s does not exist in this %s%n", path, thing);
return false;
int index = path.lastIndexOf('/') + 1;
List<GHContent> directoryContent = repo.getDirectoryContent(path.substring(0, index), ref);
for (GHContent content : directoryContent) {
if (content.isFile()) {
String filename = path.substring(index);
if (content.getName().equals(filename)) {
listener.getLogger().format(" ‘%s’ exists in this %s%n", path, thing);
return true;
}
if (content.getName().equalsIgnoreCase(filename)) {
listener.getLogger().format(" ‘%s’ not found (but found ‘%s’, search is case sensitive) in this %s, skipping%n", path, content.getName(), thing);
return false;
}
}
}
} catch (FileNotFoundException fnf) {
// means that does not exist and this is handled below this try/catch block.
}
listener.getLogger().format(" ‘%s’ does not exist in this %s%n", path, thing);
return false;
}
};
}

0 comments on commit a10e869

Please sign in to comment.