Sha256: 3c4568417ab00c045454206b77278b1fbfef96ea32600d1bc447c1555c7d0344

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

require 'travisci/bundle/update/pr/version'

module Travisci
  module Bundle
    module Update
      module Pr
        def self.start(git_username: nil, git_email: nil, git_branch: ['master'])
          raise "travisci-bundle-update-pr can be executed only in Travis CI." unless ENV['TRAVIS']
          raise "$TRAVIS_REPO_SLUG undefined." unless ENV['TRAVIS_REPO_SLUG']
          raise "$GITHUB_ACCESS_TOKEN undefined." unless ENV['GITHUB_ACCESS_TOKEN']

          unless system("bundle update && bundle update --ruby")
            raise "Unable to execute `bundle update && bundle update --ruby`"
          end
          unless `git status -s 2> /dev/null`.include?('Gemfile.lock')
            return
          end

          now = Time.now.strftime('%Y%m%d%H%M%S')
          branch = "bundle-update-#{now}"
          system("git config --global user.name #{git_username}")
          system("git config --global user.email #{git_email}")
          system("git init")
          system("git checkout -b #{branch}")
          system("git add Gemfile.lock")
          system("git commit -m '$ bundle update && bundle update --ruby'")
          system("git push --force --quiet \"https://${GITHUB_ACCESS_TOKEN}@github.com/#{ENV['TRAVIS_REPO_SLUG']}.git\" #{branch}:#{branch} > /dev/null 2>&1")

          title = "bundle update #{now}"
          body  = 'Auto generated by [TravisCI]'
          repo_full_name = "#{ENV['TRAVIS_REPO_SLUG']}"

          client = Octokit::Client.new(access_token: ENV['GITHUB_ACCESS_TOKEN'])
          client.create_pull_request(
              repo_full_name,
              git_branch,
              branch,
              title,
              body
          )
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
travisci-bundle-update-pr-0.0.6 lib/travisci/bundle/update/pr.rb
travisci-bundle-update-pr-0.0.4 lib/travisci/bundle/update/pr.rb