Skip to content

Commit 48663e5

Browse files
author
Mark Robinson
committed
Relax validation rules to allow no CWL documents in the root
1 parent 2ac32b0 commit 48663e5

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

src/main/java/org/commonwl/viewer/services/WorkflowFormValidator.java

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,9 @@ public GithubDetails validateAndParse(WorkflowForm form, Errors e) {
6767

6868
// Check the repository exists and get content to ensure that branch/path exist
6969
try {
70+
// Return the Github information if it is valid
7071
List<RepositoryContents> repoContents = githubService.getContents(githubInfo);
71-
72-
// Check that there is at least 1 .cwl file
73-
boolean foundCWL = false;
74-
for (RepositoryContents repoContent : repoContents) {
75-
int eIndex = repoContent.getName().lastIndexOf('.') + 1;
76-
if (eIndex > 0) {
77-
String extension = repoContent.getName().substring(eIndex);
78-
if (extension.equals("cwl")) {
79-
foundCWL = true;
80-
}
81-
}
82-
}
83-
if (foundCWL) {
84-
// Return the Github information
72+
if (containsCWL(repoContents, githubInfo)) {
8573
return githubInfo;
8674
} else {
8775
// The URL does not contain any .cwl files
@@ -105,4 +93,34 @@ public GithubDetails validateAndParse(WorkflowForm form, Errors e) {
10593
// Errors will stop this being used anyway
10694
return null;
10795
}
96+
97+
/**
98+
* Recursively check for CWL files within a Github repository
99+
* @param repoContents A list of contents within a path in the repository
100+
* @param githubDetails The details of the repository
101+
* @return Whether the path contains CWL files
102+
* @throws IOException Any API errors which may have occurred
103+
*/
104+
private boolean containsCWL(List<RepositoryContents> repoContents, GithubDetails githubDetails) throws IOException {
105+
// Check that there is at least 1 .cwl file
106+
for (RepositoryContents repoContent : repoContents) {
107+
if (repoContent.getType().equals(GitHubService.TYPE_DIR)) {
108+
GithubDetails githubSubdir = new GithubDetails(githubDetails.getOwner(),
109+
githubDetails.getRepoName(), githubDetails.getBranch(), repoContent.getPath());
110+
List<RepositoryContents> subdirectory = githubService.getContents(githubSubdir);
111+
if (containsCWL(subdirectory, githubSubdir)) {
112+
return true;
113+
}
114+
} else if (repoContent.getType().equals(GitHubService.TYPE_FILE)) {
115+
int eIndex = repoContent.getName().lastIndexOf('.') + 1;
116+
if (eIndex > 0) {
117+
String extension = repoContent.getName().substring(eIndex);
118+
if (extension.equals("cwl")) {
119+
return true;
120+
}
121+
}
122+
}
123+
}
124+
return false;
125+
}
108126
}

0 commit comments

Comments
 (0)