Commit 5413080f authored by Stan Hu's avatar Stan Hu

Add Rubocop linting

parent c0c0622f
......@@ -4,18 +4,39 @@ default:
- gitlab-org
stages:
- test
- deploy
.ruby-cache:
cache:
paths:
- vendor
.bundle-install:
extends: .ruby-cache
before_script:
- gem install bundler
- (if [ -d vendor ]; then echo "Vendor dir exists"; else apk add build-base; fi);
- bundle install --jobs 4 --path vendor/bundle
rubocop:
extends: .bundle-install
stage: test
script:
- gem install bundler
- bundle exec rubocop
cache:
paths:
- vendor
sync:
extends: .bundle-install
stage: deploy
only:
- schedules
- master
script:
- gem install bundler
- (if [ -d vendor ]; then echo "Vendor dir exists"; else apk add build-base; fi);
- apk add mediainfo
- bundle install --path vendor/bundle
- bundle exec ruby zoom-sync.rb
cache:
paths:
......
inherit_from: .rubocop_todo.yml
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-07-10 20:42:01 UTC using RuboCop version 0.87.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 3
# Configuration parameters: IgnoredMethods.
Metrics/AbcSize:
Max: 44
# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 31
# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 113
# Offense count: 1
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 10
# Offense count: 6
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
Metrics/MethodLength:
Max: 41
# Offense count: 1
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 11
# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Naming/FileName:
Exclude:
- 'zoom-sync.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Exclude:
- 'Gemfile'
- 'zoom-sync.rb'
......@@ -3,3 +3,7 @@ source 'https://rubygems.org'
gem 'google_drive', '= 3.0.3'
gem 'httparty', '= 0.17.0'
gem 'mediainfo', '= 1.3.3'
group :development, :test do
gem 'rubocop', '~> 0.87'
end
......@@ -3,6 +3,7 @@ GEM
specs:
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.1)
declarative (0.0.10)
declarative-option (0.1.0)
faraday (0.15.4)
......@@ -44,18 +45,37 @@ GEM
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
os (1.0.1)
parallel (1.19.2)
parser (2.7.1.4)
ast (~> 2.4.1)
public_suffix (3.1.1)
rainbow (3.0.0)
regexp_parser (1.7.1)
representable (3.0.4)
declarative (< 0.1.0)
declarative-option (< 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.2.4)
rubocop (0.87.1)
parallel (~> 1.10)
parser (>= 2.7.1.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml
rubocop-ast (>= 0.1.0, < 1.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.1.0)
parser (>= 2.7.0.1)
ruby-progressbar (1.10.1)
signet (0.11.0)
addressable (~> 2.3)
faraday (~> 0.9)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
uber (0.1.0)
unicode-display_width (1.7.0)
PLATFORMS
ruby
......@@ -64,6 +84,7 @@ DEPENDENCIES
google_drive (= 3.0.3)
httparty (= 0.17.0)
mediainfo (= 1.3.3)
rubocop (~> 0.87)
BUNDLED WITH
1.17.3
......@@ -20,7 +20,7 @@ require 'mediainfo'
class ZoomClient
include HTTParty
MAX_PAGE_SIZE = 300
RECORDINGS_URL = "https://api.zoom.us/v2/users/USER_ID/recordings".freeze
RECORDINGS_URL = 'https://api.zoom.us/v2/users/USER_ID/recordings'.freeze
USERS_URL = 'https://api.zoom.us/v2/users'.freeze
attr_reader :api_key, :api_secret
......@@ -59,7 +59,7 @@ class ZoomClient
end
def access_token
JWT.encode({ iss: api_key, exp: Time.now.to_i + 86400 }, api_secret, 'HS256', { typ: 'JWT' })
JWT.encode({ iss: api_key, exp: Time.now.to_i + 86_400 }, api_secret, 'HS256', { typ: 'JWT' })
end
private
......@@ -97,6 +97,7 @@ class ZoomClient
end
break if page_number >= total_pages
page_number += 1
end
end
......@@ -170,7 +171,7 @@ class GoogleDriveClient
# Google Drive treats anything < 50K as 0 bytes, so we
# have to assume it was uploaded if we got something back
return true if uploaded && file_size < 51200
return true if uploaded && file_size < 51_200
uploaded.size.to_i == file_size
end
......@@ -181,8 +182,8 @@ end
class ZoomSyncher
attr_reader :client, :gdrive_client
MAX_FILE_SIZE_BYTES = 2000000000 # 2 GB
REC_REGEX = /\[\s*REC\s*\]/i
MAX_FILE_SIZE_BYTES = 2_000_000_000 # 2 GB
REC_REGEX = /\[\s*REC\s*\]/i.freeze
def initialize
@client = ZoomClient.new(load_zoom_config)
......@@ -219,7 +220,7 @@ class ZoomSyncher
return
end
topic = item['topic'].gsub(REC_REGEX, "").strip
topic = item['topic'].gsub(REC_REGEX, '').strip
recording_files = item['recording_files']
return unless recording_files
......@@ -287,13 +288,8 @@ class ZoomSyncher
# Returns a config object that responds to client_id, etc.:
# https://www.rubydoc.info/gems/google_drive/2.1.1/GoogleDrive%2FSession.from_config
def load_gdrive_config
data =
if ENV['GOOGLE_DRIVE_SERVICE_ACCOUNT_KEY']
ENV['GOOGLE_DRIVE_SERVICE_ACCOUNT_KEY']
else
File.read('config.json')
end
ENV['GOOGLE_DRIVE_SERVICE_ACCOUNT_KEY'] || File.read('config.json')
StringIO.new(data)
end
......@@ -308,7 +304,7 @@ class ZoomSyncher
end
def download_video(url, filename, file_size)
STDERR.puts "Downloading #{filename}"
warn "Downloading #{filename}"
attempts = 0
loop do
......@@ -345,7 +341,6 @@ class ZoomSyncher
def sanitize_filename(filename)
filename.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
end
end
if $PROGRAM_NAME == __FILE__
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment