Skip to content

Instantly share code, notes, and snippets.

@Larusso
Created March 17, 2017 12:33
Show Gist options
  • Save Larusso/6ab3c73c61a905565eaababac49b9ec7 to your computer and use it in GitHub Desktop.
Save Larusso/6ab3c73c61a905565eaababac49b9ec7 to your computer and use it in GitHub Desktop.
Simple rake task that creates multiple pull request
require 'octokit'
require 'erb'
Octokit.auto_paginate = true
client = Octokit::Client.new access_token: 'GIT_TOKEN'
root = File.dirname(__FILE__)
def each_repo(root, &block)
Dir.foreach(root) {|repo|
if File.directory?(File.join(root, repo)) and File.exist?(File.join(root, repo, '.git'))
block.call(File.join(root,repo), repo)
end
}
end
desc "open pull request"
task :open_pm do
each_repo(root) {|repo_path, repo_name|
repo_name = "wooga/#{repo_name}"
current_branch = `git -C #{repo_path} rev-parse --abbrev-ref HEAD`.strip
last_commit_message = `git -C #{repo_path} log --format=%B -n 1`.strip
lines = last_commit_message.lines
title = lines[0]
body = ""
if lines.count > 1
first_index = (lines[1].empty?) ? 2 : 1
body = lines.slice(first_index, lines.count).join("")
end
puts repo_name
puts current_branch
puts title
puts ""
puts body
client.create_pull_request(repo_name, "master", current_branch, title, body)
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment