delete commitcommand, request approval, branches, and states

This commit is contained in:
Sven Fuchs 2016-06-19 15:45:55 +02:00
parent 04cd5bea24
commit fb0493a33c
9 changed files with 2 additions and 1011 deletions

View File

@ -1,270 +0,0 @@
describe Request::Approval do
include Travis::Testing::Stubs
let(:approval) { Request::Approval.new(request) }
before do
approval.stubs(:build_pull_requests?).returns(true)
approval.stubs(:build_pushes?).returns(true)
request.stubs(:creates_jobs?).returns(true)
end
describe 'config_accepted?' do
it 'approves the build when .travis.yml is missing, but builds with .travis.yml are allowed' do
request.config['.result'] = 'not_found'
approval.config_accepted?.should be true
end
it 'does not approve the build if .travis.yml is missing and builds without it are not allowed' do
request.repository.stubs(:builds_only_with_travis_yml?).returns(true)
request.config['.result'] = 'not_found'
approval.config_accepted?.should be false
approval.message.should == '.travis.yml is missing and builds without .travis.yml are disabled'
end
it 'approves the build when .travis.yml is present' do
request.config['.result'] = 'configured'
approval.config_accepted?.should be true
end
end
describe 'branch_accepted?' do
it 'does not accept a request that belongs to the github_pages branch' do
request.commit.stubs(:branch).returns('gh_pages')
approval.branch_accepted?.should be false
end
it 'accepts a request that belongs to the gh-pages branch if it\'s specified in branches:only' do
request.commit.stubs(:branch).returns('gh_pages')
request.config['branches'] = { 'only' => ['gh-pages'] }
approval.branch_accepted?.should be_truthy
end
it "doesn't fail when the branch configuration is an array" do
request.config['branches'] = [{ 'only' => ['gh-pages'] }]
approval.branch_accepted?.should be true
end
end
describe 'accepted?' do
it 'accepts a request that has a commit, belongs to a public repository, is not skipped and does not belong to the github_pages branch and it is not a rails fork' do
approval.should be_accepted
end
it 'does not accept a request that does not have a commit' do
approval.stubs(:commit).returns(nil)
approval.should_not be_accepted
end
it 'does not accept a request that belongs to a private repository' do
request.repository.stubs(:private?).returns(true)
approval.should_not be_accepted
end
it 'does not accept a request that belongs to an excluded repository' do
request.repository.stubs(:slug).returns('svenfuchs/rails')
approval.should_not be_accepted
end
it 'does not accept a request that is skipped (using the commit message)' do
request.commit.stubs(:message).returns('update README [ci:skip]')
approval.should_not be_accepted
end
it 'accepts a request that belongs to the github_pages branch and is explicitly set to build that branch (String)' do
request.commit.stubs(:branch).returns('gh_pages')
request.stubs(:config).returns('branches' => { 'only' => 'gh_pages' })
approval.should be_accepted
end
it 'accepts a request that belongs to the github_pages branch and is explicitly set to build that branch (Array)' do
request.commit.stubs(:branch).returns('gh_pages')
request.stubs(:config).returns('branches' => { 'only' => ['gh_pages'] })
approval.should be_accepted
end
it 'does not accept a request when it is disabled in settings' do
approval.stubs(:enabled_in_settings?).returns(false)
approval.should_not be_accepted
end
it 'does not accept a request when compare URL is too long' do
request.commit.stubs(:compare_url).returns('a'*256)
approval.should_not be_accepted
end
end
describe 'approved?' do
xit 'should be specified'
end
describe 'message' do
it 'returns "pull requests disabled" if pull requests are disabled' do
approval.stubs(:enabled_in_settings?).returns(false)
request.stubs(:pull_request?).returns(true)
approval.message.should == 'pull requests disabled'
end
it 'returns "pushes disabled" if pushes are disabled' do
approval.stubs(:enabled_in_settings?).returns(false)
request.stubs(:pull_request?).returns(false)
approval.message.should == 'pushes disabled'
end
it 'returns "missing commit" if the commit is missing' do
approval.stubs(:commit).returns(nil)
approval.message.should == 'missing commit'
end
it 'returns "private repository" if the repository is private' do
request.repository.stubs(:private?).returns(true)
request.stubs(:config).returns({key: 'value'})
approval.message.should == 'private repository'
end
it 'returns "excluded repository" if the repository is an excluded repository' do
request.repository.stubs(:slug).returns('svenfuchs/rails')
approval.message.should == 'excluded repository'
end
it 'returns "excluded repository" if the repository is an excluded repository and exclude rule is a string' do
Travis.config.repository_filter.stubs(:exclude).returns(["\\/rails$"])
request.repository.stubs(:slug).returns('svenfuchs/rails')
approval.message.should == 'excluded repository'
end
it 'returns "github pages branch" if the branch is a github pages branch' do
request.commit.stubs(:branch).returns('gh-pages')
approval.message.should == 'github pages branch'
end
it 'returns "config is missing or contains YAML syntax error" if the config is not present' do
request.stubs(:config).returns(nil)
approval.message.should == 'config is missing or contains YAML syntax error'
end
it 'returns "branch not included or excluded" if the branch was not approved' do
request.commit.stubs(:branch).returns('feature')
request.stubs(:config).returns('branches' => { 'only' => 'master' })
approval.message.should == 'branch not included or excluded'
end
it 'returns "compare URL too long; branch/tag names may be too long" if the compare URL is too long' do
request.stubs(:config).returns({key: 'value'})
request.commit.stubs(:compare_url).returns('a'*256)
approval.message.should == 'compare URL too long; branch/tag names may be too long'
end
end
describe 'skipped?' do
it 'returns true when the commit message contains [ci skip]' do
request.commit.stubs(:message).returns 'lets party like its 1999 [ci skip]'
approval.send(:skipped?).should be true
end
end
describe 'github_pages?' do
it 'returns true for a branch named gh-pages' do
request.commit.stubs(:branch).returns 'gh-pages'
approval.send(:github_pages?).should be_truthy
end
it 'returns true for a branch named gh_pages' do
request.commit.stubs(:branch).returns 'gh_pages'
approval.send(:github_pages?).should be_truthy
end
it 'returns true when a PR is for gh_pages' do
request.commit.stubs(:ref).returns 'refs/pulls/1/merge'
request.commit.stubs(:branch).returns 'gh_pages'
approval.send(:github_pages?).should be_truthy
end
it 'returns false for a branch named master' do
commit.stubs(:branch).returns 'master'
approval.send(:github_pages?).should be_falsy
end
end
describe 'included_repository?' do
it 'returns true if the repository is an included repository' do
request.repository.stubs(:slug).returns 'rails/rails'
approval.send(:included_repository?).should be true
end
it 'returns true if the repository is an included repository with rule as a string' do
Travis.config.repository_filter.stubs(:include).returns(["rails\\/rails"])
request.repository.stubs(:slug).returns 'rails/rails'
approval.send(:included_repository?).should be true
end
it 'returns false if the repository is not included' do
request.repository.stubs(:slug).returns 'josh/completeness-fu'
approval.send(:included_repository?).should be false
end
it 'returns false if the repository is not included with rule as a string' do
Travis.config.repository_filter.stubs(:include).returns(["rails\\/rails"])
request.repository.stubs(:slug).returns 'josh/completeness-fu'
approval.send(:included_repository?).should be false
end
end
describe 'excluded_repository?' do
it 'returns true if the repository is an excluded repository' do
request.repository.stubs(:slug).returns 'josh/rails'
approval.send(:excluded_repository?).should be true
end
it 'returns false if the repository is not excluded' do
request.repository.stubs(:slug).returns 'josh/completeness-fu'
approval.send(:excluded_repository?).should be false
end
it 'returns true if the repository is an excluded repository with rule as a string' do
Travis.config.repository_filter.stubs(:exclude).returns(["\\/rails$"])
request.repository.stubs(:slug).returns 'josh/rails'
approval.send(:excluded_repository?).should be true
end
it 'returns false if the repository is not excluded with rule as a string' do
Travis.config.repository_filter.stubs(:exclude).returns(["\\/rails$"])
request.repository.stubs(:slug).returns 'josh/completeness-fu'
approval.send(:excluded_repository?).should be false
end
end
describe 'enabled_in_settings?' do
it 'returns true if a request is an api request' do
request.stubs(:api_request?).returns(true)
approval.enabled_in_settings?.should be true
end
it 'returns true if pull requests are enabled and a request is a pull request' do
request.stubs(:pull_request?).returns(true)
approval.stubs(:build_pull_requests?).returns(true)
approval.enabled_in_settings?.should be true
end
it 'returns true if pushes are enabled and a request is a push' do
request.stubs(:pull_request?).returns(false)
approval.stubs(:build_pushes?).returns(true)
approval.enabled_in_settings?.should be true
end
it 'returns false if pull requests are disabled and a request is a pull request' do
request.stubs(:pull_request?).returns(true)
approval.stubs(:build_pull_requests?).returns(false)
approval.enabled_in_settings?.should be false
end
it 'returns false if pushes are disabled and a request is a push' do
request.stubs(:pull_request?).returns(false)
approval.stubs(:build_pushes?).returns(false)
approval.enabled_in_settings?.should be false
end
end
end

View File

@ -1,157 +0,0 @@
describe Request::Branches do
include Travis::Testing::Stubs
let(:branches) { Request::Branches.new(request) }
describe '#included?' do
it 'defaults to true if no branches are included' do
request.config['branches'] = { 'only' => nil }
branches.included?('feature').should be true
end
describe 'returns true if the included branches include the given branch' do
it 'given as a string' do
request.config['branches'] = { 'only' => 'feature' }
branches.included?('feature').should be true
end
it 'given as a comma separated list of branches' do
request.config['branches'] = { 'only' => 'feature, develop' }
branches.included?('feature').should be true
end
it 'given as an array of branches' do
request.config['branches'] = { 'only' => %w(feature develop) }
branches.included?('feature').should be true
end
end
describe 'returns true if the given branch matches a pattern from the included branches' do
it 'given as a string' do
request.config['branches'] = { 'only' => '/^feature-\d+$/' }
branches.included?('feature-42').should be true
end
it 'given as a comma separated list of patterns' do
request.config['branches'] = { 'only' => '/^feature-\d+$/,/^develop-\d+$/' }
branches.included?('feature-42').should be true
end
it 'given as an array of patterns' do
request.config['branches'] = { 'only' => %w(/^feature-\d+$/ /^develop-\d+$/) }
branches.included?('feature-42').should be true
end
end
describe 'returns false if the included branches do not include the given branch' do
it 'given as a string' do
request.config['branches'] = { 'only' => 'feature' }
branches.included?('master').should be false
end
it 'given as a comma separated list of branches' do
request.config['branches'] = { 'only' => 'feature, develop' }
branches.included?('master').should be false
end
it 'given as an array of branches' do
request.config['branches'] = { 'only' => %w(feature develop) }
branches.included?('master').should be false
end
end
describe 'returns false if the given branch does not match any pattern from the included branches' do
it 'given as a string' do
request.config['branches'] = { 'only' => '/^feature-\d+$/' }
branches.included?('master').should be false
end
it 'given as a comma separated list of patterns' do
request.config['branches'] = { 'only' => '/^feature-\d+$/,/^develop-\d+$/' }
branches.included?('master').should be false
end
it 'given as an array of patterns' do
request.config['branches'] = { 'only' => %w(/^feature-\d+$/ /^develop-\d+$/) }
branches.included?('master').should be false
end
end
end
describe '#excluded?' do
it 'defaults to false if no branches are excluded' do
request.config['branches'] = { 'except' => nil }
branches.excluded?('feature').should be_falsy
end
describe 'returns true if the excluded branches include the given branch' do
it 'given as a string' do
request.config['branches'] = { 'except' => 'feature' }
branches.excluded?('feature').should be true
end
it 'given as a comma separated list of branches' do
request.config['branches'] = { 'except' => 'feature, develop' }
branches.excluded?('feature').should be true
end
it 'given as an array of branches' do
request.config['branches'] = { 'except' => %w(feature develop) }
branches.excluded?('feature').should be true
end
end
describe 'returns true if the given branch matches a pattern from the excluded branches' do
it 'given as a string' do
request.config['branches'] = { 'except' => '/^feature-\d+$/' }
branches.excluded?('feature-42').should be true
end
it 'given as a comma separated list of patterns' do
request.config['branches'] = { 'except' => '/^feature-\d+$/,/^develop-\d+$/' }
branches.excluded?('feature-42').should be true
end
it 'given as an array of patterns' do
request.config['branches'] = { 'except' => %w(/^feature-\d+$/ /^develop-\d+$/) }
branches.excluded?('feature-42').should be true
end
end
describe 'returns false if the excluded branches do not include the given branch' do
it 'given as a string' do
request.config['branches'] = { 'except' => 'feature' }
branches.excluded?('master').should be false
end
it 'given as a comma separated list of branches' do
request.config['branches'] = { 'except' => 'feature, develop' }
branches.excluded?('master').should be false
end
it 'given as an array of branches' do
request.config['branches'] = { 'except' => %w(feature develop) }
branches.excluded?('master').should be false
end
end
describe 'returns false if the given branch does not match any pattern from the excluded branches' do
it 'given as a string' do
request.config['branches'] = { 'except' => '/^feature-\d+$/' }
branches.excluded?('master').should be false
end
it 'given as a comma separated list of patterns' do
request.config['branches'] = { 'except' => '/^feature-\d+$/,/^develop-\d+$/' }
branches.excluded?('master').should be false
end
it 'given as an array of patterns' do
request.config['branches'] = { 'except' => %w(/^feature-\d+$/ /^develop-\d+$/) }
branches.excluded?('master').should be false
end
end
end
end

View File

@ -1,250 +0,0 @@
describe Request::States do
let(:owner) { User.new(:login => 'joshk') }
let(:repository) { Repository.new(:name => 'travis-ci', :owner => owner, :owner_name => 'travis-ci') }
let(:commit) { Commit.new(:repository => repository, :commit => '12345', :branch => 'master', :message => 'message', :committed_at => Time.now, :compare_url => 'https://github.com/svenfuchs/minimal/compare/master...develop') }
let(:request) { Request.new(:repository => repository, :commit => commit) }
let(:approval) { Request::Approval.any_instance }
let(:config) { { :from => '.travis.yml' } }
before :each do
repository.save!
Travis.stubs(:run_service).with(:github_fetch_config, is_a(Hash)).returns(config)
request.stubs(:add_build)
request.stubs(:creates_jobs?).returns(true)
end
it 'has the state :created when just created' do
request.state.should == :created
end
describe 'start' do
describe 'with an accepted request' do
before :each do
approval.stubs(:accepted?).returns(true)
end
it 'configures the request' do
request.expects(:configure)
request.start
end
it 'finishes the request' do
request.expects(:finish)
request.start
end
it 'sets the state to started' do
request.start
request.was_started?.should be true
end
it 'sets the result to :accepted' do
request.start
request.result.should == :accepted
end
describe 'but rejected config' do
before :each do
approval.stubs(:config_accepted?).returns(false)
end
it 'does config, but resets it to nil' do
request.expects(:fetch_config).returns({})
request.start
request.config.should be_nil
end
end
describe 'but rejected branch' do
before :each do
approval.stubs(:branch_accepted?).returns(false)
end
it 'does config, but resets it to nil' do
request.expects(:fetch_config).returns({})
request.start
request.config.should be_nil
end
end
end
describe 'with a rejected request' do
before :each do
approval.stubs(:accepted?).returns(false)
end
it 'does not configure the request' do
request.expects(:fetch_config).never
request.start
end
it 'finishes the request' do
request.expects(:finish)
request.start
end
it 'sets the state to started' do
request.start
request.was_started?.should be true
end
it 'sets the result to :rejected' do
request.start
request.result.should == :rejected
end
end
end
describe 'configure' do
it 'fetches the .travis.yml config from Github' do
Travis.expects(:run_service).returns(config)
request.configure
end
it 'merges existing configuration (e.g. from an api request)' do
request.config = { env: 'FOO=foo' }
request.configure
request.config.should == config.merge(env: 'FOO=foo')
end
it 'stores the config on the request' do
request.configure
request.config.should == config
end
it 'sets the state to configured' do
request.configure
request.was_configured?.should be true
end
end
describe 'finish' do
before :each do
request.stubs(:config).returns('.configured' => true)
end
describe 'with an approved request' do
before :each do
approval.stubs(:approved?).returns(true)
end
it 'builds the build' do
request.expects(:add_build)
request.finish
end
it 'sets the state to finished' do
request.finish
request.should be_finished
end
end
describe 'with an unapproved request' do
before :each do
approval.stubs(:approved?).returns(false)
end
it 'does not build the build' do
request.expects(:add_build).never
request.finish
end
it 'sets the state to finished' do
request.finish
request.should be_finished
end
end
describe 'with a config parse error' do
let(:job) { stub(start!: nil, finish!: nil, :log_content= => nil) }
let(:build) { stub(matrix: [job], finish!: nil) }
before :each do
request.stubs(:add_build).returns(build)
request.stubs(:config).returns('.result' => 'parse_error')
end
it 'builds the build' do
request.expects(:add_build).returns(build)
request.finish
end
it 'prints an error to the log' do
job.expects(:log_content=)
request.finish
end
end
describe 'with a config server error' do
let(:job) { stub(start!: nil, finish!: nil, :log_content= => nil) }
let(:build) { stub(matrix: [job], finish!: nil) }
before :each do
request.stubs(:add_build).returns(build)
request.stubs(:config).returns('.result' => 'server_error')
end
it 'builds the build' do
request.expects(:add_build).returns(build)
request.finish
end
it 'prints an error to the log' do
job.expects(:log_content=)
request.finish
end
end
end
describe 'start!' do
before :each do
request.stubs(:config).returns('.configured' => true)
approval.stubs(:approved?).returns(true)
end
it 'finally sets the state to finished' do
request.repository.save!
request.repository_id = request.repository.id
request.save!
request.start!
request.reload.should be_finished
end
end
describe "adding a build" do
before do
request.unstub(:add_build)
Travis.config.notify_on_build_created = true
end
after do
request.stubs(:add_build)
Travis.config.notify_on_build_created = false
end
it "should create a build" do
request.save
request.add_build_and_notify.should be_a(Build)
end
it "should notify the build" do
request.save
Travis::Event.expects(:dispatch).with do |event, *args|
event.should == "build:created"
end
request.add_build_and_notify
end
it "shouldn't notify the build when the flag is disabled" do
Travis.config.notify_on_build_created = false
request.save
Travis::Event.expects(:dispatch).with { |e, *| e.should == "build:created" }.never
request.add_build_and_notify
end
end
end

View File

@ -1,5 +1,5 @@
describe User do describe User do
before { User.delete_all } before { DatabaseCleaner.clean_with :truncation }
let(:user) { Factory(:user, :github_oauth_token => 'token') } let(:user) { Factory(:user, :github_oauth_token => 'token') }
let(:payload) { GITHUB_PAYLOADS[:oauth] } let(:payload) { GITHUB_PAYLOADS[:oauth] }

View File

@ -1,23 +0,0 @@
module Travis
class CommitCommand
def initialize(message)
@message = message.to_s
end
def skip?
backwards_skip or command == 'skip'
end
private
attr_reader :message
def command
message =~ /\[ci(?: |:)([\w ]*)\]/i && $1.downcase
end
def backwards_skip
message =~ /\[skip\s+ci\]/i && true
end
end
end

View File

@ -8,12 +8,9 @@ require 'travis/model/encrypted_column'
# and needs to be approved based on the configuration. Once approved the # and needs to be approved based on the configuration. Once approved the
# Request creates a Build. # Request creates a Build.
class Request < Travis::Model class Request < Travis::Model
require 'travis/model/request/approval'
require 'travis/model/request/branches'
require 'travis/model/request/pull_request' require 'travis/model/request/pull_request'
require 'travis/model/request/states'
include States, SimpleStates include SimpleStates
serialize :token, Travis::Model::EncryptedColumn.new(disable: true) serialize :token, Travis::Model::EncryptedColumn.new(disable: true)

View File

@ -1,130 +0,0 @@
class Request
class Approval
attr_reader :request, :repository, :commit
def initialize(request)
@request = request
@repository = request.repository
@commit = request.commit
end
def settings
repository.settings
end
delegate :build_pushes?, :build_pull_requests?, to: :settings
def accepted?
commit.present? &&
!repository.private? &&
(!excluded_repository? || included_repository?) &&
!skipped? &&
!compare_url_too_long? &&
enabled_in_settings?
end
def enabled_in_settings?
request.api_request? || (request.pull_request? ? build_pull_requests? : build_pushes?)
end
def disabled_in_settings?
!enabled_in_settings?
end
def branch_accepted?
github_pages_explicitly_enabled? || !github_pages?
end
def config_accepted?
(travis_yml_present? || allow_builds_without_travis_yml?)
end
def travis_yml_present?
request.config && request.config['.result'] == 'configured'
end
def allow_builds_without_travis_yml?
!repository.builds_only_with_travis_yml?
end
def compare_url_too_long?
commit.compare_url.length > 255
end
def approved?
accepted? && request.config.present? && branch_approved? && request.creates_jobs?
end
def result
approved? ? :accepted : :rejected
end
def message
if !commit.present?
'missing commit'
elsif excluded_repository?
'excluded repository'
elsif skipped?
'skipped through commit message'
elsif disabled_in_settings?
request.pull_request? ? 'pull requests disabled' : 'pushes disabled'
elsif github_pages?
'github pages branch'
elsif !branch_approved? || !branch_accepted?
'branch not included or excluded'
elsif !config_accepted?
'.travis.yml is missing and builds without .travis.yml are disabled'
elsif repository.private?
'private repository'
elsif !request.creates_jobs?
'matrix created no jobs'
elsif compare_url_too_long?
'compare URL too long; branch/tag names may be too long'
elsif request.config.blank?
'config is missing or contains YAML syntax error'
end
end
private
def skipped?
Travis::CommitCommand.new(commit.message).skip?
end
def github_pages_explicitly_enabled?
request.config &&
request.config['branches'] &&
request.config['branches'].is_a?(Hash) &&
request.config['branches']['only'] &&
Array(request.config['branches']['only']).grep(/gh[-_]pages/i)
end
def github_pages?
commit.branch =~ /gh[-_]pages/i
end
def excluded_repository?
exclude_rules.any? { |rule| repository.slug =~ rule }
end
def included_repository?
include_rules.any? { |rule| repository.slug =~ rule }
end
def include_rules
Travis.config.repository_filter.include.map { |rule| rule.is_a?(Regexp) ? rule : Regexp.new(rule) }
end
def exclude_rules
Travis.config.repository_filter.exclude.map { |rule| rule.is_a?(Regexp) ? rule : Regexp.new(rule) }
end
def branch_approved?
branches.included?(commit.branch) && !branches.excluded?(commit.branch)
end
def branches
@branches ||= Branches.new(request)
end
end
end

