-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.rb
143 lines (103 loc) · 4.01 KB
/
config.rb
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
require 'redcarpet'
require 'jiralicious'
require 'wunderground'
require 'active_support/all'
require "lib/custom_helpers"
# Load local ENV vars, for development
require './env' if File.exists?('env.rb')
Jiralicious.configure do |config|
# Leave out username and password
config.username = ENV['JIRA_USERNAME']
config.password = ENV['JIRA_PASSWORD']
config.uri = ENV['JIRA_URL']
config.api_version = "latest"
config.auth_type = :basic
end
w_api = Wunderground.new(ENV['WUNDERGROUND_KEY'])
activate :directory_indexes
activate :automatic_image_sizes
activate :livereload
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
set :markdown_engine, :redcarpet
configure :build do
quarters = [[1,2,3], [4,5,6], [7,8,9], [10,11,12]]
quarter = quarters[(Time.now.month - 1) / 3]
quarter_start = Date.new(Date.today.year,quarter[0],1).at_beginning_of_month.strftime('%Y/%m/%d')
quarter_end = Date.new(Date.today.year,quarter[2],1).at_end_of_month.strftime('%Y/%m/%d')
company = load_json('data/company.json')
locations = company['locations']
employees_array = []
locations.each do |location|
location["employees"].each do |employee|
if employee["goal"] > 0
# Generate employee username
name = employee["name"].split(' ')
first_initial = name[0][0]
last_name = name[1]
username = (first_initial + last_name).downcase
puts "(#{Time.now}) Getting #{username.upcase}'s issues..."
# Get user's issues
r = Jiralicious.search("(owner = \"#{username}\") AND (status = 'Review' OR status = 'Stage' OR (status = 'Closed' AND resolutiondate >= \"#{quarter_start}\" AND resolutiondate <= \"#{quarter_end}\")) AND (issuetype != 'Bug')", :max_results=>'2500',:fields=>'customfield_10004,project,issuetype,issuekey,resolutiondate')
issues_array = []
r.issues.each do |issue|
resolution_date = issue["fields"]["resolutiondate"]
if resolution_date.nil?
resolution_date = Date.today().strftime('%Y/%m/%d')
end
issue_hash = {
:bricks => issue["fields"]["customfield_10004"],
:project => issue["fields"]["project"]["key"],
:issuetype => issue["fields"]["issuetype"]["name"],
:resolutiondate => resolution_date
}
issues_array << issue_hash
end
puts "(#{Time.now}) Finished!"
# Build employee hash
employee = {
:name => employee["name"],
:goal => employee["goal"],
:username => username,
:issues => issues_array
}
# Load employee into array
employees_array << employee
end
end
end
# Parse array to JSON
employees_json = employees_array.to_json
# Write JSON to data
File.open("./data/employees.json", 'w') do |file|
file.puts employees_json
end
# Initialize empty array
weather_array = []
# Loop through company locations
locations.each do |location|
location_name = location["location"]
location_weather = w_api.forecast_and_conditions_for("#{location_name}")
weather_array << location_weather
end
weather_json = weather_array.to_json
File.open("./data/weather.json", 'w') do |file|
file.puts weather_json
end
end
helpers CustomHelpers
activate :s3_sync do |s3_sync|
s3_sync.bucket = ENV['S3_BUCKET']
s3_sync.region = ENV['S3_REGION']
s3_sync.aws_access_key_id = ENV['S3_KEY']
s3_sync.aws_secret_access_key = ENV['S3_SECRET']
s3_sync.delete = true # We delete stray files by default.
s3_sync.after_build = false # We do not chain after the build step by default.
s3_sync.prefer_gzip = true
s3_sync.path_style = true
s3_sync.reduced_redundancy_storage = false
s3_sync.acl = 'public-read'
s3_sync.encryption = false
end
caching_policy 'text/html', max_age: 0, must_revalidate: true