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

New method on RepositoryCommits client - Get the sha1 of a commit reference #1195

Merged
merged 15 commits into from
Mar 22, 2016

Conversation

rogertinsley
Copy link
Contributor

Title
New method on RepositoryCommits client - Get the sha1 of a commit reference. Fixes #1189

Description

  • Add a sha1 method to IRepositoryCommitsClient
  • Add unit and integration tests for this new method
  • Add a sha1 method to IObservableRepositoryCommitsClients
  • Update AcceptHeaders to include the preview http accept header

This is my first foray into contributing to OSS. Any feedback is greatly appreciated.

Updated RepositoryCommitsClients and unit/integration tests
Added implementation for Reactive framework
@rogertinsley rogertinsley changed the title New method on RepositoryCommits client - Get the sha1 of a commit reference #1189 New method on RepositoryCommits client - Get the sha1 of a commit reference Mar 16, 2016
/// <param name="name">The name of the repository</param>
/// <param name="reference">The repository reference</param>
/// <returns></returns>
Task<string> Sha1(string owner, string name, string reference);
Copy link
Member

Choose a reason for hiding this comment

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

Could we add a verb to this method? Say something like GetSha1?

@shiftkey
Copy link
Member

@rogertinsley welcome!

To be perfectly honest, the only bits of feedback I have are minor - this is really nice work!

One suggestion - if you wanted to add another integration test where you:

  • create a repository
  • make a commit through the API, get the new SHA
  • verify the SHA from this new endpoint matches what you got earlier

I think that'll give us enough coverage for this endpoint to close this out.

@rogertinsley
Copy link
Contributor Author

Thanks @shiftkey, I'll make the changes that you've suggested 👍

public class TheSha1Method
{
[Fact]
public async Task EnsureNonNullArguments()
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor note that the wording should be "Ensures" rather than "Ensure". Since the test shoudl read TheGetSha1Method.EnsuresNonNullArguments() 😀

Also this test is checking Null and Empty arguments. In other places ive seen us implement this as 2 test methods eg EnsuresNonNullArguments() and EnsuresNonEmptyArguments()

@ryangribble
Copy link
Contributor

Great first contribution 👏

I agree with @shiftkey regarding adding verb for GetSha1() and the extra integration test (look around for other examples that use the repository context helper to create a repo for the test then automatically clean it up afterwards)...

I've also raised one minor nitpick on consistency/wording in the tests

- Create repository
- Call GetSha1
- Call it a second time
- Verify the two responses are equal
- One unit test for NonNullArguments
- Another unit test for NonEMptyArguments
@M-Zuber
Copy link
Contributor

M-Zuber commented Mar 17, 2016

👏 Nice stuff!
Welcome to OSS 😄

@rogertinsley
Copy link
Contributor Author

I've made the changes you both have suggested.

Are you happy with the integration test approach? I've used a similar approach to other tests in the same class, that is to use CreateTheWorld to create repo & commit. Get the Sha1 and compare that it hasn't changed.

public class TheSha1Method
{
[Fact]
public async void EnsuresNonNullArguments()
Copy link
Member

Choose a reason for hiding this comment

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

Make this async Task as this is more test-runner friendly...

Copy link
Member

Choose a reason for hiding this comment

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

And the CI test won't fail like it currently is...

- CreateTheWorld now returns a Task<Reference>
- This reference is compared with client.GetSha1
@rogertinsley
Copy link
Contributor Author

I've updated CreateTheWorld to return a Task<Reference> and compare it against the GetSha1 and the class TheSha1Method methods should be async

@@ -790,5 +790,40 @@ public void GetsCorrectUrl()
await Assert.ThrowsAsync<ArgumentException>(() => client.EditBranch("owner", "repo", "", update));
}
}

public class TheSha1Method
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be TheGetSha1Method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks - updated it, I'm getting there 😄

@ryangribble
Copy link
Contributor

This looks good!

But I noticed there are no Unit or Integration tests for the ObservableRepositoryCommitsClient.

I realise this was like that before this PR... Some parts of the code base (particularly observable implementations) don't have tests around them, but as we touch these areas ideally we should start to correct that problem. Without tests there really could be something lurking in there making the observable implementation not work and we dont want to find out from end users if possible!

So at a minimum, I'd like to see tests added for the Observable GetSha1() method that has been added... And ideally - tests for ALL the methods in this observable client could be added! 😀

If you have a look at some existing examples of Observable client unit and integration tests you will find that the unit tests of observable would have a CallsIntoClient type test (that checks the underlying regular client method is called with appropriate args), as well as EnsuresNonNullArguments and EnsuresNonEmptyArguments tests as appropriate (depending on what parameters the call takes and whether they have checks for nulls/empty string). Also a test for the Ctor guarding against a null client argument.

Im not sure where @shiftkey stands on integration tests for observable clients - given that alot are missing, and it's pretty much only ever calling the regular client anyway... perhaps all we need are unit tests for observable clients...

But in my contributions I do typically add integration tests, I pretty much copy/paste the regular client test, modify it to use the observable client and also like to write it as per below, so it's obvious the item is an observable (eventhough you could simply await it inline). This is just personal preference.

var observable = _fixture.GetSha1(x,x,x);
var sha1 = await observable;

Added integration test for GetSha1 for observableclient
Check the ctor for a null IGitHubClient
@rogertinsley
Copy link
Contributor Author

I've added unit and integrations tests for the ObservableRepositoryCommitsClient, specifically the GetSha1 method.

@shiftkey
Copy link
Member

Im not sure where @shiftkey stands on integration tests for observable clients - given that alot are missing, and it's pretty much only ever calling the regular client anyway... perhaps all we need are unit tests for observable clients...

This is essentially my views - if the implementation is just calling the Task-based API, then additional integration tests for the Observables are just doubling up. But yes, 👍 to additional unit tests.

@ryangribble
Copy link
Contributor

Oops! Looks like just a minor issue there with the "NotNull" test checking empty strings, and the "NonEmpty" test checking nulls! If you can just fix that up we are good to go

Also given @shiftkey's comment let's ditch the integration test for the observable implementation, since it's just calling the real client anyway. SORRY!

NoNull needs to test null strings and NonEmpty tests empty strings
@rogertinsley
Copy link
Contributor Author

No problem - I've removed the integration test and updated the unit test.

I've learnt a lot about the codebase and how to contribute with this PR and you guys haven't scared me off either 😁 so I'm going to pick up some more up-for-grabs 😄

@shiftkey
Copy link
Member

@rogertinsley this all looks good! I can't wait for the next one.

I'll let @ryangribble have the final word.

@ryangribble
Copy link
Contributor

I've learnt a lot about the codebase and how to contribute with this PR and you guys haven't scared me off either

Great to hear! Bring on the next one, this one LGTM
LGTM

ryangribble added a commit that referenced this pull request Mar 22, 2016
New method on RepositoryCommits client - Get the sha1 of a commit reference
@ryangribble ryangribble merged commit e147837 into octokit:master Mar 22, 2016
@nickfloyd nickfloyd added Type: Feature New feature or request and removed category: feature labels Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants