"Fossies" - the Fresh Open Source Software Archive

Member "asciidoctor-2.0.10/tasks/dependents.rake" (1 Jun 2019, 2265 Bytes) of package /linux/www/asciidoctor-2.0.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 # frozen_string_literal: true
    2 namespace :build do
    3   desc 'Trigger builds for all dependent projects on Travis CI'
    4   task :dependents do
    5     if ENV['TRAVIS'].to_s == 'true'
    6       next unless ENV['TRAVIS_PULL_REQUEST'].to_s == 'false' &&
    7           ENV['TRAVIS_TAG'].to_s.empty? &&
    8           (ENV['TRAVIS_JOB_NUMBER'].to_s.end_with? '.1')
    9     end
   10     # NOTE The TRAVIS_TOKEN env var must be defined in Travis interface.
   11     # Retrieve this token using the `travis token` command.
   12     # The GitHub user corresponding to the Travis user must have write access to the repository.
   13     # After granting permission, sign into Travis and resync the repositories.
   14     next unless (token = ENV['TRAVIS_TOKEN'])
   15     require 'json'
   16     require 'net/http'
   17     require 'open-uri'
   18     require 'yaml'
   19     %w(
   20       asciidoctor/asciidoctor.js
   21       asciidoctor/asciidoctorj
   22       asciidoctor/asciidoctor-diagram
   23       asciidoctor/asciidoctor-reveal.js
   24     ).each do |project|
   25       org, name, branch = project.split '/', 3
   26       branch ||= 'master'
   27       project = [org, name, branch] * '/'
   28       header = {
   29         'Content-Type' => 'application/json',
   30         'Accept' => 'application/json',
   31         'Travis-API-Version' => '3',
   32         'Authorization' => %(token #{token})
   33       }
   34       if (commit_hash = ENV['TRAVIS_COMMIT'])
   35         commit_memo = %( (#{commit_hash.slice 0, 8})\n\nhttps://github.com/#{ENV['TRAVIS_REPO_SLUG'] || 'asciidoctor/asciidoctor'}/commit/#{commit_hash})
   36       end
   37       config = YAML.load open(%(https://raw.githubusercontent.com/#{project}/.travis-upstream-only.yml)) {|fd| fd.read } rescue {}
   38       payload = {
   39         'request' => {
   40           'branch' => branch,
   41           'message' => %(Build triggered by Asciidoctor#{commit_memo}),
   42           'config' => config
   43         }
   44       }.to_json
   45       (http = Net::HTTP.new 'api.travis-ci.org', 443).use_ssl = true
   46       request = Net::HTTP::Post.new %(/repo/#{org}%2F#{name}/requests), header
   47       request.body = payload
   48       response = http.request request
   49       if response.code == '202'
   50         puts %(Successfully triggered build on #{project} repository)
   51       else
   52         warn %(Unable to trigger build on #{project} repository: #{response.code} - #{response.message})
   53       end
   54     end
   55   end
   56 end