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 Get Repository.Contents functionality #143

Closed
wants to merge 4 commits into from
Closed

Adding Get Repository.Contents functionality #143

wants to merge 4 commits into from

Conversation

Shazwazza
Copy link
Contributor

@Shazwazza Shazwazza commented Jan 9, 2020

I'm unsure of if you will accept PRs that only implement one part of the functionality. For example, for the Repository.Contents there is: Get, Create/Update, Delete, Get archive link

But I'm really only looking to implement the Get part. Is that ok for a phase 1 approach?

Please let me know what else needs to be considered, i haven't looked at the tests yet so I'm unsure if everything is tested or not.

This PR was replaced by #146

@msftclas
Copy link

msftclas commented Jan 9, 2020

CLA assistant check
All CLA requirements met.

@Shazwazza Shazwazza marked this pull request as ready for review January 9, 2020 07:58
@Shazwazza
Copy link
Contributor Author

I've marked this 'ready' for review since I have this working locally with this code for retrieving file contents, you can pass in -Path to get a single item or leave it out to get the root.

@HowardWolosky HowardWolosky changed the title PR for creating Repository.Contents functionality Adding Get Repository.Contents functionality Jan 10, 2020
Copy link
Member

@HowardWolosky HowardWolosky 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 the submission, @Shazwazza! Welcome to the project.

There's certainly no requirement for a submission to include coverage for all API's within a relevant area. All I ask is that any provided function covers all potential functionality that the API would support for that function, which yours does.

I've called out a number of things that need to be fixed in order to be merged in, but they're mostly pretty minor and shouldn't take much time to address. I would also ask that you include a couple UT's along with your change (testing retrieving the contents of this repo's README.md (as a single file) and the whole contents (as a directory) should be sufficient.

In terms of actual usage though, I'm finding that your method is returning back unexpected results.

I tried this:

Get-GitHubContents -OwnerName Microsoft -RepositoryName PowerShellForGitHub -Path README.md -MediaType Raw

and it returned back to me an array of integers (likely representing each character). Whereas, if I call what should be the equivalent command:

Invoke-GHRestMethodMultipleResult -Description 'Getting Contents' -UriFragment /repos/Microsoft/PowerShellForGitHub/contents/README.md -AcceptHeader 'application/vnd.github.v3.Raw'

Which gives me back the full response. It's not clear to me what is different between those two commands, but I'll leave it to you to figure out and resolve that issue.

Finally, I suggest that include an additional switch that will auto-decode the encoded file contents for users, given how that is a fairly likely scenario.

Thanks again for the contribution! Looking forward to seeing what you do next!

GitHubContents.ps1 Show resolved Hide resolved
GitHubContents.ps1 Outdated Show resolved Hide resolved
GitHubContents.ps1 Outdated Show resolved Hide resolved
GitHubContents.ps1 Show resolved Hide resolved
$telemetryProperties = @{
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
'Path' = $PSBoundParameters.ContainsKey('Path')
Copy link
Member

Choose a reason for hiding this comment

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

There isn't anything that we really gain here from logging Path. There's no change in behavior that we'd make with that data, so given that, we wouldn't log it. What would be interesting would be to log something that differentiates usage for getting a single file vs a directory of files. But Path by itself doesn't need to be logged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this logging it's not really possible to differentiate between whether it's a file or a directory since it's just a name and GitHub figures out if it's a file or directory so we'd only know that based on the results. What do you suggest in this case, should i just remove the Path parameter from being logged? Or do you have another idea?

GitHubContents.ps1 Outdated Show resolved Hide resolved
GitHubContents.ps1 Outdated Show resolved Hide resolved
GitHubContents.ps1 Show resolved Hide resolved
GitHubContents.ps1 Outdated Show resolved Hide resolved
GitHubContents.ps1 Outdated Show resolved Hide resolved
@HowardWolosky HowardWolosky self-assigned this Jan 13, 2020
@Shazwazza
Copy link
Contributor Author

@HowardWolosky thanks for the notes! A bunch of this was copy/pasted (guilty!) so yup there's certainly some left over things lying around. I'll get back to this as soon as i can, cheers!

@Shazwazza
Copy link
Contributor Author

Had pushed some changes and then started writing/running unit tests... unfortunately the GitHubRepositoryForks.tests.ps1 test will delete any fork of this repo that you currently have :P maybe not the most ideal thing when trying to contribute, haha.

I don't think there's another option here except for me to create a new fork and PR and close this one unless you know some other way?

@Shazwazza
Copy link
Contributor Author

Have pushed a new PR here #146

@Shazwazza Shazwazza closed this Feb 4, 2020
@HowardWolosky HowardWolosky added api-contents Work to complete the API's defined here: https://developer.github.com/v3/repos/contents superseded The PR was replaced by a newer PR labels Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-contents Work to complete the API's defined here: https://developer.github.com/v3/repos/contents superseded The PR was replaced by a newer PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants