-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathrequest.rb
57 lines (47 loc) · 1.82 KB
/
request.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
require 'active_record'
require 'travis/scheduler/record/organization'
require 'travis/scheduler/record/repository'
require 'travis/scheduler/record/user'
class Request < ActiveRecord::Base
belongs_to :commit
belongs_to :pull_request
belongs_to :repository
belongs_to :owner, polymorphic: true
serialize :payload
# This check has been put in place in order to address a security issue on
# GitHub's side. See https://blog.travis-ci.com/2016-07-07-security-advisory-encrypted-variables.
#
# The underlying issue has been fixed by GitHub in June 2016 (see
# https://github.com/travis-pro/team-teal/issues/1280#issuecomment-250129327),
# but we're keeping this check around for the time being, especially for
# Enterprise.
def same_repo_pull_request?
# When we're starting to archive payloads after N months we'll also disallow
# restarting builds older than N months. Once we do so we can also return
# false if Scheduler.config.enterprise is not true.
# It's not the same repo PR if repo names don't match
return false if head_repo_vcs_id != repository.vcs_id
# It may not be the same repo if head_ref or head_sha are missing
return false if head_ref.nil? or head_sha.nil?
# It may not be same repo PR if ref is a commit
return false if head_sha =~ /^#{Regexp.escape(head_ref)}/
true
rescue => e
Travis::Scheduler.logger.error "[request:#{id}] Couldn't determine whether pull request is from the same repository: #{e.message}"
false
end
def payload
fail "[deprectated] Reading request.payload."
end
private
def head_repo_vcs_id
return unless pull_request
repository.github? ? pull_request.head_repo_github_id.to_s : pull_request.head_repo_vcs_id
end
def head_ref
pull_request&.head_ref
end
def head_sha
head_commit
end
end