summaryrefslogtreecommitdiff
path: root/scripts/update-feature-categories
blob: 88520b9f95f26be10b8014d3052fa5e35a924a60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'uri'
require 'net/http'
require 'yaml'

url = URI("https://gitlab.com/gitlab-com/www-gitlab-com/raw/master/data/stages.yml")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)

response = http.request(request)

stages_doc = YAML.safe_load(response.read_body)
feature_categories = stages_doc["stages"].values
  .flat_map { |stage| stage["groups"].values }
  .flat_map { |group| group["categories"] }
  .select(&:itself)
  .uniq
  .sort

File.open("#{__dir__}/../config/feature_categories.yml", 'w') do |file|
  file.puts(<<~HEADER_COMMENT)
    #
    # This file contains a list of all feature categories in GitLab
    # It is generated from the stages file at #{url}.
    # If you would like to update it, please run
    # `./scripts/update-feature-categories` to generate a new copy
    #
    # PLEASE DO NOT EDIT THIS FILE MANUALLY.
    #
  HEADER_COMMENT
  file.write(feature_categories.to_yaml)
end