fastlane-plugin-nordalp_app_publish 0.1.0 → 0.2.1

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: ddf14fca40ddbb1dc0b03ca5c21a7e08f989c1aee67f37600f2f8b65d6dff760
4
- data.tar.gz: ac0f39c222e700f99ab50b01337447661234b695cb7a835923ba75f73356f6e1
3
+ metadata.gz: 5ae3b926dfb8c35cb52069f251079ddd581cee3ebc4cd8ea1b63e618686ddc13
4
+ data.tar.gz: 92ef57ca05bf5be16865d1ce1a92f8b9ce44274455edc4fbde6da3aeb733ed4a
5
5
  SHA512:
6
- metadata.gz: 745815571ea1d2287dffa26e982aedf9d8f86cca3401a1547f4757bbc0c73aaef18cd8b2f601fd4868a9634808f7dacab99bb20a1c2599b533da2de46efcda7e
7
- data.tar.gz: a6bff9610d89fcd6de21b759829f7192719ce3aa30255091e0aa12a787b9788bf105ac9ffe3158b244e9bb82b4fafe1f7c2e6fb7bc58b9e376f27335ea9db04f
6
+ metadata.gz: 221bb820fd68f26244389321694e8b713d5b90872fe80ad513138d6c8a1e3390a2e4c0ca6ad726136004b4ff80bb97e50914fce65e25e243025394b7742b7d15
7
+ data.tar.gz: 54a659e9b490fdd604a01ff35e1d3717840ecd384b82c1f5889baf1469bf26d64428665128440c0653acc0bb1fea253f4c5d4e365bbe59796250fe87c9bf90bf
@@ -1,83 +1,95 @@
1
- require 'fastlane/action'
2
- require_relative '../helper/nordalp_app_publish_helper'
3
- require 'redcarpet'
4
-
5
- module Fastlane
6
- module Actions
7
- class NordalpAppPublishAction < Action
8
- def self.run(params)
9
- UI.message("Upload to #{params[:url]} using #{params[:token]}")
10
- Helper::NordalpAppPublishHelper.show_message()
11
- changelog = Helper::NordalpAppPublishHelper.read_first_changelog_entry("CHANGELOG.md")
12
- UI.message("Changelog for #{changelog[:version]} @ #{changelog[:date]}")
13
-
14
- apks = lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS]
15
- jsons = lane_context[SharedValues::GRADLE_ALL_OUTPUT_JSON_OUTPUT_PATHS]
16
- links = lane_context[:S3_ALL_FILE_URL]
17
- if (apks.length == jsons.length && apks.length == links.length)
18
- markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true)
19
- UI.message("Sending #{links.length} version(s) to CMS")
20
- jsons.each_with_index do |element,index|
21
- json_string = File.read(element)
22
- data_hash = JSON.parse(json_string)
23
- application_id = data_hash["applicationId"]
24
- version_code = data_hash["elements"][0]["versionCode"]
25
- version_name = data_hash["elements"][0]["versionName"]
26
- UI.message("Use #{links[index]} for #{application_id}")
27
- result = Helper::NordalpAppPublishHelper.post_app(params[:url], params[:token], {
28
- changelog: {
29
- version: changelog[:version],
30
- date: changelog[:date],
31
- text: markdown.render(changelog[:text]).gsub("<h3>", "<h5>").gsub("</h3>", "</h5>")
32
- },
33
- application_id: application_id,
34
- link: links[index],
35
- version_code: version_code,
36
- version_name: version_name
37
- })
38
- UI.message("Result #{result}")
39
- end
40
- else
41
- UI.message("Number of items not equal in 3 arrays!")
42
- end
43
- end
44
-
45
- def self.description
46
- "Publish an app update to Nordalp website"
47
- end
48
-
49
- def self.authors
50
- ["ov3rk1ll"]
51
- end
52
-
53
- def self.return_value
54
- # Optional
55
- end
56
-
57
- def self.details
58
- # Optional:
59
- ""
60
- end
61
-
62
- def self.available_options
63
- [
64
- FastlaneCore::ConfigItem.new(key: :token,
65
- env_name: "NORDALP_APP_PUBLISH_TOKEN",
66
- description: "Access token for CMS",
67
- optional: false,
68
- type: String),
69
- FastlaneCore::ConfigItem.new(key: :url,
70
- env_name: "NORDALP_APP_PUBLISH_URL",
71
- description: "URL for CMS flow",
72
- optional: true,
73
- default_value: "https://cms.nordalp.de/flows/trigger/d6c99c78-63cf-4701-a297-aeee079ad8da",
74
- type: String)
75
- ]
76
- end
77
-
78
- def self.is_supported?(platform)
79
- [:android].include?(platform)
80
- end
81
- end
82
- end
83
- end
1
+ require 'fastlane/action'
2
+ require 'fastlane_core'
3
+ require 'redcarpet'
4
+
5
+ require_relative '../helper/nordalp_app_publish_helper'
6
+
7
+ module Fastlane
8
+ module Actions
9
+ # Fastlane Plugin action class
10
+ class NordalpAppPublishAction < Action
11
+ # rubocop:disable Require/MissingRequireStatement
12
+ def self.run(params)
13
+ UI.message("Upload to #{params[:url]} using #{params[:token]}")
14
+ changelog = Helper::NordalpAppPublishHelper.read_first_changelog_entry('CHANGELOG.md')
15
+ UI.message("Changelog for #{changelog[:version]} @ #{changelog[:date]}")
16
+
17
+ jsons = lane_context[SharedValues::GRADLE_ALL_OUTPUT_JSON_OUTPUT_PATHS]
18
+ links = lane_context[:S3_ALL_FILE_URL]
19
+ if jsons.length == links.length
20
+ # Markdown renderer to convert changelog to HTML
21
+ markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true)
22
+
23
+ jsons.each_with_index do |element, index|
24
+ # Read app data from json-output file
25
+ json_string = File.read(element)
26
+ data_hash = JSON.parse(json_string)
27
+ application_id = data_hash['applicationId']
28
+ version_code = data_hash['elements'][0]['versionCode']
29
+ version_name = data_hash['elements'][0]['versionName']
30
+
31
+ # Send data to CMS
32
+ # The CMS will discard any submissions with an application_id that does not yet have a record
33
+ post_data = {
34
+ changelog: {
35
+ version: changelog[:version],
36
+ date: changelog[:date],
37
+ # The Changelog expects the
38
+ text: markdown
39
+ .render(changelog[:text])
40
+ .gsub('<h3>', '<h5>')
41
+ .gsub('</h3>', '</h5>')
42
+ },
43
+ application_id: application_id,
44
+ link: links[index],
45
+ version_code: version_code,
46
+ version_name: version_name
47
+ }
48
+ result = Helper::NordalpAppPublishHelper.post_app(params[:url], params[:token], post_data)
49
+ UI.message("Sent #{application_id} with result #{result}")
50
+ end
51
+ else
52
+ UI.message('Number of items not equal in json and link arrays!')
53
+ end
54
+ end
55
+ # rubocop:enable Require/MissingRequireStatement
56
+
57
+ def self.description
58
+ 'Publish an app update to Nordalp website'
59
+ end
60
+
61
+ def self.authors
62
+ ['ov3rk1ll']
63
+ end
64
+
65
+ def self.return_value
66
+ # Optional
67
+ end
68
+
69
+ def self.details
70
+ # Optional:
71
+ ''
72
+ end
73
+
74
+ def self.available_options
75
+ [
76
+ FastlaneCore::ConfigItem.new(key: :token,
77
+ env_name: 'NORDALP_APP_PUBLISH_TOKEN',
78
+ description: 'Access token for CMS',
79
+ optional: false,
80
+ type: String),
81
+ FastlaneCore::ConfigItem.new(key: :url,
82
+ env_name: 'NORDALP_APP_PUBLISH_URL',
83
+ description: 'URL for CMS flow',
84
+ optional: true,
85
+ default_value: 'https://cms.nordalp.de/flows/trigger/d6c99c78-63cf-4701-a297-aeee079ad8da',
86
+ type: String)
87
+ ]
88
+ end
89
+
90
+ def self.is_supported?(platform)
91
+ [:android].include?(platform)
92
+ end
93
+ end
94
+ end
95
+ end
@@ -1,70 +1,60 @@
1
- require 'fastlane_core/ui/ui'
2
- require 'httparty'
3
-
4
- module Fastlane
5
- UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
6
-
7
- module Helper
8
- class NordalpAppPublishHelper
9
- # class methods that you define here become available in your action
10
- # as `Helper::NordalpAppPublishHelper.your_method`
11
- #
12
- def self.show_message
13
- UI.message("Hello from the nordalp_app_publish plugin helper!")
14
- end
15
-
16
- def self.read_first_changelog_entry(filename)
17
- unless File.exist?(filename)
18
- return { error: "File not found: #{filename}" }
19
- end
20
-
21
- # Read the entire file content
22
- content = File.read(filename)
23
-
24
- # Regular expression to match the first H2 version entry
25
- version_regex = /^##\s+(\[([^\]]+)\]\(([^)]+)\)|[^(\r?\n]+)\s*\(([^)]+)\)\s*\r?\n(.*?)(?=\r?\n## |\z)/im
26
- match = content.match(version_regex)
27
-
28
- if match
29
- # The version name is captured in Group 2 if it's a link, or Group 1 if it's plain text.
30
- version_name = match[2] || (match[1] ? match[1].strip : nil)
31
- date = match[4]
32
- text = match[5].strip
33
-
34
- return {
35
- version: version_name,
36
- date: date,
37
- text: text
38
- }
39
- else
40
- return { error: "No version entries found matching the expected format (## [version](link) (date))" }
41
- end
42
- end
43
-
44
- def self.post_app(url_string, token_string, data_hash)
45
- response = HTTParty.post(
46
- url_string,
47
- {
48
- # HTTParty automatically converts the body (a Hash) to JSON
49
- # and sets the Content-Type header to application/json
50
- body: data_hash.to_json,
51
- headers: {
52
- 'Authenticate' => token_string,
53
- 'Content-Type' => 'application/json',
54
- 'Accept' => 'application/json'
55
- }
56
- }
57
- )
58
-
59
- # HTTParty can optionally parse the response body if it's JSON
60
- return {
61
- code: response.code,
62
- body: response.parsed_response # Accesses the parsed JSON response body
63
- }
64
-
65
- rescue StandardError => e
66
- return { error: "An error occurred: #{e.message}" }
67
- end
68
- end
69
- end
70
- end
1
+ require 'fastlane_core/ui/ui'
2
+ require 'httparty'
3
+
4
+ module Fastlane
5
+ UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
6
+
7
+ module Helper
8
+ class NordalpAppPublishHelper
9
+ def self.read_first_changelog_entry(filename)
10
+ return { error: "File not found: #{filename}" } unless File.exist?(filename)
11
+
12
+ # Read the entire file content
13
+ content = File.read(filename)
14
+
15
+ # Regular expression to match the first H2 version entry
16
+ version_regex = /^##\s+(\[([^\]]+)\]\(([^)]+)\)|[^(\r?\n]+)\s*\(([^)]+)\)\s*\r?\n(.*?)(?=\r?\n## |\z)/im
17
+ match = content.match(version_regex)
18
+
19
+ unless match
20
+ return { error: 'No version entries found matching the expected format (## [version](link) (date))' }
21
+ end
22
+
23
+ # The version name is captured in Group 2 if it's a link, or Group 1 if it's plain text.
24
+ version_name = match[2] || match[1]&.strip
25
+ date = match[4]
26
+ text = match[5].strip
27
+
28
+ {
29
+ version: version_name,
30
+ date: date,
31
+ text: text
32
+ }
33
+ end
34
+
35
+ def self.post_app(url_string, token_string, data_hash)
36
+ response = HTTParty.post(
37
+ url_string,
38
+ {
39
+ # HTTParty automatically converts the body (a Hash) to JSON
40
+ # and sets the Content-Type header to application/json
41
+ body: data_hash.to_json,
42
+ headers: {
43
+ 'Authorization' => "Bearer #{token_string}",
44
+ 'Content-Type' => 'application/json',
45
+ 'Accept' => 'application/json'
46
+ }
47
+ }
48
+ )
49
+
50
+ # HTTParty can optionally parse the response body if it's JSON
51
+ {
52
+ code: response.code,
53
+ body: response.parsed_response # Accesses the parsed JSON response body
54
+ }
55
+ rescue StandardError => e
56
+ { error: "An error occurred: #{e.message}" }
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,5 +1,5 @@
1
- module Fastlane
2
- module NordalpAppPublish
3
- VERSION = "0.1.0"
4
- end
5
- end
1
+ module Fastlane
2
+ module NordalpAppPublish
3
+ VERSION = '0.2.1'
4
+ end
5
+ end
@@ -1,16 +1,16 @@
1
- require 'fastlane/plugin/nordalp_app_publish/version'
2
-
3
- module Fastlane
4
- module NordalpAppPublish
5
- # Return all .rb files inside the "actions" and "helper" directory
6
- def self.all_classes
7
- Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
- end
9
- end
10
- end
11
-
12
- # By default we want to import all available actions and helpers
13
- # A plugin can contain any number of actions and plugins
14
- Fastlane::NordalpAppPublish.all_classes.each do |current|
15
- require current
16
- end
1
+ require 'fastlane/plugin/nordalp_app_publish/version'
2
+
3
+ module Fastlane
4
+ module NordalpAppPublish
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::NordalpAppPublish.all_classes.each do |current|
15
+ require current
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-nordalp_app_publish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ov3rk1ll