octo_merge 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc888e5760a08871d2d68cd5e43044e4cc03eb92
4
- data.tar.gz: e715350366209678d5c31d315ac5d905ef9e1904
3
+ metadata.gz: d04807b8aa3b52cc6ba26b896fd4c293a6ce2b15
4
+ data.tar.gz: f61a9911d245112f1e2db1e324fd32d110a29f6e
5
5
  SHA512:
6
- metadata.gz: 777dc01da1a20b0c2df6711089a0fce0a065a76e789c7c1aae5a9948c96ad0ee14954929ce222c77cf47839873da37584efd432c4b74ed9f9663741af05a6748
7
- data.tar.gz: 53660d4e55248fff632d5cee36c71cc32c3024047769b3a6aaf12bbad188a740764425224e538538cd4f7d0a5ee0dc2eccf0bc7df743d706add9379713a917f3
6
+ metadata.gz: be5dcf239a003519014f413e5024ecb5d9df799d736df2394de0bf428e90481fcb4f86e49c002d6339808fd99166c2d275a6713eb65fa679475818b74cec8772
7
+ data.tar.gz: 8f3534fe23b033a617f23fbffd6d40f5d781dc98ba6fb7404f05dace046328b16b526101028ede993d142495f09969080044b65d4fc3d831662c4a24a5f565be
data/exe/octo-merge CHANGED
@@ -4,11 +4,18 @@ require "optparse"
4
4
  require "octo_merge"
5
5
  require "yaml"
6
6
 
7
- options = if File.exist?(".octo-merge.yml")
7
+ options = {}
8
+
9
+ user_config_path = File.expand_path("~/.octo-merge.yml")
10
+
11
+ if File.exist?(user_config_path)
12
+ body = File.read(user_config_path)
13
+ options.merge!(YAML.load(body))
14
+ end
15
+
16
+ if File.exist?(".octo-merge.yml")
8
17
  body = File.read(".octo-merge.yml")
9
- YAML.load(body)
10
- else
11
- {}
18
+ options.merge!(YAML.load(body))
12
19
  end
13
20
 
14
21
  # Symbolize keys
@@ -17,6 +17,7 @@ class Git
17
17
  end
18
18
 
19
19
  git :checkout
20
+ git :commit
20
21
  git :fetch
21
22
  git :merge_no_ff, "merge --no-ff"
22
23
  git :rebase
@@ -0,0 +1,87 @@
1
+ require 'tempfile'
2
+
3
+ module OctoMerge
4
+ class MergeWithRebaseAndMessage < AbstractMerge
5
+ def run
6
+ git.checkout(master)
7
+ git.fetch(upstream)
8
+ git.reset_hard("#{upstream}/#{master}")
9
+
10
+ pull_requests.each do |pull_request|
11
+ git.remote_add("#{pull_request.remote} #{pull_request.remote_url}")
12
+ git.fetch(pull_request.remote)
13
+ git.checkout(pull_request.branch)
14
+ git.rebase(master)
15
+ git.checkout(master)
16
+ git.merge_no_ff(pull_request.branch)
17
+
18
+ add_merge_message(pull_request)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ # TODO: Can we add a custom message to a merge commit in an easier way?
25
+ #
26
+ # Note: It's hard to add a multiline message with `merge --message`.
27
+ #
28
+ # The `--file` options does not work for `git --merge` so we abuse
29
+ # `git commit --amend` to apply this message to the merge commit.
30
+ def add_merge_message(pull_request)
31
+ MergeMessageFile.path_for(pull_request) do |path|
32
+ git.commit("--amend --file=#{path}")
33
+ end
34
+ end
35
+
36
+ class MergeMessageFile
37
+ def initialize(pull_request)
38
+ @pull_request = pull_request
39
+ file.write(body)
40
+ file.close
41
+ end
42
+
43
+ def self.path_for(pull_request)
44
+ new(pull_request).tap do |file|
45
+ yield(file.path)
46
+ file.delete
47
+ end
48
+ end
49
+
50
+ def path
51
+ file.path
52
+ end
53
+
54
+ def delete
55
+ file.unlink
56
+ end
57
+
58
+ private
59
+
60
+ attr_reader :pull_request
61
+
62
+ def file
63
+ @file ||= Tempfile.new('merge_commit_message')
64
+ end
65
+
66
+ def body
67
+ sanitize <<-BODY
68
+ Merge branch '#{pull_request.branch}'
69
+
70
+ Resolves and closes: #{pull_request.url}
71
+
72
+ = #{pull_request.title}
73
+
74
+ #{pull_request.body}
75
+ BODY
76
+
77
+ end
78
+
79
+ def sanitize(body)
80
+ # Replace leading "#" and replace with "="
81
+ body.gsub(/^#+/) { |s| "=" * s.length }
82
+ end
83
+ end
84
+
85
+ private_constant :MergeMessageFile
86
+ end
87
+ end
@@ -9,6 +9,10 @@ module OctoMerge
9
9
  @number = number.to_s
10
10
  end
11
11
 
12
+ def url
13
+ github_api_result.html_url
14
+ end
15
+
12
16
  def remote
13
17
  github_api_result.user.login
14
18
  end
@@ -21,6 +25,14 @@ module OctoMerge
21
25
  github_api_result.head.ref
22
26
  end
23
27
 
28
+ def title
29
+ github_api_result.title
30
+ end
31
+
32
+ def body
33
+ github_api_result.body
34
+ end
35
+
24
36
  def ==(other_pull_request)
25
37
  repo == other_pull_request.repo && number == other_pull_request.number
26
38
  end
@@ -1,3 +1,3 @@
1
1
  module OctoMerge
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/octo_merge.rb CHANGED
@@ -10,6 +10,7 @@ require "octo_merge/pull_request"
10
10
 
11
11
  require "octo_merge/abstract_merge"
12
12
  require "octo_merge/merge_with_rebase"
13
+ require "octo_merge/merge_with_rebase_and_message"
13
14
  require "octo_merge/merge_without_rebase"
14
15
 
15
16
  module OctoMerge
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octo_merge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Helm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-01 00:00:00.000000000 Z
11
+ date: 2016-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -137,6 +137,7 @@ files:
137
137
  - lib/octo_merge/interactive_pull_requests.rb
138
138
  - lib/octo_merge/list_pull_requests.rb
139
139
  - lib/octo_merge/merge_with_rebase.rb
140
+ - lib/octo_merge/merge_with_rebase_and_message.rb
140
141
  - lib/octo_merge/merge_without_rebase.rb
141
142
  - lib/octo_merge/pull_request.rb
142
143
  - lib/octo_merge/version.rb