forked from prontolabs/pronto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract Git::Patches, Git::Repository and Git::Remote
- Loading branch information
Showing
16 changed files
with
121 additions
and
60 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Pronto | ||
module Git | ||
class Patches | ||
include Enumerable | ||
|
||
attr_reader :commit, :repo | ||
|
||
def initialize(repo, commit, patches) | ||
@commit = commit | ||
@patches = patches.map { |patch| Git::Patch.new(patch, repo) } | ||
end | ||
|
||
def each(&block) | ||
@patches.each(&block) | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Pronto | ||
module Git | ||
class Remote < Struct.new(:remote) | ||
def github_slug | ||
match = /.*github.com(:|\/)(?<slug>.*).git/.match(remote.url) | ||
match[:slug] if match | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module Pronto | ||
module Git | ||
class Repository | ||
def initialize(path) | ||
@repo = Rugged::Repository.new(path) | ||
end | ||
|
||
def remotes | ||
@repo.remotes.map { |remote| Remote.new(remote) } | ||
end | ||
|
||
def diff(commit) | ||
merge_base = merge_base(commit) | ||
patches = @repo.diff(merge_base, head) | ||
Patches.new(self, merge_base, patches) | ||
end | ||
|
||
def show_commit(sha) | ||
return [] unless sha | ||
|
||
commit = @repo.lookup(sha) | ||
return [] if commit.parents.count != 1 | ||
|
||
# TODO: Rugged does not seem to support diffing against multiple parents | ||
diff = commit.diff(reverse: true) | ||
return [] if diff.nil? | ||
|
||
Patches.new(self, sha, diff.patches) | ||
end | ||
|
||
def path | ||
@repo.path | ||
end | ||
|
||
def rugged | ||
@repo | ||
end | ||
|
||
private | ||
|
||
def merge_base(commit) | ||
@repo.merge_base(commit, head) | ||
end | ||
|
||
def head | ||
@repo.head.target | ||
end | ||
end | ||
end | ||
end |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
require 'spec_helper' | ||
require 'ostruct' | ||
|
||
module Pronto | ||
module Formatter | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
require 'spec_helper' | ||
require 'ostruct' | ||
|
||
module Pronto | ||
module Formatter | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
require 'spec_helper' | ||
require 'ostruct' | ||
|
||
module Pronto | ||
module Formatter | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'spec_helper' | ||
|
||
module Pronto | ||
module Git | ||
describe Remote do | ||
let(:remote) { Remote.new(double(url: url)) } | ||
|
||
describe '#github_slug' do | ||
subject { remote.github_slug } | ||
|
||
context 'ssh' do | ||
let(:url) { '[email protected]:mmozuras/pronto.git' } | ||
it { should == 'mmozuras/pronto' } | ||
end | ||
|
||
context 'http' do | ||
let(:url) { 'https://github.com/mmozuras/pronto.git' } | ||
it { should == 'mmozuras/pronto' } | ||
end | ||
end | ||
end | ||
end | ||
end |
Empty file.
This file was deleted.
Oops, something went wrong.
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
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