Add 'Available since' to module API function docs (#10229)

The script which generates the markdown docs from module.c is updated to include
the version in which each module API function was introduced.

The script uses git tags to find this information. If git is not available or if we're not in
a git repo, the 'since' is silently skipped.

The line `**Available since:** (version)` is added after the function prototype

Rename to utils/generate-module-api-doc.rb
This commit is contained in:
Viktor Söderqvist 2022-02-03 09:25:37 +01:00 committed by GitHub
parent c9e1602f90
commit f4ecc799c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,6 +78,7 @@ def docufy(src,i)
puts "<span id=\"#{name}\"></span>\n\n" puts "<span id=\"#{name}\"></span>\n\n"
puts "### `#{name}`\n\n" puts "### `#{name}`\n\n"
puts " #{proto}\n" puts " #{proto}\n"
puts "**Available since:** #{$since[name]}\n\n" if $since[name]
comment = "" comment = ""
while true while true
i = i-1 i = i-1
@ -135,8 +136,9 @@ def is_func_line(src, i)
end end
puts "# Modules API reference\n\n" puts "# Modules API reference\n\n"
puts "<!-- This file is generated from module.c using gendoc.rb -->\n\n" puts "<!-- This file is generated from module.c using\n"
src = File.open(File.dirname(__FILE__) ++ "/../module.c").to_a puts " utils/generate-module-api-doc.rb -->\n\n"
src = File.open(File.dirname(__FILE__) ++ "/../src/module.c").to_a
# Build function index # Build function index
$index = {} $index = {}
@ -148,6 +150,24 @@ src.each_with_index do |line,i|
end end
end end
# Populate the 'since' map (name => version) if we're in a git repo.
$since = {}
git_dir = File.dirname(__FILE__) ++ "/../.git"
if File.directory?(git_dir) && `which git` != ""
`git --git-dir="#{git_dir}" tag --sort=v:refname`.each_line do |version|
next if version !~ /^(\d+)\.\d+\.\d+?$/ || $1.to_i < 4
version.chomp!
`git --git-dir="#{git_dir}" cat-file blob "#{version}:src/module.c"`.each_line do |line|
if line =~ /^\w.*[ \*]RM_([A-z0-9]+)/
name = "RedisModule_#{$1}"
if ! $since[name]
$since[name] = version
end
end
end
end
end
# Print TOC # Print TOC
puts "## Sections\n\n" puts "## Sections\n\n"
src.each_with_index do |_line,i| src.each_with_index do |_line,i|