Created
March 17, 2017 12:33
-
-
Save Larusso/6ab3c73c61a905565eaababac49b9ec7 to your computer and use it in GitHub Desktop.
Simple rake task that creates multiple pull request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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