Sha256: 21854c2379ba2fa360c593bae97e903324fdc8379e5eda439a64212fd184e812

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

require "httparty"
require 'rexml/document'
require 'cgi'

require "kraken-build/version"
require "kraken-build/jenkins-api.rb"
require "kraken-build/github-api.rb"

module KrakenBuild
  def self.set_config(options = {})
    @config = options
    @repository = @config[:repository]
    @github = GithubApi.new(@config)
    @jenkins = JenkinsApi.new(@config)
    @jobs = []
    @branches = []

    @config
  end

  def self.get_jenkins_branches
    @jenkins.get_jobs.map { |job| job =~ /^#{@repository}\.(.*)$/ && $1 }.compact
  end

  def self.get_github_branches
    @github.get_branches
  end

  def self.run
    @jobs = get_jenkins_branches
    @branches = get_github_branches

    create = compute_jobs_to_create
    create.map do |job|
      job_name = "#{@repository}.#{job}"
      puts "creating => #{job_name}"
      @jenkins.create_job(job_name)
      @jenkins.build_job(job_name)
    end

    remove = compute_jobs_to_remove
    remove.map do |job|
      job_name = "#{@repository}.#{job}"
      puts "removing => #{job_name}"
      @jenkins.remove_job(job_name)
    end
  end

   def self.compute_jobs_to_create
    @branches - @jobs
  end

  def self.compute_jobs_to_remove
    @jobs - @branches
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kraken-build-0.0.5 lib/kraken-build.rb
kraken-build-0.0.4 lib/kraken-build.rb
kraken-build-0.0.3 lib/kraken-build.rb