diff mbox series

[yocto-autobuilder2] reporters: swatbot: Fix branch name retrieval

Message ID 20250910-contrib-mathieu-swatbot_branches_fix-v1-1-55f1635094c7@bootlin.com
State New
Headers show
Series [yocto-autobuilder2] reporters: swatbot: Fix branch name retrieval | expand

Commit Message

Mathieu Dubois-Briand Sept. 10, 2025, 8:52 a.m. UTC
The swatbot reporter tries to get the name of the built branch, using
the "branch_poky" property of the build. Some builders, such as "docs",
do not use the poky git, so this property is missing. Currently, this
result in a non-fatal error on the buildbot controller, but the build
entry is not added to swatbot.

Import code from swattool, falling back to oecore or yocto-docs branch
name.

Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
---
 reporters/swatbot.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)


---
base-commit: 247aaef0910826113ccfc892f42f9012a45034f7
change-id: 20250910-contrib-mathieu-swatbot_branches_fix-7fbe5402eed6

Best regards,
diff mbox series

Patch

diff --git a/reporters/swatbot.py b/reporters/swatbot.py
index 5e434d5d04a4..6e3827329033 100644
--- a/reporters/swatbot.py
+++ b/reporters/swatbot.py
@@ -49,6 +49,24 @@  class SwatBotURI(object):
             return self.client.get(query, timeout=self.TIMEOUT, headers=self.headers, allow_redirects=False)
         return req
 
+    def get_build_branch(self, build):
+        """Extract branch name from build properties.
+
+        Args:
+            build: Build dictionary containing properties
+
+        Returns:
+            Branch name if found, None otherwise
+        """
+        repos = ['poky', 'oecore', 'yocto-docs']
+        for repo in repos:
+            branch = build['properties'].get(f'branch_{repo}')
+            if branch:
+                return branch[0]
+        branches = [p for p in build['properties'] if p.startswith('branch')]
+        log.err("Failed to get corresponding branch, possible values: %s", branches)
+        return None
+
     def find_build_collection(self, build):
         dbid = None
 
@@ -77,7 +95,7 @@  class SwatBotURI(object):
                     'attributes': {
                         "buildid": collection_build_id,
                         "targetname": build['builder']['name'],
-                        "branch": build['properties']['branch_poky'][0],
+                        "branch": self.get_build_branch(build)
                     }
                 }
             }