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 +4 -4
- data/fight-club.gemspec +0 -1
- data/lib/fight_club.rb +1 -8
- data/lib/fight_club/arena.rb +15 -7
- data/lib/fight_club/commenter.rb +11 -11
- data/lib/fight_club/comparer.rb +38 -0
- data/lib/fight_club/config.rb +2 -1
- data/lib/fight_club/git.rb +47 -0
- data/lib/fight_club/merger.rb +8 -26
- data/lib/fight_club/repository.rb +4 -7
- data/lib/fight_club/version.rb +1 -1
- metadata +4 -17
- data/lib/fight_club/rebaser.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a269b42519673bd28d5fa19403da0d94f309b0b1
|
4
|
+
data.tar.gz: 87f3cc35e6e17503dc6202acc4c69c46cfb9ad1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ae27b472c71cbc3dbc4ecee48faa321acc4bdf3099472580ef1bccfc1b9be2fb4fa790303c34ba806fae7e1c303c1a530b0643b3749fd67affc1a38eec070ee
|
7
|
+
data.tar.gz: 4e23480dc43e04799159ff29a0102c2902f62f5df841af3bf4a999699f8fd7b6b53385e2ad5b63bfec356b2de767aa93f2aaa75a7283eb79d6f188e0edb898e1
|
data/fight-club.gemspec
CHANGED
data/lib/fight_club.rb
CHANGED
@@ -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
|
data/lib/fight_club/arena.rb
CHANGED
@@ -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(
|
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("
|
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
|
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
|
-
|
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.
|
51
|
+
@git ||= Git.new(
|
52
|
+
"#{FightClub.config.repos_directory}",
|
53
|
+
FightClub.config.repo_name,
|
54
|
+
)
|
47
55
|
end
|
48
56
|
end
|
49
57
|
end
|
data/lib/fight_club/commenter.rb
CHANGED
@@ -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
|
data/lib/fight_club/config.rb
CHANGED
@@ -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
|
data/lib/fight_club/merger.rb
CHANGED
@@ -1,36 +1,18 @@
|
|
1
1
|
module FightClub
|
2
2
|
class Merger
|
3
|
-
def
|
4
|
-
|
5
|
-
|
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
|
-
|
15
|
-
|
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
|
-
|
10
|
+
git.merge_abort
|
19
11
|
|
20
|
-
|
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
|
-
|
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 #{
|
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?("#{
|
7
|
-
|
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
|
data/lib/fight_club/version.rb
CHANGED
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.
|
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-
|
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
|
data/lib/fight_club/rebaser.rb
DELETED
@@ -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
|