View File

@ -1,57 +0,0 @@
class Request
# Logic that figures out whether a branch is in- or excluded (white- or
# blacklisted) by the configuration (`.travis.yml`)
class Branches
attr_reader :request, :commit
def initialize(request)
@request = request
@commit = request.commit
end
def included?(branch)
!included || includes?(included, branch)
end
def excluded?(branch)
excluded && includes?(excluded, branch)
end
private
def included
config['only']
end
def excluded
config['except']
end
def includes?(branches, branch)
branches.any? { |pattern| matches?(pattern, branch) }
end
def matches?(pattern, branch)
pattern = pattern =~ %r{^/(.*)/$} ? Regexp.new($1) : pattern
pattern === branch
end
def config
@config ||= case branches = request.config.try(:[], 'branches')
when Array
{ :only => branches }
when String
{ :only => split(branches) }
when Hash
branches.each_with_object({}) { |(k, v), result| result[k] = split(v) }
else
{}
end
end
def split(branches)
branches.is_a?(String) ? branches.split(',').map(&:strip) : branches
end
end
end

View File

@ -1,119 +0,0 @@
require 'active_support/concern'
require 'simple_states'
class Request
module States
extend ActiveSupport::Concern
include Travis::Event
included do
include SimpleStates
states :created, :started, :finished
event :start, :to => :started, :after => :configure
event :configure, :to => :configured, :after => :finish
event :finish, :to => :finished
event :all, :after => :notify
end
def configure
if !accepted?
Travis.logger.warn("[request:configure] Request not accepted: event_type=#{event_type.inspect} commit=#{commit.try(:commit).inspect} message=#{approval.message.inspect}")
else
self.config = fetch_config.merge(config || {})
if branch_accepted? && config_accepted?
Travis.logger.info("[request:configure] Request successfully configured commit=#{commit.commit.inspect}")
else
self.config = nil
Travis.logger.warn("[request:configure] Request not accepted: event_type=#{event_type.inspect} commit=#{commit.try(:commit).inspect} message=#{approval.message.inspect}")
end
end
save!
end
def finish
if config.blank?
Travis.logger.warn("[request:finish] Request not creating a build: config is blank or contains YAML syntax error, config=#{config.inspect} commit=#{commit.try(:commit).inspect}")
elsif !approved?
Travis.logger.warn("[request:finish] Request not creating a build: not approved commit=#{commit.try(:commit).inspect} message=#{approval.message.inspect}")
elsif parse_error?
Travis.logger.info("[request:finish] Request created but Build and Job automatically errored due to a config parsing error. commit=#{commit.try(:commit).inspect}")
add_parse_error_build
elsif server_error?
Travis.logger.info("[request:finish] Request created but Build and Job automatically errored due to a config server error. commit=#{commit.try(:commit).inspect}")
add_server_error_build
else
add_build_and_notify
Travis.logger.info("[request:finish] Request created a build. commit=#{commit.try(:commit).inspect}")
end
self.result = approval.result
self.message = approval.message
Travis.logger.info("[request:finish] Request finished. result=#{result.inspect} message=#{message.inspect} commit=#{commit.try(:commit).inspect}")
end
def add_build
builds.create!(:repository => repository, :commit => commit, :config => config, :owner => owner)
end
def add_build_and_notify
add_build.tap do |build|
build.notify(:created) if Travis.config.notify_on_build_created
end
end
protected
delegate :accepted?, :approved?, :branch_accepted?, :config_accepted?, :to => :approval
def approval
@approval ||= Approval.new(self)
end
def fetch_config
Travis.run_service(:github_fetch_config, request: self) # TODO move to a service, have it pass the config to configure
end
def add_parse_error_build
Build.transaction do
build = add_build
job = build.matrix.first
job.start!(started_at: Time.now.utc)
job.log_content = <<ERROR
\033[31;1mERROR\033[0m: An error occured while trying to parse your .travis.yml file.
Please make sure that the file is valid YAML.
http://lint.travis-ci.org can check your .travis.yml.
The error was "#{config[".result_message"]}".
ERROR
job.finish!(state: "errored", finished_at: Time.now.utc)
build.finish!(state: "errored", finished_at: Time.now.utc)
end
end
def parse_error?
config[".result"] == "parse_error"
end
def add_server_error_build
Build.transaction do
build = add_build
job = build.matrix.first
job.start!(started_at: Time.now.utc)
job.log_content = <<ERROR
\033[31;1mERROR\033[0m: An error occured while trying to fetch your .travis.yml file.
Is GitHub down? Please contact support@travis-ci.com if this persists.
ERROR
job.finish!(state: "errored", finished_at: Time.now.utc)
build.finish!(state: "errored", finished_at: Time.now.utc)
end
end
def server_error?
config[".result"] == "server_error"
end
end
end