From c2fea1600d74ef63dcd8ba028d4a34a89b436027 Mon Sep 17 00:00:00 2001 From: Jeff Mesnil Date: Thu, 4 Jul 2024 08:44:44 +0200 Subject: [PATCH] Add labels for the stability-levels Based on the value of the `stability-level` field in the front matter, add a label `stability-level/xxx` to the PR. Signed-off-by: Jeff Mesnil --- .scripts/check_proposals | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/.scripts/check_proposals b/.scripts/check_proposals index 6a134d66..7ee64684 100755 --- a/.scripts/check_proposals +++ b/.scripts/check_proposals @@ -25,6 +25,7 @@ end class MetadataChecker def initialize @categories = load_all_categories() + @stability_levels = ["experimental", "preview", "community", "default"] end def check pr_number, front_matter @@ -44,12 +45,16 @@ class MetadataChecker else system("gh pr edit #{pr_number} --remove-label missing-issue") end - stability_level_error = check_stability_level(pr_number, front_matter) - if stability_level_error.length() > 0 - errors << stability_level_error - system("gh pr edit #{pr_number} --add-label invalid-stability-level") - else + begin + stability_level, err = check_stability_level(pr_number, front_matter) system("gh pr edit #{pr_number} --remove-label invalid-stability-level") + # remove any previous stability-levels + @stability_levels.map { | level | system("gh pr edit #{pr_number} --remove-label stability-level/#{level}") } + system("gh pr edit #{pr_number} --add-label stability-level/#{stability_level}") + rescue => error + errors << error.message + system("gh pr edit #{pr_number} --add-label invalid-stability-level") + @stability_levels.map { | level | system("gh pr edit #{pr_number} --remove-label stability-level/#{level}") } end errors @@ -78,13 +83,11 @@ class MetadataChecker end def check_stability_level pr_number, front_matter - stability_levels = ["experimental", "preview", "community", "default"] - - errors = [] - unless (front_matter.key? "stability-level") && (stability_levels.include? front_matter["stability-level"]) - errors << "Invalid field: stability-level" + unless (front_matter.key? "stability-level") && (@stability_levels.include? front_matter["stability-level"]) + raise "Invalid field: stability-level" + else + return front_matter["stability-level"] end - errors end def load_all_categories