Created
October 8, 2021 17:45
-
-
Save fabdbt/181fe85ecb64ca78b5acc41586c2b776 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# Requirements : | |
# Be logged using Github CLI : https://github.com/cli/cli | |
# Place this script in a folder at same level than other repositories, i.e. : | |
# - ./Workspace/api-core | |
# - ./Workspace/mep/matera_mep.rb | |
# Usage : | |
# * ruby matera_mep.rb [repo] | |
# Arguments : | |
# * repo (optional) : If you want to create a PR elsewhere than api-core, pass the project name, i.e. app-core | |
# ruby matera_mep.rb app-core | |
require "json" | |
require "date" | |
require "tempfile" | |
DEFAULT_PROJECT = "api-core" | |
PROJECT = ARGV[0] || DEFAULT_PROJECT | |
def fetch_pr_url | |
result = `bash -c "gh pr list --search 'is:pr is:open base:master head:development' --limit 1 --json url -R github.com/matera-tech/#{PROJECT} | cat"` | |
body = JSON.parse(result) | |
body.dig(0, "url") | |
end | |
if url = fetch_pr_url | |
system("open", url) | |
else | |
date = Date.today.strftime("%d/%m") | |
puts "Creating PR for #{date} ..." | |
file = Tempfile.new('foo') | |
commits = `cd ../#{PROJECT} && git fetch origin -q && git log --graph --pretty=format:'%s' --abbrev-commit origin/master..origin/development | cat` | |
file.write(commits) | |
file.rewind | |
pr_url = `bash -c 'cd ../#{PROJECT} && echo \"ok\" && gh pr create --title \"MEP #{date}\" --body-file \"#{file.path}\" --fill --base master --head development | cat'` | |
file.unlink | |
puts "PR created ! #{pr_url}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment