fight_club 0.0.7 → 0.0.8

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: d34def593e81184a62f6cf94c897aaf2b0bd4d9f
4
- data.tar.gz: e74a9144d1959b1168f31775d3c1ce494b525e78
3
+ metadata.gz: a269b42519673bd28d5fa19403da0d94f309b0b1
4
+ data.tar.gz: 87f3cc35e6e17503dc6202acc4c69c46cfb9ad1b
5
5
  SHA512:
6
- metadata.gz: 149bf227c0f4e283a0589c1b5af1ae54f588d173a93a78b5dc77bbea91de47b482c997a7bc687e48d68f24066b6fc0f1016a08ebe0414c3c771a07850e62bc38
7
- data.tar.gz: 318c8ba656c7a6ac41fa0d6105c8e5e401bc9d58df290633f1495f826941dbd53a26bfcab524675d23261908d357966616371d71e787c9db02d1d0cc0cc50f78
6
+ metadata.gz: 4ae27b472c71cbc3dbc4ecee48faa321acc4bdf3099472580ef1bccfc1b9be2fb4fa790303c34ba806fae7e1c303c1a530b0643b3749fd67affc1a38eec070ee
7
+ data.tar.gz: 4e23480dc43e04799159ff29a0102c2902f62f5df841af3bf4a999699f8fd7b6b53385e2ad5b63bfec356b2de767aa93f2aaa75a7283eb79d6f188e0edb898e1
@@ -17,7 +17,6 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.add_development_dependency "bundler", "~> 1.6"
19
19
  spec.add_development_dependency "rake"
20
- spec.add_runtime_dependency "git"
21
20
  spec.add_runtime_dependency "octokit"
22
21
  spec.add_runtime_dependency "httparty"
23
22
  end
@@ -2,6 +2,7 @@ require_relative "fight_club/version"
2
2
  require_relative "fight_club/arena"
3
3
  require_relative "fight_club/config"
4
4
 
5
+
5
6
  module FightClub
6
7
  class << self
7
8
  attr_writer :config, :log
@@ -22,12 +23,4 @@ module FightClub
22
23
  def self.configure
23
24
  yield(config)
24
25
  end
25
-
26
- def self.working_dir
27
- "#{FightClub.config.repos_directory}/repos"
28
- end
29
-
30
- def self.git_command
31
- "git '--git-dir=#{working_dir}/#{config.repo_name}/.git' '--work-tree=#{working_dir}/#{config.repo_name}'"
32
- end
33
26
  end
@@ -1,12 +1,12 @@
1
- require 'git'
2
1
  require 'logger'
3
2
  require 'octokit'
4
3
  require 'httparty'
4
+ require_relative 'git'
5
5
  require_relative 'config'
6
6
  require_relative 'commenter'
7
7
  require_relative 'repository'
8
+ require_relative 'comparer'
8
9
  require_relative 'merger'
9
- require_relative 'rebaser'
10
10
 
11
11
  module FightClub
12
12
  class Arena
@@ -15,20 +15,25 @@ module FightClub
15
15
  end
16
16
 
17
17
  def start
18
- Repository.new.update(FightClub.config.uri, FightClub.config.repo_name)
18
+ Repository.new.update(
19
+ FightClub.config.uri,
20
+ FightClub.config.repo_name,
21
+ "#{FightClub.config.repos_directory}/repos",
22
+ git
23
+ )
19
24
 
20
- git.checkout("origin/#{base_pull["head"]["ref"]}")
25
+ git.checkout("#{base_pull["head"]["ref"]}")
21
26
 
22
27
  return unless base_pull["base"]["ref"] == FightClub.config.master_branch
23
28
 
24
- return unless Rebaser.attempt_rebase(base_pull)
29
+ return unless Merger.attempt_merge(base_pull, git)
25
30
 
26
31
  git.reset_hard("origin/#{base_pull["head"]["ref"]}")
27
32
 
28
33
  pull_requests = client.pull_requests(FightClub.config.repo, :per_page => 200)
29
34
 
30
35
  pull_requests.each do |pr|
31
- Merger.new(base_pull, pr, git).execute
36
+ Comparer.new(base_pull, pr, git).execute
32
37
  end
33
38
 
34
39
  true
@@ -43,7 +48,10 @@ module FightClub
43
48
  end
44
49
 
45
50
  def git
46
- @git ||= Git.open("#{FightClub.working_dir}/#{FightClub.config.repo_name}", log: Logger.new(STDOUT))
51
+ @git ||= Git.new(
52
+ "#{FightClub.config.repos_directory}",
53
+ FightClub.config.repo_name,
54
+ )
47
55
  end
48
56
  end
49
57
  end
@@ -2,17 +2,17 @@ module FightClub
2
2
  class Commenter
3
3
  def self.comment(pr, message)
4
4
  unless FightClub.log[pr["number"]].include? message
5
- HTTParty.post(
6
- pr["_links"]["comments"]["href"],
7
- body: {
8
- body: message,
9
- }.to_json,
10
- headers: {
11
- 'Content-Type' => 'application/json',
12
- 'User-Agent' => 'ruby',
13
- "Authorization" => "token #{FightClub.config.oauth}"
14
- }
15
- )
5
+ #HTTParty.post(
6
+ #pr["_links"]["comments"]["href"],
7
+ #body: {
8
+ #body: message,
9
+ #}.to_json,
10
+ #headers: {
11
+ #'Content-Type' => 'application/json',
12
+ #'User-Agent' => 'ruby',
13
+ #"Authorization" => "token #{FightClub.config.oauth}"
14
+ #}
15
+ #)
16
16
 
17
17
  FightClub.log[pr["number"]] << message
18
18
  Logger.new(STDOUT).info "Left a comment on #{pr["number"]} with message: #{message}"
@@ -0,0 +1,38 @@
1
+ module FightClub
2
+ class Comparer
3
+ def initialize(base_pull, pr, git)
4
+ @base_pull = base_pull
5
+ @pr = pr
6
+ @git = git
7
+ end
8
+
9
+ def execute
10
+ Logger.new(STDOUT).info "Trying to merge #{pr.head.ref} into #{base_pull["head"]["ref"]}..."
11
+ return unless pr.base.ref == FightClub.config.master_branch
12
+ return if pr.head.ref == base_pull["head"]["ref"]
13
+
14
+ git.reset_hard("origin/#{base_pull["head"]["ref"]}")
15
+ git.checkout(pr.head.ref)
16
+ return unless Merger.attempt_merge(pr, git)
17
+
18
+ git.checkout(base_pull["head"]["ref"])
19
+
20
+ Merger.attempt_merge(base_pull, git)
21
+
22
+ unless attempt_to_merge_both_prs(pr.head.ref)
23
+ Commenter.comment(pr, "Your branch currently conflicts with another open pull request: #{base_pull["_links"]["html"]["href"]}")
24
+ Commenter.comment(base_pull, "Your branch currently conflicts with another open pull request: #{pr._links.html.href}")
25
+ end
26
+ end
27
+
28
+ def attempt_to_merge_both_prs(branch)
29
+ result = git.merge("origin/#{branch}")
30
+
31
+ !(result.include? 'CONFLICT')
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :base_pull, :pr, :git
37
+ end
38
+ end
@@ -1,6 +1,7 @@
1
1
  module FightClub
2
2
  class Config
3
- attr_accessor :repo, :oauth, :repo_name, :uri, :master_branch, :repos_directory
3
+ attr_accessor :repo, :oauth, :repo_name,
4
+ :uri, :master_branch, :repos_directory
4
5
 
5
6
  def initialize
6
7
  @repo = 'baxterthehacker/public-repo'
@@ -0,0 +1,47 @@
1
+ module FightClub
2
+ class Git
3
+ def initialize(directory, repo_name, logger = Logger.new(STDOUT))
4
+ @logger = logger
5
+ @directory = directory
6
+ @repo_name = repo_name
7
+ end
8
+
9
+ def clone(target)
10
+ run("git clone #{target} #{directory}/#{repo_name}")
11
+ end
12
+
13
+ def checkout(target)
14
+ run("#{base_command} checkout #{target}")
15
+ end
16
+
17
+ def reset_hard(target)
18
+ run("#{base_command} reset --hard #{target}")
19
+ end
20
+
21
+ def merge(target)
22
+ run("#{base_command} merge -m 'merge' #{target}")
23
+ end
24
+
25
+ def merge_abort
26
+ run("#{base_command} merge --abort")
27
+ end
28
+
29
+ def fetch
30
+ run("#{base_command} fetch")
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :logger, :directory, :repo_name
36
+
37
+ def run(command)
38
+ logger.info("Git executing: #{command}")
39
+
40
+ `#{command}`
41
+ end
42
+
43
+ def base_command
44
+ "git '--git-dir=#{directory}/#{repo_name}/.git' '--work-tree=#{directory}/#{repo_name}'"
45
+ end
46
+ end
47
+ end
@@ -1,36 +1,18 @@
1
1
  module FightClub
2
2
  class Merger
3
- def initialize(base_pull, pr, git)
4
- @base_pull = base_pull
5
- @pr = pr
6
- @git = git
7
- end
8
-
9
- def execute
10
- Logger.new(STDOUT).info "Trying to merge #{pr.head.ref} into #{base_pull["head"]["ref"]}..."
11
- return unless pr.base.ref == FightClub.config.master_branch
12
- return if pr.head.ref == base_pull["head"]["ref"]
3
+ def self.attempt_merge(pr, git)
4
+ git.reset_hard("origin/#{pr["head"]["ref"]}")
5
+ result = git.merge("origin/#{FightClub.config.master_branch}")
13
6
 
14
- git.reset_hard("origin/#{base_pull["head"]["ref"]}")
15
- git.checkout("origin/#{pr.head.ref}")
16
- return unless Rebaser.attempt_rebase(pr)
7
+ if result.include? 'CONFLICT'
8
+ Commenter.comment(pr, 'Your branch is currently conflicting with the target branch. Please resolve all merge conflicts and repush.')
17
9
 
18
- git.checkout("origin/#{base_pull["head"]["ref"]}")
10
+ git.merge_abort
19
11
 
20
- unless attempt_merge(pr)
21
- Commenter.comment(pr, "Your branch currently conflicts with another open pull request: #{base_pull["_links"]["html"]["href"]}")
22
- Commenter.comment(base_pull, "Your branch currently conflicts with another open pull request: #{pr._links.html.href}")
12
+ return false
23
13
  end
24
- end
25
14
 
26
- def attempt_merge(pr)
27
- result = `#{FightClub.git_command} merge origin/#{pr.head.ref}`
28
-
29
- !(result.include? 'CONFLICT')
15
+ true
30
16
  end
31
-
32
- private
33
-
34
- attr_reader :base_pull, :pr, :git
35
17
  end
36
18
  end
@@ -1,14 +1,11 @@
1
1
  module FightClub
2
2
  class Repository
3
- def update(uri, name)
4
- system("mkdir -p #{FightClub.working_dir}/#{name}") unless Dir.exists? "#{FightClub.working_dir}/#{name}"
3
+ def update(uri, name, working_dir, git)
4
+ system("mkdir -p #{working_dir}/#{name}") unless Dir.exists? "#{working_dir}/#{name}"
5
5
 
6
- unless File.exists?("#{FightClub.working_dir}/#{name}/.gitconfig")
7
- Logger.new(STDOUT).info "Cloning using URI: #{uri} | Name: #{name} | Path: #{FightClub.working_dir}"
8
- git = Git.clone(uri, name, :path => FightClub.working_dir)
6
+ unless File.exists?("#{working_dir}/#{name}/.gitconfig")
7
+ git.clone(uri)
9
8
  Logger.new(STDOUT).info "Clone complete!"
10
- else
11
- git = Git.open("#{FightClub.working_dir}/#{name}", :log => Logger.new(STDOUT))
12
9
  end
13
10
 
14
11
  git.fetch
@@ -1,3 +1,3 @@
1
1
  module FightClub
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fight_club
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Minkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: git
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: octokit
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -96,9 +82,10 @@ files:
96
82
  - lib/fight_club.rb
97
83
  - lib/fight_club/arena.rb
98
84
  - lib/fight_club/commenter.rb
85
+ - lib/fight_club/comparer.rb
99
86
  - lib/fight_club/config.rb
87
+ - lib/fight_club/git.rb
100
88
  - lib/fight_club/merger.rb
101
- - lib/fight_club/rebaser.rb
102
89
  - lib/fight_club/repository.rb
103
90
  - lib/fight_club/version.rb
104
91
  - repos/.gitignore
@@ -1,16 +0,0 @@
1
- module FightClub
2
- class Rebaser
3
- def self.attempt_rebase(pr)
4
- result = `#{FightClub.git_command} rebase origin/#{FightClub.config.master_branch}`
5
-
6
- if result.include? 'CONFLICT'
7
- Commenter.comment(pr, 'Your branch is currently conflicting with the target branch. Please resolve all merge conflicts and repush.')
8
- `#{FightClub.git_command} rebase --abort`
9
-
10
- return false
11
- end
12
-
13
- true
14
- end
15
- end
16
- end