Skip to content

Commit 36f1bea

Browse files
authored
Auto-detect pipeline from provided input #1883 (#1904)
Signed-off-by: tdruez <[email protected]>
1 parent e22a24d commit 36f1bea

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

scanpipe/templates/scanpipe/project_form.html

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,62 @@ <h3 class="subtitle mb-3">Pipelines:</h3>
179179
pipelineSelect.addEventListener("change", handlePipelineChange);
180180
});
181181
</script>
182+
183+
<script>
184+
document.addEventListener("DOMContentLoaded", function() {
185+
function detectPipelineFromValue(value) {
186+
value = value.trim().toLowerCase();
187+
188+
if (!value) return "";
189+
190+
// Handle Docker reference
191+
if (value.startsWith("docker:")) return "analyze_docker_image";
192+
193+
// Handle Package URL
194+
if (value.startsWith("pkg:")) return "scan_single_package";
195+
196+
// Handle SBOM file formats
197+
if (
198+
value.endsWith(".spdx") ||
199+
value.endsWith(".spdx.json") ||
200+
value.endsWith(".spdx.yml") ||
201+
value.endsWith("bom.json") ||
202+
value.endsWith(".cdx.json") ||
203+
value.endsWith(".cyclonedx.json") ||
204+
value.endsWith("bom.xml") ||
205+
value.endsWith(".cdx.xml") ||
206+
value.endsWith(".cyclonedx.xml")
207+
) return "load_sbom";
208+
209+
// No match
210+
return "";
211+
}
212+
213+
const textarea = document.getElementById("id_input_urls");
214+
const pipelineSelect = document.getElementById("id_pipeline");
215+
const fileInput = document.getElementById("id_input_files");
216+
217+
// Handle textarea input
218+
textarea.addEventListener("input", () => {
219+
const value = textarea.value.trim();
220+
const pipeline = detectPipelineFromValue(value);
221+
pipelineSelect.value = pipeline;
222+
});
223+
224+
// Handle file uploads
225+
fileInput.addEventListener("change", () => {
226+
const files = Array.from(fileInput.files);
227+
228+
// Detect based on first file, multiple input files not supported.
229+
if (files.length === 1) {
230+
const firstFile = files[0].name.toLowerCase();
231+
const pipeline = detectPipelineFromValue(firstFile);
232+
pipelineSelect.value = pipeline;
233+
} else {
234+
pipelineSelect.value = "";
235+
}
236+
});
237+
238+
});
239+
</script>
182240
{% endblock %}

0 commit comments

Comments
 (0)