Class: Fastlane::Actions::SetMilestoneFrozenMarkerAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/actions/common/set_milestone_frozen_marker_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



50
51
52
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/set_milestone_frozen_marker_action.rb', line 50

def self.authors
  ['Automattic']
end

.available_optionsObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/set_milestone_frozen_marker_action.rb', line 54

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :repository,
                                 env_name: 'GHHELPER_REPOSITORY',
                                 description: 'The remote path of the GH repository on which we work',
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :milestone,
                                 env_name: 'GHHELPER_MILESTORE',
                                 description: 'The GitHub milestone',
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :freeze,
                                 description: 'If true, the action will add the ❄️ emoji to the milestone title; otherwise, will remove it if already present',
                                 optional: false,
                                 default_value: true,
                                 type: Boolean),
    Fastlane::Helper::GithubHelper.github_token_config_item,
  ]
end

.descriptionObject



46
47
48
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/set_milestone_frozen_marker_action.rb', line 46

def self.description
  'Add or remove the frozen marker (❄️ emoji) on a given GitHub milestone'
end

.is_frozen(milestone) ⇒ Object



40
41
42
43
44
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/set_milestone_frozen_marker_action.rb', line 40

def self.is_frozen(milestone)
  return milestone[:title].include?('❄️') unless milestone.nil?

  false
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/set_milestone_frozen_marker_action.rb', line 75

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



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
38
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/set_milestone_frozen_marker_action.rb', line 7

def self.run(params)
  repository = params[:repository]
  milestone_title = params[:milestone]
  freeze = params[:freeze]

  github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
  milestone = github_helper.get_milestone(repository, milestone_title)

  UI.user_error!("Milestone `#{milestone_title}` not found.") if milestone.nil?

  mile_title = milestone[:title]

  if freeze
    # Check if the state needs changes
    if is_frozen(milestone)
      UI.message("Milestone `#{mile_title}` is already frozen. Nothing to do")
      return # Already frozen: nothing to do
    end

    mile_title = "#{mile_title} ❄️"
  else
    unless is_frozen(milestone)
      UI.message("Milestone `#{mile_title}` is not frozen. Nothing to do")
      return # Not frozen: nothing to do
    end

    mile_title = milestone[:title].gsub(/ ?❄️/, '')
  end

  UI.message("New milestone title: `#{mile_title}`")
  github_helper.update_milestone(repository: repository, number: milestone[:number], title: mile_title)
end