-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathrepo.rb
More file actions
111 lines (87 loc) · 3.47 KB
/
repo.rb
File metadata and controls
111 lines (87 loc) · 3.47 KB
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
# frozen_string_literal: true
require 'forwardable'
module Travis
module Scheduler
module Serialize
class Worker
class Repo < Struct.new(:repo, :config)
extend Forwardable
def_delegators :repo, :id, :github_id, :slug,
:last_build_id, :last_build_number, :last_build_started_at,
:last_build_finished_at, :last_build_duration, :last_build_state,
:default_branch, :description, :key, :settings, :private?,
:managed_by_app?, :installation, :vcs_id, :vcs_type, :url, :vcs_source_host, :server_type
def vm_type
Travis::Features.active?(:premium_vms, repo) ? :premium : :default
end
def timeouts
{ hard_limit: hard_limit_timeout, log_silence: timeout(:log_silence) }
end
def api_url
"#{config[:github][:api_url]}/repos/#{slug}"
end
def source_url
return repo.vcs_source_host if travis_vcs_proxy?
return repo.clone_url if repo.vcs_type == 'AssemblaRepository' && repo.server_type == 'perforce'
return source_git_url if force_private? && !Travis.config.prefer_https
return source_http_url if Travis.config.prefer_https || managed_by_app?
repo.private? || force_private? ? source_git_url : source_http_url
end
def source_git_url(repo_slug = nil)
"git@#{source_host}:#{repo_slug || slug}.git"
end
def source_http_url(repo_slug = nil)
"https://#{source_host}/#{repo_slug || slug}.git"
end
def installation_id
repo.installation&.github_id if repo.managed_by_app? && (repo.private || force_private?)
end
def keep_netrc?
repo.owner&.keep_netrc?
end
def github?
vcs_type == 'GithubRepository'
end
def travis_vcs_proxy?
vcs_type == 'TravisproxyRepository'
end
def owner_type
repo.owner_type
end
def owner_id
repo.owner_id
end
private
# If the repo does not have a custom timeout, look to the repo's
# owner for a default value, which might change depending on their
# current paid/unpaid status.
#
def hard_limit_timeout
timeout(:hard_limit) || repo.owner.default_worker_timeout
end
def timeout(type)
timeout = repo.settings.send(:"timeout_#{type}")
if timeout == nil
config = Travis.config.settings&.timeouts&.defaults
timeout = config[type] if config
end
return unless timeout
timeout = Integer(timeout)
timeout * 60 # worker handles timeouts in seconds
end
def force_private?
return repo.vcs_source_host != source_host if repo.vcs_source_host
github? && source_host != 'github.com'
end
def source_host
return URI(URI::Parser.new.escape(repo.vcs_source_host))&.host if travis_vcs_proxy?
repo.vcs_source_host || config[:github][:source_host] || 'github.com'
rescue Exception => e
puts "source host fail: #{e.message}"
repo.vcs_source_host || config[:github][:source_host] || 'github.com'
end
end
end
end
end
end