fastlane-plugin-wpmreleasetoolkit 12.3.3 → 12.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: 041f45f2654eb686e2730d5e33adf6023c10649a12d0a31cdd93795e96660a95
4
- data.tar.gz: 9c95db0f646fb9879c908a9234bbb764f334195ad84a3ba274baf53ce967544d
3
+ metadata.gz: d4cdbaa88428a89afebe8e5ccddc35bc4ebce263ae07caa40598fc54bec24fca
4
+ data.tar.gz: a16e7052eddb43d6f98aab25c51ad2628d702b54842f726ee4c1fde45003eb02
5
5
  SHA512:
6
- metadata.gz: 3ed5eb05f72b84b22e60c85acbb7787623ffc3d76efa077d1197934e01191afca394d2ec5ae92974e603dd2955f22ae2a36866a2ca751ae0e300f01bb01453b2
7
- data.tar.gz: aa314297334366742f676bdd2d0cc96ff609e975bb0a75ab4fc5ce62b676de89dd6065fc0e6e9383bdb519f381255b261f1f0555539568148f03f842c42cc660
6
+ metadata.gz: 6c2999022ddf9da5acaaf1085344a31458a88c048daa6b3ef91350f8875fcdb94326d3c29335abcbab965eb507112cab0d45d3fb75fe826f01f2f185ee843857
7
+ data.tar.gz: '08151bb5c92923d4733f0a3aa590c03a912dcc5378099482c8e2388334849d85e9fa2c826c5c69e13e985b31a2171b136daf4d6779f0d750ac2df54a9c2b9d76'
@@ -8,16 +8,18 @@ module Fastlane
8
8
  release_notes_file_path = params[:release_notes_file_path]
9
9
  extracted_notes_file_path = params[:extracted_notes_file_path]
10
10
 
11
- extracted_notes_file = File.open(extracted_notes_file_path, 'w') unless extracted_notes_file_path.blank?
12
-
11
+ extracted_notes = ''
13
12
  extract_notes(release_notes_file_path, version) do |line|
14
- extracted_notes_file.nil? ? puts(line) : extracted_notes_file.write(line)
13
+ extracted_notes += line
15
14
  end
15
+ extracted_notes.chomp!('') # Remove any extra empty line(s) at the end
16
16
 
17
- return if extracted_notes_file.nil?
17
+ unless extracted_notes_file_path.nil? || extracted_notes_file_path.empty?
18
+ File.write(extracted_notes_file_path, extracted_notes)
19
+ commit_extracted_notes_file(extracted_notes_file_path, version)
20
+ end
18
21
 
19
- extracted_notes_file.close
20
- check_and_commit_extracted_notes_file(extracted_notes_file_path, version)
22
+ extracted_notes
21
23
  end
22
24
 
23
25
  def self.extract_notes(release_notes_file_path, version)
@@ -39,9 +41,13 @@ module Fastlane
39
41
  end
40
42
  end
41
43
 
42
- def self.check_and_commit_extracted_notes_file(file_path, version)
43
- Action.sh("git add #{file_path}")
44
- Action.sh("git diff-index --quiet HEAD || git commit -m \"Update draft release notes for #{version}.\"")
44
+ def self.commit_extracted_notes_file(file_path, version)
45
+ other_action.git_add(path: file_path)
46
+ other_action.git_commit(
47
+ path: file_path,
48
+ message: "Update draft release notes for #{version}",
49
+ allow_nothing_to_commit: true
50
+ )
45
51
  end
46
52
 
47
53
  def self.description
@@ -53,7 +59,7 @@ module Fastlane
53
59
  end
54
60
 
55
61
  def self.return_value
56
- # If your method provides a return value, you can describe here what it does
62
+ 'The content of the extracted release notes (the same text as what was written in the `extracted_notes_file_path` if one was provided)'
57
63
  end
58
64
 
59
65
  def self.details
