summaryrefslogtreecommitdiff
path: root/lib/tasks/gitlab/product_intelligence.rake
blob: 329cd9c8c2a0f396b16c41935442b3ba65dbed59 (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
# frozen_string_literal: true

namespace :gitlab do
  namespace :product_intelligence do
    # @example
    #   bundle exec rake gitlab:product_intelligence:activate_metrics MILESTONE=14.0

    desc 'GitLab | Product Intelligence | Update milestone metrics status to data_available'
    task activate_metrics: :environment do
      milestone = ENV['MILESTONE']
      raise "Please supply the MILESTONE env var".color(:red) unless milestone.present?

      Gitlab::Usage::MetricDefinition.definitions.values.each do |metric|
        next if metric.attributes[:milestone] != milestone || metric.attributes[:status] != 'implemented'

        metric.attributes[:status] = 'data_available'
        path = metric.path
        File.open(path, "w") { |file| file << metric.to_h.deep_stringify_keys.to_yaml }
      end

      puts "Task completed successfully"
    end
  end
end