forked from travis-ci/travis-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_log.rb
More file actions
45 lines (35 loc) · 971 Bytes
/
Copy pathremove_log.rb
File metadata and controls
45 lines (35 loc) · 971 Bytes
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
module Travis
module Services
class RemoveLog < Base
register :remove_log
FORMAT = "Log removed by %s at %s"
def run
return nil unless job && can_remove?
message = FORMAT % [current_user.name, DateTime.now.iso8601]
if params[:reason]
message << "\n\n#{params[:reason]}"
end
log.content = message
log.archive_verified = false
log.archived_at = nil
log.save! && log
end
def log
@log ||= job.log
end
def can_remove?
authorized? && job.finished?
end
def authorized?
current_user.permission?(:push, repository_id: job.repository.id)
end
private
def job
@job ||= scope(:job).find_by_id(params[:id])
rescue ActiveRecord::SubclassNotFound => e
Travis.logger.warn "[services:remove-log] #{e.message}"
raise ActiveRecord::RecordNotFound
end
end
end
end