This repository was archived by the owner on Feb 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
First pass at using rugged #31
Open
nolman
wants to merge
2
commits into
master
Choose a base branch
from
first-pass-at-using-rugged
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -12,11 +12,21 @@ def emails_in_branch(build) | |
| end | ||
|
|
||
| def changes_since_last_green(build) | ||
| output = GitRepo.inside_repo(build.repository) do | ||
| # TODO: Push this down into GitRepo and integration test it. | ||
| Cocaine::CommandLine.new("git log --no-merges --format='::!::%H|%an <%ae>|%ad|%B::!::' '#{build.previous_successful_build.try(:ref)}...#{build.ref}'").run | ||
| GitRepo.inside_repo(build.repository) do |repo| | ||
| last_green_ref = build.previous_successful_build.try(:ref) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, not quite as concise as the command line and Cocaine, but it reads fairly well and is less arcane. So on the whole I like it. |
||
| current_ref = build.ref | ||
| walker = Rugged::Walker.new(repo) | ||
| walker.sorting(Rugged::SORT_REVERSE) | ||
| if last_green_ref | ||
| walker.push(last_green_ref) | ||
| walker.hide(last_green_ref) | ||
| end | ||
| walker.push(current_ref) | ||
| walker.map do |commit| | ||
| author = commit.author | ||
| {hash: commit.oid, author: "#{author[:name]} <#{author[:email]}>", date: commit.time, message: commit.message.gsub("\n", " ")} | ||
| end | ||
| end | ||
| parse_git_changes(output) | ||
| end | ||
|
|
||
| def changes_in_branch(build) | ||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -69,25 +69,53 @@ | |
| end | ||
|
|
||
| describe "#changes_since_last_green" do | ||
| let!(:last_successful_build) { FactoryGirl.create(:build, state: :succeeded, project: project, ref: first_commit) } | ||
| let(:build) { FactoryGirl.create(:build, project: project, ref: head) } | ||
| let(:head) { repo.last_commit.oid } | ||
| let(:first_commit) { repo.last_commit.parents.first.parents.first.oid } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't know rugged well enough to say whether there is another way to say either "first commit" or a more concise translation of HEAD^^, but this doesn't seem too bad to me. |
||
| let(:commiter) { {email: "bilbo@theshire.com", name: 'Bilbo', time: Time.now} } | ||
| let(:repo) do | ||
| repo = fixture_repo | ||
| 3.times { |i| commit_to(repo, commiter, commit_message.call(i)) } | ||
| repo | ||
| end | ||
| let!(:frozen_time) { freeze_time! } | ||
| subject { GitBlame.changes_since_last_green(build) } | ||
| let(:commit_message) { Proc.new {|i| "Making commit number #{i+1} to the repo!" }} | ||
|
|
||
| before do | ||
| GitBlame.unstub(:changes_since_last_green) | ||
| GitRepo.stub(:inside_repo).and_yield(repo) | ||
| end | ||
|
|
||
| it "should parse the git log message and return a hash of information" do | ||
| GitRepo.stub(:inside_repo).and_return("::!::817b88be7488cab5e4f9d9975222db80d8bceb3b|User One <github+uo@squareup.com>|Fri Oct 19 17:43:47 2012 -0700|this is my commit message::!::") | ||
| git_changes = subject | ||
| git_changes.first[:hash].should == "817b88be7488cab5e4f9d9975222db80d8bceb3b" | ||
| git_changes.first[:author].should == "User One <github+uo@squareup.com>" | ||
| git_changes.first[:date].should == "Fri Oct 19 17:43:47 2012 -0700" | ||
| git_changes.first[:message].should == "this is my commit message" | ||
| context "with no prior green build" do | ||
| let!(:last_successful_build) { nil } | ||
| it "returns all the commits" do | ||
| git_changes = subject | ||
| git_changes.size.should == 3 | ||
| end | ||
| end | ||
|
|
||
| it "should strip new lines in the commit message" do | ||
| GitRepo.stub(:inside_repo).and_return("::!::817b88|User One|Fri Oct 19|this is my commit message\nanother line::!::") | ||
| it "parses the git log message and return a hash of information" do | ||
| git_changes = subject | ||
| git_changes.first[:message].should == "this is my commit message another line" | ||
| git_changes.size.should == 2 | ||
| git_changes.first[:hash].should_not == head | ||
| git_changes.first[:hash].should_not == first_commit | ||
| git_changes.first[:message].should == "Making commit number 2 to the repo!" | ||
|
|
||
| git_changes.last[:hash].should == head | ||
| git_changes.last[:author].should == "Bilbo <bilbo@theshire.com>" | ||
| git_changes.last[:date].to_i.should == frozen_time.to_i | ||
| git_changes.last[:message].should == "Making commit number 3 to the repo!" | ||
| end | ||
|
|
||
| context "with new lines in the commit message" do | ||
| let(:commit_message) { Proc.new {|i| "Making commit number #{i+1} to the\nrepo!" }} | ||
|
|
||
| it "strips the new lines in the commit message" do | ||
| git_changes = subject | ||
| git_changes.last[:message].should == "Making commit number 3 to the repo!" | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under the circumstances, this seems like the version to use. They just aren't making numbered releases with any frequency.