fastlane-plugin-wpmreleasetoolkit 9.3.1 → 9.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adbc7e50db36af4f4a69cb15a8d7ec5b0f006b9632e9027497f38d02e7c8670d
4
- data.tar.gz: 18cc86253415b727a3677e47d70d0541c25d38d7fec610d377e292922ad53e2a
3
+ metadata.gz: bd44032856f74c52c1ddc0ad52169d8c88f8af309a3654e5d3f4aed2bfaee8fc
4
+ data.tar.gz: af620c26cfe9f8c4c0bbf80d59ef1d3042dbb293eed051592ff94d589fd22074
5
5
  SHA512:
6
- metadata.gz: 297b158333face55b84e385eb76509377d4d40cf9a908cf90bae25c01024938aacdcf7276d2933b461795021c3fab5d10adecd27ad2869fb152f6fee4bdfad1b
7
- data.tar.gz: 293850e7a492026281c7d9234aeb7d751c395a1bfe03c55403bfcdd1cd88d277cca5067e8fbc810c2fd7a1e796a378aaa7b9dff39cd57a8033db6a91c6b9dd21
6
+ metadata.gz: 44a3e501c71875f0c3e621a5cbc99cc866204ac28777c3ce1745c22f4aafdde179bae6716ab660475624aaab2c682621baf748914695218aeb02f5e242080cbf
7
+ data.tar.gz: fb19b292f589ee8c63dcc54abc8908bbfe8f73ec3af087ea3d4b8aff91ad7246bb2a92a4e6a04411dd5f56f3b4ba1707012c8d98207ab3c460403086d8b06c96
@@ -0,0 +1,104 @@
1
+ require 'fastlane/action'
2
+ require_relative '../../helper/github_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class UpdatePullRequestsMilestoneAction < Action
7
+ def self.run(params)
8
+ repository = params[:repository]
9
+
10
+ github_helper = Fastlane::Helper::GithubHelper.new(github_token: params[:github_token])
11
+
12
+ pr_numbers = params[:pr_numbers]
13
+ from_milestone = params[:from_milestone]
14
+ to_milestone = params[:to_milestone]
15
+ pr_comment = params[:pr_comment]
16
+
17
+ target_milestone = nil
18
+ unless to_milestone.nil?
19
+ target_milestone = github_helper.get_milestone(repository, to_milestone)
20
+ UI.user_error!("Unable to find target milestone matching version #{to_milestone}") if target_milestone.nil?
21
+ end
22
+
23
+ prs_nums = if pr_numbers
24
+ pr_numbers
25
+ elsif from_milestone
26
+ # get the milestone object based on title starting text
27
+ m = github_helper.get_milestone(repository, from_milestone)
28
+ UI.user_error!("Unable to find source milestone matching version #{from_milestone}") if m.nil?
29
+
30
+ # get all open PRs in that milestone
31
+ github_helper.get_prs_for_milestone(repository: repository, milestone: m).map(&:number)
32
+ else
33
+ UI.user_error!('One of `pr_numbers` or `from_milestone` must be provided to indicate which PR(s) to update')
34
+ end
35
+
36
+ UI.message("Updating milestone of #{prs_nums.count} PRs to `#{target_milestone&.title}`")
37
+
38
+ prs_nums.each do |pr_num|
39
+ github_helper.set_pr_milestone(
40
+ repository: repository,
41
+ pr_number: pr_num,
42
+ milestone: target_milestone
43
+ )
44
+ next if pr_comment.nil? || pr_comment.empty?
45
+
46
+ github_helper.comment_on_pr(
47
+ project_slug: repository,
48
+ pr_number: pr_num,
49
+ body: pr_comment
50
+ )
51
+ end
52
+ end
53
+
54
+ def self.description
55
+ 'Updates the milestone field of PRs'
56
+ end
57
+
58
+ def self.authors
59
+ ['Automattic']
60
+ end
61
+
62
+ def self.return_value
63
+ 'The PR numbers of all the PRs that were updated with the new milestone'
64
+ end
65
+
66
+ def self.details
67
+ 'Updates the milestone field of a PR, of or all still-opened PRs in a milestone'
68
+ end
69
+
70
+ def self.available_options
71
+ [
72
+ FastlaneCore::ConfigItem.new(key: :repository,
73
+ env_name: 'GHHELPER_REPOSITORY',
74
+ description: 'The remote path of the GH repository on which we work',
75
+ optional: false,
76
+ type: String),
77
+ FastlaneCore::ConfigItem.new(key: :pr_numbers,
78
+ description: 'The PR numbers to update the milestone of',
79
+ optional: true,
80
+ type: Array,
81
+ conflicting_options: [:from_milestone]),
82
+ FastlaneCore::ConfigItem.new(key: :from_milestone,
83
+ description: 'The version (milestone title\'s start) for which we want to update all open PRs of to a new milestone',
84
+ optional: true,
85
+ type: String,
86
+ conflicting_options: [:pr_numbers]),
87
+ FastlaneCore::ConfigItem.new(key: :to_milestone,
88
+ description: 'The version (milestone title\'s start) for the new milestone to assign to the targeted PRs. Pass nil to unset the milestone',
89
+ optional: true,
90
+ type: String),
91
+ FastlaneCore::ConfigItem.new(key: :pr_comment,
92
+ description: 'If non-nil, the custom comment to leave on each PR whose milestone has been updated',
93
+ optional: true,
94
+ type: String),
95
+ Fastlane::Helper::GithubHelper.github_token_config_item,
96
+ ]
97
+ end
98
+
99
+ def self.is_supported?(platform)
100
+ true
101
+ end
102
+ end
103
+ end
104
+ end
@@ -25,25 +25,49 @@ module Fastlane
25
25
  @client.auto_paginate = true
