|
18 | 18 | require 'optparse'
|
19 | 19 |
|
20 | 20 | @options = {
|
21 |
| - repo_root: "./" |
| 21 | + repo_root: "./", |
| 22 | + pr_title: "Autogenerated PR", |
| 23 | + pr_body: "", |
| 24 | + base_branch: "generated-branch-for-pr-"+Time.new.strftime("%Y%m%d%H%M%S"), |
| 25 | + commit_comment: "Auto generated commit." |
22 | 26 | }
|
23 | 27 | begin
|
24 | 28 | OptionParser.new do |opts|
|
25 | 29 | opts.banner = "Usage: create_pull_request.rb [options]"
|
26 | 30 | opts.on('-r', '--repo-root REPO_ROOT', 'Root path of the repo dir.') { |v| @options[:repo_root] = v }
|
27 | 31 | opts.on('-t', '--repo-token REPO_TOKEN', 'Token with write access') { |v| @options[:repo_token] = v }
|
28 |
| - opts.on('-n', '--notices-path NOTICES_PATH', 'Path of NOTICES file') { |v| @options[:notices_path] = v } |
| 32 | + opts.on('-n', '--target-path PATH', 'Path of targeted file or dir') { |v| @options[:target_path] = v } |
| 33 | + opts.on('--pr-title PR_TITLE', 'Title of a PR') { |v| @options[:pr_title] = v } |
| 34 | + opts.on('--pr-body PR_BODY', 'Body of a PR') { |v| @options[:pr_body] = v } |
| 35 | + opts.on('--base-branch', 'A new branch will be generated if not specified or the branch does not exist.') { |v| @options[:base_branch] = v } |
| 36 | + opts.on('--commit-comment', 'Commit comment') { |v| @options[:commit_comment] = v } |
29 | 37 | end.parse!
|
30 | 38 |
|
31 |
| - raise OptionParser::MissingArgument if @options[:repo_token].nil? || @options[:notices_path].nil? |
| 39 | + raise OptionParser::MissingArgument if @options[:repo_token].nil? || @options[:target_path].nil? |
32 | 40 | rescue OptionParser::MissingArgument
|
33 |
| - puts "Notices path, `--notices-path`, should be specified. " if @options[:notices_path].nil? |
| 41 | + puts "target path, `--target-path`, should be specified. " if @options[:target_path].nil? |
34 | 42 | puts "A token ,`--repo-token`, should be provided for creating a pull request." if @options[:repo_token].nil?
|
35 | 43 | raise
|
36 | 44 | end
|
37 | 45 |
|
38 | 46 | REPO_ROOT=@options[:repo_root]
|
39 | 47 | ACCESS_TOKEN=@options[:repo_token]
|
40 |
| -NOTICES_PATH=@options[:notices_path] |
| 48 | +TARGET_PATH=@options[:target_path] |
| 49 | +PR_TITLE=@options[:pr_title] |
| 50 | +PR_BODY=@options[:pr_boday] |
| 51 | +BASE_BRANCH=@options[:base_branch] |
| 52 | +COMMIT_COMMENT=@options[:commit_comment] |
41 | 53 |
|
42 |
| -def generate_pr_for_notices_changes(repo_root:, notices_path:) |
43 |
| - system("cd #{repo_root}") |
44 |
| - system("git checkout -b notices_diff_detected\n git add CoreOnly/NOTICES\n git commit -m \"NOTICES diff detected.\"\n git push -u origin notices_diff_detected") |
| 54 | +def generate_pr_for_target_changes(repo_root:, target_path:) |
| 55 | + system("cd #{REPO_ROOT}\ngit checkout -b #{BASE_BRANCH}\n") |
| 56 | + if `git diff #{TARGET_PATH}`=="" |
| 57 | + puts "The file, #{TARGET_PATH}, has no changes." |
| 58 | + return |
| 59 | + end |
| 60 | + system("git add #{TARGET_PATH}\ngit commit -m \"#{COMMIT_COMMENT}\"\n git push -u origin #{BASE_BRANCH}") |
45 | 61 | client = Octokit::Client.new(access_token: ACCESS_TOKEN)
|
46 |
| - client.create_pull_request("firebase/firebase-ios-sdk", "master", "notices_diff_detected", "Pull Request title", "Pull Request body") |
| 62 | + client.create_pull_request("firebase/firebase-ios-sdk", "master", BASE_BRANCH, PR_TITLE, PR_BODY) |
47 | 63 | end
|
48 | 64 |
|
49 | 65 |
|
50 | 66 | def main()
|
51 |
| - generate_pr_for_notices_changes(repo_root: REPO_ROOT, notices_path: NOTICES_PATH) |
| 67 | + generate_pr_for_target_changes(repo_root: REPO_ROOT, target_path: TARGET_PATH) |
52 | 68 | end
|
53 | 69 |
|
54 | 70 | main()
|
|
0 commit comments