Skip to content

Adding possiblity to get ssh keys#544

Merged
bitwiseman merged 4 commits into
hub4j:masterfrom
seal-software:getKeysForUser
Sep 30, 2019
Merged

Adding possiblity to get ssh keys#544
bitwiseman merged 4 commits into
hub4j:masterfrom
seal-software:getKeysForUser

Conversation

@arngrimur-seal
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown
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.

Comment thread src/main/java/org/kohsuke/github/GHUser.java
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

}

@Test
public void getKeys() throws IOException {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

*/
public class GHUser extends GHPerson {

public List<GHKey> listKeys() throws IOException {
Copy link
Copy Markdown
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
Copy Markdown
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