diff mbox series

[yocto-autobuilder2,5/5] releaseselector: Read release shortcuts from the force scheduler spec

Message ID 20261104-mathieu-release-selector-fix-v1-5-a245895c0093@bootlin.com
State New
Headers show
Series releaseselector: Fix know issues and improve configuration retrieval | expand

Commit Message

Mathieu Dubois-Briand Nov. 4, 2026, 9:32 a.m. UTC
The release selector configuration was encoded in the choice strings
and decoded in the browser. Instead, use field spec attribute to
retrieve them.

AI-Generated: Uses opencode (DeepSeek V4 Flash)
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
---
 yocto_console_view/src/releaseselectorfield.ts    | 52 ++++++++++-------------
 yocto_console_view/yocto_console_view/__init__.py |  9 +---
 2 files changed, 23 insertions(+), 38 deletions(-)
diff mbox series

Patch

diff --git a/yocto_console_view/src/releaseselectorfield.ts b/yocto_console_view/src/releaseselectorfield.ts
index 1c4d289af224..c5c681a51e29 100644
--- a/yocto_console_view/src/releaseselectorfield.ts
+++ b/yocto_console_view/src/releaseselectorfield.ts
@@ -1,5 +1,5 @@ 
 import {buildbotSetupPlugin} from "buildbot-plugin-support";
-buildbotSetupPlugin((reg) => {
+buildbotSetupPlugin((reg, config) => {
 	let selectInputName = null;
 	let selectListName = null;
 	let inputRefs = null;
@@ -12,6 +12,26 @@  buildbotSetupPlugin((reg) => {
 		return label ? label.textContent.split(':')[0] : null;
 	}
 
+	async function loadSelectors() {
+		try {
+			const res = await fetch(config.buildbotURL + 'api/v2/forceschedulers', {
+				headers: {accept: 'application/json'}
+			});
+			const data = await res.json();
+			for (const sched of data.forceschedulers ?? []) {
+				for (const field of sched.all_fields) {
+					if (field.selectors) {
+						selectors = new Map(Object.entries(field.selectors));
+						return;
+					}
+				}
+			}
+		} catch (e) {
+			console.error('releaseselector: failed to load release shortcuts:', e);
+		}
+	}
+	loadSelectors();
+
 	const onTransitionEndEvent = (event) => {
 		/*
 		 * We are looking for the transition showing the "forcebuild" dialog.
@@ -46,19 +66,11 @@  buildbotSetupPlugin((reg) => {
 			prepareInterceptor(input);
 		});
 
-		/*
-		 * Only show the pretty name in the release selector field.
-		 */
-		const releaseSelector = inputRefs.get('force-field-branchselector');
-		const releaseSelectorLabel = releaseSelector.parentNode.previousSibling;
-		const sepIdx = releaseSelectorLabel.textContent.indexOf(':');
-		if (sepIdx >= 0) {
-			releaseSelectorLabel.textContent = releaseSelectorLabel.textContent.substring(0, sepIdx);
-		}
 
 		/*
 		 * Get the name of the ReleaseSelector field div.
 		 */
+		const releaseSelector = inputRefs.get('force-field-branchselector');
 		selectInputName = releaseSelector.attributes.getNamedItem('id').value;
 		const selectName = selectInputName.substring(0, selectInputName.lastIndexOf('-'));
 		selectListName = selectName + '-listbox';
@@ -66,24 +78,6 @@  buildbotSetupPlugin((reg) => {
 	}
 	window.addEventListener('transitionend', onTransitionEndEvent);
 
-	function updateSelectors() {
-		if (selectListName) {
-			const listDiv = document.getElementById(selectListName);
-			if (listDiv) {
-				listDiv.childNodes.forEach(div => {
-					const sepIdx = div.textContent.indexOf(':');
-					if (sepIdx >= 0) {
-						try {
-							selectors.set(div.textContent.substring(0, sepIdx),
-							              JSON.parse(div.textContent.substring(sepIdx + 1)));
-						} catch (e) {}
-						div.textContent = div.textContent.substring(0, sepIdx);
-					}
-				});
-			}
-		}
-	}
-
 	function applySelectorByName(name) {
 		const selector = selectors.get(name);
 		if (selector) {
@@ -92,8 +86,6 @@  buildbotSetupPlugin((reg) => {
 	}
 
 	const onClick = (event) => {
-		updateSelectors();
-
 		if (event.target.parentElement) {
 			const parentId = event.target.parentElement.attributes.getNamedItem('id');
 			if (parentId && parentId.value == selectListName) {
diff --git a/yocto_console_view/yocto_console_view/__init__.py b/yocto_console_view/yocto_console_view/__init__.py
index 6118ac29409b..eedf6958cfe9 100644
--- a/yocto_console_view/yocto_console_view/__init__.py
+++ b/yocto_console_view/yocto_console_view/__init__.py
@@ -16,8 +16,6 @@ 
 from buildbot.www.plugin import Application
 from buildbot.schedulers.forcesched import ChoiceStringParameter
 
-import json
-
 # create the interface for the setuptools entry point
 ep = Application(__package__, "Yocto Buildbot Console View plugin")
 
@@ -27,10 +25,5 @@  class ReleaseSelector(ChoiceStringParameter):
     selectors = None
 
     def __init__(self, name, selectors, **kw):
-        def format_choice(choice):
-            return choice + ': ' + json.dumps(selectors.get(choice, {}))
-
         super().__init__(name, **kw)
-        self.choices = [format_choice(choice)
-                        for choice in kw.get('choices', {})]
-        self.__dict__['default'] = format_choice(self.__dict__['default'])
+        self.selectors = selectors