danger-android_permissions_checker 0.0.2 → 0.0.3

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: 26d593c45170d3f8e0d46bde541d8cefc81e5596c026cd58d6c1cf0c9254f930
4
- data.tar.gz: a9f90f3673ba04bb47e51d3fdff462991fc0b375571520141ba4108764f8856a
3
+ metadata.gz: d3dfd424ff01cc47bc35d2a029331868bb399b8bd81a2987efcfc7022517bf63
4
+ data.tar.gz: 11b46f55ba9ed75a03d06bce4e9044e03c30d458744158246e00d1611ba3a88d
5
5
  SHA512:
6
- metadata.gz: 5803cd6d6f55c62f8767d8cf08e1ccc89f3344bce3b4228dd32b8e36bc8f34f923b5982a300a45252b68aaed156d19c49e42cd96adbb01a850a805d8b348a410
7
- data.tar.gz: ef06d442a6631b0f73646e14874f4ad18b4743aa5df45aeb66ea27f210aeab56e8f3efb694b170c083804cc78ea5522c474b6e945488f73a08286e4e26881fe7
6
+ metadata.gz: 33bdceb9b0d80317370b3d0f29f623a44c53575a46396141128808d4bc73630ad4da698e38e4aff4541ab7eee0f5ecaf5aa57e0da310643f2c09bf67dc5d7b9b
7
+ data.tar.gz: dda3f3d49fab08272cc73ef8ffd730be2aa05c59864e54c81276ff1b43d6957afbdd6def52983100ed230d2adfae83c333a57d413107d61a68921774ca3a72f5
@@ -0,0 +1,10 @@
1
+ # CHANGELOG
2
+
3
+ ## v0.0.3
4
+
5
+ - [Allow to specify report method](https://github.com/mataku/danger-android_permissions_checker/pull/2) by [@mathroule](https://github.com/mathroule)
6
+ - [Use latest bundler](https://github.com/mataku/danger-android_permissions_checker/pull/3)
7
+
8
+ ## v0.0.2
9
+
10
+ - [Notify to prefer to update list if permissions changed](https://github.com/mataku/danger-android_permissions_checker/pull/1)
data/README.md CHANGED
@@ -8,7 +8,7 @@ A [Danger](https://danger.systems/ruby) plugin to check diff of android apk perm
8
8
 
9
9
  ## How to check
10
10
 
11
- Check permissions between current permissions and apk generated on CI service. if changed, show permissions which added or deleted.
11
+ Check permissions between current permissions and apk generated on CI service. If changed, show permissions which added or deleted.
12
12
 
13
13
  ## Usage
14
14
 
@@ -18,7 +18,7 @@ Create current permission list file of your apk using aapt, like this.
18
18
  $ aapt d permissions /path/to/apk > permissions.txt
19
19
  ```
20
20
 
21
- Add this to Dangerfile. Specify apk generated by CI service and permission list file generated by above command.
21
+ Add this to Dangerfile. Specify APK generated by CI service and permission list file generated by above command.
22
22
 
23
23
  ```
24
24
  android_permissions_checker.check(
@@ -27,10 +27,22 @@ android_permissions_checker.check(
27
27
  )
28
28
  ```
29
29
 
30
+ To use specific report method (default is warn). Available options are: message, warn, fail.
31
+ ```
32
+ android_permissions_checker.report_method = 'fail'
33
+ android_permissions_checker.check(
34
+ apk: '/path/to/generated_apk_by_CI',
35
+ permission_list_file: /path/to/permissions.txt
36
+ )
37
+ ```
38
+
30
39
  ## NOTE
31
40
 
32
41
  This gem uses `aapt` command to parse permissions of generated apk, so you need to add /path/to/aapt (Android Build-tools) to $PATH on your CI service.
33
42
 
43
+ ## ChangeLog
44
+
45
+ See [ChangeLog.md](https://github.com/mataku/danger-android_permissions_checker/blob/master/ChangeLog.md).
34
46
 
35
47
  ## Development
36
48
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
22
22
 
23
23
  # General ruby development
24
- spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'bundler', '>= 1.3'
25
25
  spec.add_development_dependency 'rake', '~> 10.0'
26
26
 
27
27
  # Testing support
@@ -1,3 +1,3 @@
1
1
  module AndroidPermissionsChecker
2
- VERSION = "0.0.2".freeze
2
+ VERSION = "0.0.3".freeze
3
3
  end
@@ -1,8 +1,39 @@
1
1
  module Danger
2
+ # Check permissions between current permissions and APK generated on CI service.
3
+ # If changed, show permissions which added or deleted.
4
+ #
5
+ # @example Running Android permissions checker with its basic configuration
6
+ #
7
+ # android_permissions_checker.check(
8
+ # apk: '/path/to/generated_apk_by_CI',
9
+ # permission_list_file: /path/to/permissions.txt
10
+ # )
11
+ #
12
+ # @example Running Android permissions checker with specific report method
13
+ #
14
+ # android_permissions_checker.report_method = 'fail'
15
+ # android_permissions_checker.check(
16
+ # apk: '/path/to/generated_apk_by_CI',
17
+ # permission_list_file: /path/to/permissions.txt
18
+ # )
19
+ #
20
+ # @see mataku/danger-android_permissions_checker
21
+ # @tags android, permissions, apk
22
+
2
23
  class DangerAndroidPermissionsChecker < Plugin
24
+ REPORT_METHODS = %i(message warn fail).freeze
25
+
26
+ # *Optional*
27
+ # Set report method
28
+ #
29
+ # @return [String, Symbol] error by default
30
+ attr_accessor :report_method
31
+
32
+ # Calls permissions check.
33
+ # @return [void]
3
34
  def check(apk: nil, permission_list_file: nil)
4
35
  if apk.nil? || !File.exist?(apk)
5
- raise "Can\'t find apk: #{apk}"
36
+ raise "Can't find apk: #{apk}"
6
37
  end
7
38
 
8
39
  if permission_list_file.nil? || !File.exist?(permission_list_file)
@@ -10,7 +41,12 @@ module Danger
10
41
  end
11
42
 
12
43
  unless system 'which aapt > /dev/null 2>&1'
13
- raise 'Can\'t find required command: aapt. Set PATH to Android Build-tools.'
44
+ raise "Can't find required command: aapt. Set PATH to Android Build-tools."
45
+ end
46
+
47
+ @report_method = (report_method || :warn).to_sym
48
+ unless REPORT_METHODS.include?(report_method)
49
+ raise "Unknown report method: #{report_method}"
14
50
  end
15
51
 
16
52
  generated_permissions = `aapt d permissions #{apk}`.split("\n")
@@ -38,7 +74,7 @@ module Danger
38
74
 
39
75
  unless message.empty?
40
76
  markdown(message)
41
- warn("APK permissions changed, see below. Should update `#{permission_list_file}` if it is intended change.")
77
+ send(report_method, "APK permissions changed, see below. Should update `#{permission_list_file}` if it is intended change.")
42
78
  end
43
79
  end
44
80
  end
@@ -52,7 +52,6 @@ module Danger
52
52
  expect(dangerfile.status_report[:warnings][0]).to eq("APK permissions changed, see below. Should update `#{current_permission_file}` if it is intended change.")
53
53
  expect(dangerfile.status_report[:markdowns][0].message).not_to include('Deleted')
54
54
  expect(dangerfile.status_report[:markdowns][0].message).to include('Added')
55
-
56
55
  end
57
56
  end
58
57
 
@@ -83,6 +82,68 @@ module Danger
83
82
  expect(dangerfile.status_report[:markdowns][0].message).to include('Added')
84
83
  end
85
84
  end
85
+
86
+ context 'Report method set to fail' do
87
+ let(:generated_permissions) do
88
+ "package: com.mataku.scrobscrob.dev\nuses-permission: name='android.permission.INTERNET'\nuses-permission: name='com.mataku.INTERNET'\n"
89
+ end
90
+
91
+ it 'should report errors' do
92
+ plugin.report_method = 'fail'
93
+ plugin.check(apk: apk, permission_list_file: current_permission_file)
94
+ expect(dangerfile.status_report[:errors].length).to eq(1)
95
+ expect(dangerfile.status_report[:errors][0]).to eq("APK permissions changed, see below. Should update `#{current_permission_file}` if it is intended change.")
96
+ expect(dangerfile.status_report[:messages].length).to eq(0)
97
+ expect(dangerfile.status_report[:warnings].length).to eq(0)
98
+ expect(dangerfile.status_report[:markdowns][0].message).not_to include('Deleted')
99
+ expect(dangerfile.status_report[:markdowns][0].message).to include('Added')
100
+ end
101
+ end
102
+
103
+ context 'Report method set to message' do
104
+ let(:generated_permissions) do
105
+ "package: com.mataku.scrobscrob.dev\nuses-permission: name='android.permission.INTERNET'\nuses-permission: name='com.mataku.INTERNET'\n"
106
+ end
107
+
108
+ it 'should report messages' do
109
+ plugin.report_method = 'message'
110
+ plugin.check(apk: apk, permission_list_file: current_permission_file)
111
+ expect(dangerfile.status_report[:errors].length).to eq(0)
112
+ expect(dangerfile.status_report[:messages].length).to eq(1)
113
+ expect(dangerfile.status_report[:messages][0]).to eq("APK permissions changed, see below. Should update `#{current_permission_file}` if it is intended change.")
114
+ expect(dangerfile.status_report[:warnings].length).to eq(0)
115
+ expect(dangerfile.status_report[:markdowns][0].message).not_to include('Deleted')
116
+ expect(dangerfile.status_report[:markdowns][0].message).to include('Added')
117
+ end
118
+ end
119
+
120
+ context 'Report method set to warn' do
121
+ let(:generated_permissions) do
122
+ "package: com.mataku.scrobscrob.dev\nuses-permission: name='android.permission.INTERNET'\nuses-permission: name='com.mataku.INTERNET'\n"
123
+ end
124
+
125
+ it 'should report warnings' do
126
+ plugin.report_method = 'warn'
127
+ plugin.check(apk: apk, permission_list_file: current_permission_file)
128
+ expect(dangerfile.status_report[:errors].length).to eq(0)
129
+ expect(dangerfile.status_report[:messages].length).to eq(0)
130
+ expect(dangerfile.status_report[:warnings].length).to eq(1)
131
+ expect(dangerfile.status_report[:warnings][0]).to eq("APK permissions changed, see below. Should update `#{current_permission_file}` if it is intended change.")
132
+ expect(dangerfile.status_report[:markdowns][0].message).not_to include('Deleted')
133
+ expect(dangerfile.status_report[:markdowns][0].message).to include('Added')
134
+ end
135
+ end
136
+
137
+ context 'Report method set to unknown' do
138
+ let(:generated_permissions) do
139
+ "package: com.mataku.scrobscrob.dev\nuses-permission: name='android.permission.INTERNET'\nuses-permission: name='com.mataku.INTERNET'\n"
140
+ end
141
+
142
+ it 'should fail' do
143
+ plugin.report_method = 'unknown'
144
+ expect { plugin.check(apk: apk, permission_list_file: current_permission_file) }.to raise_error("Unknown report method: unknown")
145
+ end
146
+ end
86
147
  end
87
148
  end
88
149
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-android_permissions_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - mataku
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-26 00:00:00.000000000 Z
11
+ date: 2020-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
@@ -90,6 +90,7 @@ files:
90
90
  - ".gitignore"
91
91
  - ".rubocop.yml"
92
92
  - ".travis.yml"
93
+ - ChangeLog.md
93
94
  - Gemfile
94
95
  - Guardfile
95
96
  - LICENSE.txt
@@ -121,8 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  - !ruby/object:Gem::Version
122
123
  version: '0'
123
124
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 2.7.7
125
+ rubygems_version: 3.0.6
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: A Danger plugin to check diff of android apk permissions.