Skip to content

Commit 6a47b9d

Browse files
authored
fetch-external-content: Fetch openhab.d.ts bundled type definitions from openhab-js releases (#2757)
Signed-off-by: Florian Hotze <dev@florianhotze.com>
1 parent 346d28e commit 6a47b9d

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

scripts/fetch-external-content.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,27 @@ def update_external_repositories
9393
end
9494
end
9595

96+
def fetch_openhab_js_types
97+
pom_path = File.join(RESOURCE_FOLDER, "openhab-addons/bundles/org.openhab.automation.jsscripting/pom.xml")
98+
unless File.exist?(pom_path)
99+
warn " ⚠️ JS Scripting POM not found at #{pom_path}"
100+
return
101+
end
102+
103+
pom_content = File.read(pom_path)
104+
version_match = pom_content.match(/<ohjs.version>(.*?)<\/ohjs.version>/)
105+
unless version_match
106+
warn " ⚠️ Could not find <ohjs.version> in JS Scripting POM"
107+
return
108+
end
109+
110+
ohjs_version = version_match[1].strip
111+
puts " Found openhab-js version in POM: #{ohjs_version}"
112+
113+
dest_path = File.join(BASE_DIR, "addons/automation/jsscripting/res/openhab.d.ts")
114+
download_github_release_asset("openhab/openhab-js", ohjs_version, "openhab.d.ts", dest_path)
115+
end
116+
96117
def main
97118
puts "Starting fetch external content pipeline..."
98119

@@ -128,6 +149,9 @@ def main
128149
end
129150
puts " ✔ Processed add-on readme files"
130151

152+
# 4b. Fetch openhab.d.ts definitions based on JS Scripting POM version
153+
fetch_openhab_js_types
154+
131155
# 5. Inline Ecosystem and Apps copying/renaming
132156
puts " Copying ecosystem & apps documentation..."
133157

scripts/lib/process_utils.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
require "fileutils"
44
require "pathname"
5+
require "net/http"
6+
require "uri"
57

68
ADDONS_REPO_BRANCH = "main"
79

@@ -271,3 +273,33 @@ def self.colorize(text, color_name)
271273
"\e[#{color_code}m#{text}\e[0m"
272274
end
273275
end
276+
277+
def download_github_release_asset(repo, tag, asset_name, dest_path)
278+
url = "https://github.com/#{repo}/releases/download/#{tag}/#{asset_name}"
279+
puts " Fetching #{asset_name} from GitHub release #{tag}..."
280+
281+
uri = URI(url)
282+
limit = 5
283+
while limit > 0
284+
response = Net::HTTP.get_response(uri)
285+
case response
286+
when Net::HTTPSuccess
287+
FileUtils.mkdir_p(File.dirname(dest_path))
288+
File.write(dest_path, response.body)
289+
puts " ✔ Saved #{asset_name} to #{dest_path}"
290+
return true
291+
when Net::HTTPRedirection
292+
location = response['location']
293+
uri = URI(location)
294+
limit -= 1
295+
when Net::HTTPNotFound
296+
warn " ⚠️ Asset #{asset_name} not found in release #{tag} (HTTP 404)"
297+
return false
298+
else
299+
warn " ⚠️ HTTP Error: #{response.code} #{response.message} for #{url}"
300+
return false
301+
end
302+
end
303+
warn " ⚠️ Too many redirects trying to download #{asset_name}"
304+
false
305+
end

0 commit comments

Comments
 (0)