@@ -0,0 +1,141 @@
1
+ require 'fastlane/action'
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ module Fastlane
6
+ module Actions
7
+ class OpenaiAskAction < Action
8
+ OPENAI_API_ENDPOINT = URI('https://api.openai.com/v1/chat/completions').freeze
9
+
10
+ PREDEFINED_PROMPTS = {
11
+ release_notes: <<~PROMPT.freeze
12
+ Act like a mobile app marketer who wants to prepare release notes for Google Play and App Store.
13
+ Do not write it point by point and keep it under 350 characters. It should be a unique paragraph.
14
+
15
+ When provided a list, use the number of any potential "*" in brackets at the start of each item as indicator of importance.
16
+ Ignore items starting with "[Internal]", and ignore links to GitHub.
17
+ PROMPT
18
+ }.freeze
19
+
20
+ def self.run(params)
21
+ api_token = params[:api_token]
22
+ prompt = params[:prompt]
23
+ prompt = PREDEFINED_PROMPTS[prompt] if PREDEFINED_PROMPTS.key?(prompt)
24
+ question = params[:question]
25
+
26
+ headers = {
27
+ 'Content-Type': 'application/json',
28
+ Authorization: "Bearer #{api_token}"
29
+ }
30
+ body = request_body(prompt: prompt, question: question)
31
+
32
+ response = Net::HTTP.post(OPENAI_API_ENDPOINT, body, headers)
33
+
34
+ case response
35
+ when Net::HTTPOK
36
+ json = JSON.parse(response.body)
37
+ json['choices']&.first&.dig('message', 'content')
38
+ else
39
+ UI.user_error!("Error in OpenAI API response: #{response}. #{response.body}")
40
+ end
41
+ end
42
+
43
+ def self.request_body(prompt:, question:)
44
+ {
45
+ model: 'gpt-4o',
46
+ response_format: { type: 'text' },
47
+ temperature: 1,
48
+ max_tokens: 2048,
49
+ top_p: 1,
50
+ messages: [
51
+ format_message(role: 'system', text: prompt),
52
+ format_message(role: 'user', text: question),
53
+ ].compact
54
+ }.to_json
55
+ end
56
+
57
+ def self.format_message(role:, text:)
58
+ return nil if text.nil? || text.empty?
59
+
60
+ {
61
+ role: role,
62
+ content: [{ type: 'text', text: text }]
63
+ }
64
+ end
65
+
66
+ #####################################################
67
+ # @!group Documentation
68
+ #####################################################
69
+
70
+ def self.description
71
+ 'Use OpenAI API to generate response to a prompt'
72
+ end
73
+
74
+ def self.authors
75
+ ['Automattic']
76
+ end
77
+
78
+ def self.return_value
79
+ 'The response text from the prompt as returned by OpenAI API'
80
+ end
81
+
82
+ def self.details
83
+ <<~DETAILS
84
+ Uses the OpenAI API to generate response to a prompt.
85
+ Can be used to e.g. ask it to generate Release Notes based on a bullet point technical changelog or similar.
86
+ DETAILS
87
+ end
88
+
89
+ def self.examples
90
+ [
91
+ <<~EXEMPLE,
92
+ items = extract_release_notes_for_version(version: app_version, release_notes_file_path: 'RELEASE-NOTES.txt')
93
+ nice_changelog = openai_ask(
94
+ prompt: :release_notes, # Uses the pre-crafted prompt for App Store / Play Store release notes
95
+ question: "Help me write release notes for the following items:\n#{items}",
96
+ api_token: get_required_env('OPENAI_API_TOKEN')
97
+ )
98
+ File.write(File.join('fastlane', 'metadata', 'android', 'en-US', 'changelogs', 'default.txt'), nice_changelog)
99
+ EXEMPLE
100
+ ]
101
+ end
102
+
103
+ def self.available_prompt_symbols
104
+ PREDEFINED_PROMPTS.keys.map { |v| "`:#{v}`" }.join(',')
105
+ end
106
+
107
+ def self.available_options
108
+ [
109
+ FastlaneCore::ConfigItem.new(key: :prompt,
110
+ description: 'The internal top-level instructions to give to the model to tell it how to behave. ' \
111
+ + "Use a Ruby Symbol from one of [#{available_prompt_symbols}] to use a predefined prompt instead of writing your own",
112
+ optional: true,
113
+ default_value: nil,
114
+ type: String,
115
+ skip_type_validation: true,
116
+ verify_block: proc do |value|
117
+ next if value.is_a?(String)
118
+ next if PREDEFINED_PROMPTS.include?(value)
119
+
120
+ UI.user_error!("Parameter `prompt` can only be a String or one of the following Symbols: [#{available_prompt_symbols}]")
121
+ end),
122
+ FastlaneCore::ConfigItem.new(key: :question,
123
+ description: 'The user message to ask the question to the OpenAI model',
124
+ optional: false,
125
+ default_value: nil,
126
+ type: String),
127
+ FastlaneCore::ConfigItem.new(key: :api_token,
128
+ description: 'The OpenAI API Token to use for the request',
129
+ env_name: 'OPENAI_API_TOKEN',
130
+ optional: false,
131
+ sensitive: true,
132
+ type: String),
133
+ ]
134
+ end
135
+
136
+ def self.is_supported?(_platform)
137
+ true
138
+ end
139
+ end
140
+ end
141
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fastlane
4
4
  module Wpmreleasetoolkit
5
- VERSION = '12.3.3'
5
+ VERSION = '12.4.0'
6
6
  end
7
7
  end
@@ -8,19 +8,18 @@ module Fastlane
8
8
  class DateVersionCalculator < AbstractVersionCalculator
9
9
  # Calculate the next date-based release version.
10
10
  #
11
- # If the current month is December, the method prompts the user to determine if the next
12
- # release will be the first release of the next year. If so, it increments the major version
13
- # and sets the minor version to 1, resetting the patch and build number components to zero.
14
- # Otherwise, it calculates the next minor version.
11
+ # When increment_to_next_year is true, increments the major version (representing the year) and resets all other
12
+ # components (minor to 1, patch and build number to 0). Otherwise, calculates the
13
+ # next minor version using the parent class implementation.
15
14
  #
16
15
  # @param [AppVersion] version The version to calculate the next date-based release version for.
16
+ # @param [Boolean] increment_to_next_year Whether to increment the version to the next year. Defaults to false.
17
17
  #
18
18
  # @return [AppVersion] The next date-based release version.
19
19
  #
20
- def next_release_version(version:)
21
- new_version = version.dup
22
- first_release_of_year = FastlaneCore::UI.confirm('Is this release the first release of next year?') if Time.now.month == 12
23
- if first_release_of_year
20
+ def next_release_version(version:, increment_to_next_year: false)
21
+ if increment_to_next_year
22
+ new_version = version.dup
24
23
  new_version.major += 1
25
24
  new_version.minor = 1
26
25
  new_version.patch = 0
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: 12.3.3
4
+ version: 12.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-11-21 00:00:00.000000000 Z
11
+ date: 2024-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -423,6 +423,7 @@ files:
423
423
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_between_tags.rb
424
424
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb
425
425
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_update_metadata_source.rb
426
+ - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/openai_ask_action.rb
426
427
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/promo_screenshots_action.rb
427
428
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb
428
429
  - lib/fastlane/plugin/wpmreleasetoolkit/actions/common/publish_github_release_action.rb