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

Adding possiblity to get ssh keys #544

Merged
merged 4 commits into from
Sep 30, 2019

Conversation

arngrimur-seal
Copy link

No description provided.

Copy link
Member

@bitwiseman bitwiseman left a comment

Choose a reason for hiding this comment

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

Thanks for contributing!

Solid work with tests.

A few questions/comments, once those are addressed we can merge.

src/main/java/org/kohsuke/github/GHUser.java Show resolved Hide resolved
@@ -36,6 +35,10 @@
*/
public class GHUser extends GHPerson {

public List<GHKey> listKeys() throws IOException {
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/users/"+login+"/keys", GHKey[].class)));
Copy link
Member

Choose a reason for hiding this comment

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

It is possible for there to be multiple pages of keys? I know it is unlikely for some one to have more than a page of keys, but if it is possible it might be better to use a PagedIterable.

Copy link
Author

Choose a reason for hiding this comment

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

I think it is a over kill using PagedIterable, but it is of course possible. Most people only have a single ssh key and less than 10.

Personally I think it better to return a list and instead read all the keys in listKeys() . I can of course iterate until all key have been read

Copy link
Member

Choose a reason for hiding this comment

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

@arngrimur-seal
I see your point.

Okay, I just did a quick review of the code base. Generally, list* methods return PagedIterable<T>. If there is a method that returns a List<T> or a T[] it is called get*.

I think this completely misleading naming, but I'd rather be consistent with the existing naming pattern. So, let's change the name to getKeys(). Then we're good to go.

Copy link
Author

Choose a reason for hiding this comment

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

Not sure I understand, are we good to merge or do you want me to update the code so we make sure all keys has been rtrieved?

Copy link
Member

Choose a reason for hiding this comment

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

Added a suggestion comment above.

@@ -27,4 +26,27 @@ public void listFollowsAndFollowers() throws IOException {
assertEquals(30, users.size());
return users;
}

@Test
public void getKeys() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

This is really great. How was it using this test framework and takeSnapshot? I just added it and would appreciate any feedback you can offer.

Copy link
Author

Choose a reason for hiding this comment

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

It took a while before I understood the framework but then it was simple. Deleting and generating the test data has drawbacks since it is easy do forget about that step but the advantage with test taking lots of time and that data is constant is a greater benefit.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, well, if you have any suggestions for how to make it easier (such as improvements to the CONTRIBUTING.md) that would be great.

@@ -36,6 +35,10 @@
*/
public class GHUser extends GHPerson {

public List<GHKey> listKeys() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public List<GHKey> listKeys() throws IOException {
public List<GHKey> getKeys() throws IOException {

@Test
public void getKeys() throws IOException {
GHUser u = gitHub.getUser("rtyler");
List<GHKey> ghKeys = new ArrayList<>(u.listKeys());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
List<GHKey> ghKeys = new ArrayList<>(u.listKeys());
List<GHKey> ghKeys = new ArrayList<>(u.getKeys());

@bitwiseman bitwiseman merged commit 55f9c40 into hub4j:master Sep 30, 2019
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