Sha256: 8bc95038452bb4f5f6b9651683bb1f2dad855149671abbdd9966a466b389f7b9

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'fileutils'

module Danger
  class DangerAndroidPermissionsChecker < Plugin
    def check(apk: nil, permission_list_file: nil)
      if apk.nil? || !File.exist?(apk)
        raise "Can\'t find apk: #{apk}"
      end

      if permission_list_file.nil? || !File.exist?(permission_list_file)
        raise "Can't find permission list file: #{permission_list_file}\n"
      end

      unless system 'which aapt > /dev/null 2>&1'
        raise 'Can\'t find required command: aapt. Set PATH to Android Build-tools.'
      end

      generated_permissions = `aapt d permissions #{apk}`.split("\n")
      current_permissions = File.open(permission_list_file).readlines.map(&:chomp)

      deleted = current_permissions - generated_permissions
      added = generated_permissions - current_permissions
      message = ""
      
      if deleted.length > 0
        message += "### Deleted permissions\n"
        deleted.each do |v|
          message += "- #{v}\n"
        end
        message += "\n"
      end

      if added.length > 0
        message += "### Added Permissions\n"

        added.each do |v|
          message += "- #{v}\n"
        end
      end

      unless message.empty?
        markdown(message)
        warn('APK permissions changed, see below.')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danger-android_permissions_checker-0.0.1 lib/android_permissions_checker/plugin.rb