Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for env variable for committed_at in Codeship payload #168

Merged
merged 10 commits into from
Jan 19, 2017

Conversation

antoniobg
Copy link
Contributor

We run into this issue #156 where we couldn't get the test coverage to work unless we included the .git folder in the docker image. We've forked the repository and now we pass an environment variable with the date of the last commit, so we don't need to include that .git folder. Not sure if it's something you want to include in your repository, but just in case I'm creating the PR.

@antoniobg antoniobg changed the title Add support for env variable for COMMITTED in Codeship payload Add support for env variable for committed_at in Codeship payload Jan 18, 2017
Copy link
Contributor

@maxjacobson maxjacobson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @antoniobg, thanks for taking this on. This direction look good overall and I'm happy to cut a new release on the mainline reporter gem so you don't need to maintain a fork :)

committed_at = git("log -1 --pretty=format:%ct")
committed_at.to_i.zero? ? nil : committed_at.to_i
committed_at.nil? ? nil : committed_at.to_i
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe #git will return an empty string, not nil in this case. If that's right, this should remain unchanged

}
end

def branch_from_git_or_ci
clean_service_branch || clean_git_branch || "master"
end

def committed_at_from_ci_or_git
committed_at_from_ci || committed_at_from_git
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change the order of these so git is preferred over CI

@@ -34,9 +38,13 @@ def head
git("log -1 --pretty=format:'%H'")
end

def committed_at
def committed_at_from_ci
Ci.service_data[:committed_at]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we ought to add to_i on this to match committed_at_from_git

@@ -79,5 +79,19 @@ def self.root
end
end

describe 'committed_at_from_ci_or_git' do
it 'returns the committed_at from ci' do
allow(Ci).to receive(:service_data).and_return({committed_at: 'ci-committed_at'})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of ci-committed_at, WDYT about putting a value such as "1484768698" (result of Time.now.to_i.to_s), which is what we expect codeship to set in this environment variable

it "does not raise if there's a committed_at in ci_service data" do
payload[:git][:committed_at] = nil
payload[:ci_service] = {}
payload[:ci_service][:committed_at] = Time.now
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this ought to be Time.now.to_i.to_s to reflect the expected format of this value

@antoniobg
Copy link
Contributor Author

Thank you very much @maxjacobson, I think I've addressed all the issues you mentioned.

Copy link
Contributor

@maxjacobson maxjacobson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antoniobg thanks! will you take a look at the failing build?

expect(Git.committed_at_from_git_or_ci).to eq Git.send(:committed_at_from_git)
end

it 'returns the committed_at from git if there is no ci committed_at' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this scenario description should now be "returns the committed_at from ci if there is no git committed_at"

@antoniobg antoniobg force-pushed the env-var-for-comitted-at branch from 90afdbe to f32a258 Compare January 18, 2017 21:12
@antoniobg
Copy link
Contributor Author

@maxjacobson it failed because it was taken the branch name of this PR pull\168, and the spec was expecting the branch name master.

Copy link
Contributor

@maxjacobson maxjacobson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, yea, some meta things like that come up sometimes 😉

This LGTM -- planning to merge and cut a release soon, but don't have time to do it tonight. Thanks again for working on this!

@antoniobg
Copy link
Contributor Author

No worries and thank you for accepting the PR!

@maxjacobson maxjacobson merged commit 925d5b2 into codeclimate:master Jan 19, 2017
maxjacobson added a commit that referenced this pull request Jan 19, 2017
This is a small follow-up to #168 that I just noticed before cutting the
v1.0.5 release
maxjacobson added a commit that referenced this pull request Jan 19, 2017
This is a small follow-up to #168 that I just noticed before cutting the
v1.0.5 release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants