fastlane-plugin-wpmreleasetoolkit 12.3.4 → 12.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b59d8ce8652d5491809fc8a80bf3e08b35a3d65f244eb9f7f8faccb212ba9c81
4
- data.tar.gz: aea9e1d13eb564f07088120c9f763aa2042bc34c0672ca938670b0ee1e698209
3
+ metadata.gz: d4cdbaa88428a89afebe8e5ccddc35bc4ebce263ae07caa40598fc54bec24fca
4
+ data.tar.gz: a16e7052eddb43d6f98aab25c51ad2628d702b54842f726ee4c1fde45003eb02
5
5
  SHA512:
6
- metadata.gz: c3dca2f486e3ff752f89b8b27a36d5f2287dc9c529eb46efe10ca6c6168ebfa595489921ae4a550c80e6b1f10f616401ba53e8e1ce102210f478c79f16bbde6a
7
- data.tar.gz: 3dc7792faa4d46efabde9c7075f198dae635b15be7a9cc9a157610c23fec524ed3a5ebb28e6e3377cb0e5313a313579debcc1ee41abb10308eaafcb063b0c427
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.4'
5
+ VERSION = '12.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: 12.3.4
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-12-02 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