Class: Fastlane::Actions::UpdateAssignedMilestoneAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



58
59
60
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/update_assigned_milestone_action.rb', line 58

def self.authors
  ['Automattic']
end

.available_optionsObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/update_assigned_milestone_action.rb', line 70

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: :numbers,
                                 description: 'The PR and/or issue numbers to update the milestone of',
                                 optional: true,
                                 type: Array,
                                 conflicting_options: [:from_milestone]),
    FastlaneCore::ConfigItem.new(key: :from_milestone,
                                 description: 'The version (start of the milestone title) for which we intend to update all open PRs and issues to a new milestone',
                                 optional: true,
                                 type: String,
                                 conflicting_options: [:numbers]),
    FastlaneCore::ConfigItem.new(key: :to_milestone,
                                 description: 'The version (start of the milestone title) for the new milestone to assign to the targeted PRs and issues. Pass nil to unset the milestone',
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :comment,
                                 description: 'If non-nil, the custom comment to leave on each PR and issue whose milestone has been updated',
                                 optional: true,
                                 type: String),
    Fastlane::Helper::GithubHelper.github_token_config_item,
  ]
end

.descriptionObject



54
55
56
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/update_assigned_milestone_action.rb', line 54

def self.description
  'Updates the milestone field of GitHub Issues and PRs'
end

.detailsObject



66
67
68
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/update_assigned_milestone_action.rb', line 66

def self.details
  'Updates the milestone field of a given list of PRs/Issues, or of all still-opened PRs/Issues in a given milestone'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/update_assigned_milestone_action.rb', line 99

def self.is_supported?(platform)
  true
end

.return_valueObject



62
63
64
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/update_assigned_milestone_action.rb', line 62

def self.return_value
  'The numbers of all the PRs and Isses that were updated with the new milestone'
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/update_assigned_milestone_action.rb', line 7

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

  github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])

  numbers = params[:numbers]
  from_milestone = params[:from_milestone]
  to_milestone = params[:to_milestone]
  comment = params[:comment]

  target_milestone = nil
  unless to_milestone.nil?
    target_milestone = github_helper.get_milestone(repository, to_milestone)
    UI.user_error!("Unable to find target milestone matching version #{to_milestone}") if target_milestone.nil?
  end

  issues_list = if numbers
                  numbers
                elsif from_milestone
                  # get the milestone object based on title starting text
                  m = github_helper.get_milestone(repository, from_milestone)
                  UI.user_error!("Unable to find source milestone matching version #{from_milestone}") if m.nil?

                  # get all open PRs in that milestone
                  github_helper.get_prs_and_issues_for_milestone(repository: repository, milestone: m).map(&:number)
                else
                  UI.user_error!('One of `numbers` or `from_milestone` must be provided to indicate which PR(s)/issue(s) to update')
                end

  UI.message("Updating milestone of #{issues_list.count} PRs/Issues to `#{target_milestone&.title}`")

  issues_list.each do |num|
    github_helper.set_milestone(
      repository: repository,
      number: num,
      milestone: target_milestone
    )
    next if comment.nil? || comment.empty?

    github_helper.comment_on_pr(
      project_slug: repository,
      pr_number: num,
      body: comment
    )
  end
end