1
2
3
4
5
6
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
98
99
100
101
102
|
# frozen_string_literal: true
module Integrations
class GooglePlay < Integration
PACKAGE_NAME_REGEX = /\A[a-zA-Z0-9]+(\.[a-zA-Z0-9]+){2,20}\z/
SECTION_TYPE_GOOGLE_PLAY = 'google_play'
with_options if: :activated? do
validates :service_account_key, presence: true, json_schema: {
filename: "google_service_account_key", parse_json: true
}
validates :service_account_key_file_name, presence: true
validates :package_name, presence: true, format: { with: PACKAGE_NAME_REGEX }
end
field :package_name,
section: SECTION_TYPE_CONNECTION,
placeholder: 'com.example.myapp',
required: true
field :service_account_key_file_name,
section: SECTION_TYPE_CONNECTION,
required: true,
is_secret: false
field :service_account_key, api_only: true, is_secret: false
def title
s_('GooglePlay|Google Play')
end
def description
s_('GooglePlay|Use GitLab to build and release an app in Google Play.')
end
def help
variable_list = [
'<code>SUPPLY_PACKAGE_NAME</code>',
'<code>SUPPLY_JSON_KEY_DATA</code>'
]
# rubocop:disable Layout/LineLength
texts = [
s_("Use the Google Play integration to connect to Google Play with fastlane in CI/CD pipelines."),
s_("After you enable the integration, the following protected variable is created for CI/CD use:"),
variable_list.join('<br>'),
s_(format("To generate a Google Play service account key and use this integration, see the <a href='%{url}' target='_blank'>integration documentation</a>.", url: Rails.application.routes.url_helpers.help_page_url('user/project/integrations/google_play'))).html_safe
]
# rubocop:enable Layout/LineLength
texts.join('<br><br>'.html_safe)
end
def self.to_param
'google_play'
end
def self.supported_events
[]
end
def sections
[
{
type: SECTION_TYPE_GOOGLE_PLAY,
title: s_('Integrations|Integration details'),
description: help
}
]
end
def test(*_args)
client.list_reviews(package_name)
{ success: true }
rescue Google::Apis::ClientError => error
{ success: false, message: error }
end
def ci_variables
return [] unless activated?
[
{ key: 'SUPPLY_JSON_KEY_DATA', value: service_account_key, masked: true, public: false },
{ key: 'SUPPLY_PACKAGE_NAME', value: package_name, masked: false, public: false }
]
end
private
def client
service = Google::Apis::AndroidpublisherV3::AndroidPublisherService.new # rubocop: disable CodeReuse/ServiceClass
service.authorization = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: StringIO.new(service_account_key),
scope: [Google::Apis::AndroidpublisherV3::AUTH_ANDROIDPUBLISHER]
)
service
end
end
end
|