26
26
  end
27
27
 
28
+ # @param [String] repository A GitHub repository slug
29
+ # @param [String] release The release version to find the milestone for.
30
+ # @note This relies on the `release` version string being at the start of the milestone's `title`
31
+ # @return [Sawyer::Resource] A milestone object in a repository, or nil if none matches
32
+ #
28
33
  def get_milestone(repository, release)
29
- miles = client.list_milestones(repository)
30
- mile = nil
31
-
32
- miles&.each do |mm|
33
- mile = mm if mm[:title].start_with?(release)
34
+ milestones = client.list_milestones(repository)
35
+ milestones&.reverse&.find do |m|
36
+ m[:title].start_with?(release)
34
37
  end
35
-
36
- return mile
37
38
  end
38
39
 
39
40
  # Fetch all the PRs for a given milestone
40
41
  #
41
42
  # @param [String] repository The repository name, including the organization (e.g. `wordpress-mobile/wordpress-ios`)
42
- # @param [String] milestone The name of the milestone we want to fetch the list of PRs for (e.g.: `16.9`)
43
- # @return [<Sawyer::Resource>] A list of the PRs for the given milestone, sorted by number
43
+ # @param [Sawyer::Resource, String] milestone The milestone object, or title of the milestone, we want to fetch the list of PRs for (e.g.: `16.9`)
44
+ # @param [Boolean] include_closed If set to true, will include both opened and closed PRs. Otherwise, will only include opened PRs.
45
+ # @return [Array<Sawyer::Resource>] A list of the PRs for the given milestone, sorted by number
44
46
  #
45
- def get_prs_for_milestone(repository, milestone)
46
- client.search_issues(%(type:pr milestone:"#{milestone}" repo:#{repository}))[:items].sort_by(&:number)
47
+ def get_prs_for_milestone(repository:, milestone:, include_closed: false)
48
+ milestone_title = milestone.is_a?(Sawyer::Resource) ? milestone.title : milestone
49
+ query = %(repo:#{repository} type:pr milestone:"#{milestone_title}")
50
+ query += ' is:open' unless include_closed
51
+
52
+ client.search_issues(query)[:items].sort_by(&:number)
53
+ end
54
+
55
+ # Set/Update the milestone assigned to a given PR or issue
56
+ #
57
+ # @param [String] repository The repository name, including the organization (e.g. `wordpress-mobile/wordpress-ios`)
58
+ # @param [Integer] pr_number The PR (or issue) number to update the milestone of
59
+ # @param [Sawyer::Resource?, Integer?] milestone The milestone object or number to set on this PR, or nil to unset the milestone
60
+ # @note Use `get_milestone` to get a milestone object from a version number
61
+ # @raise [Fastlane::UI::Error] UI.user_error! if PR does not exist or milestone provided is invalid
62
+ #
63
+ def set_pr_milestone(repository:, pr_number:, milestone:)
64
+ milestone_num = milestone.is_a?(Sawyer::Resource) ? milestone.number : milestone
65
+
66
+ client.update_issue(repository, pr_number, { milestone: milestone_num })
67
+ rescue Octokit::NotFound
68
+ UI.user_error!("Could not find PR ##{pr_number} in #{repository}")
69
+ rescue Octokit::UnprocessableEntity
70
+ UI.user_error!("Invalid milestone #{milestone_num}")
47
71
  end
48
72
 
49
73
  def get_last_milestone(repository)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fastlane
4
4
  module Wpmreleasetoolkit
5
- VERSION = '9.3.1'
5
+ VERSION = '9.4.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-wpmreleasetoolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.3.1
4
+ version: 9.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Automattic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-15 00:00:00.000000000 Z
11
+ date: 2024-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -460,6 +460,7 @@ files:
460
460
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/remove_branch_protection_action.rb
461
461
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/set_branch_protection_action.rb
462
462
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/setfrozentag_action.rb
463
+ - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/update_pull_requests_milestone_action.rb
463
464
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/upload_to_s3.rb
464
465
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_add_files_to_copy_action.rb
465
466
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/configure/configure_apply_action.rb