-
Notifications
You must be signed in to change notification settings - Fork 188
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
Support in Set-GitHubContent to upload binary files #336
Changes from all commits
1b404ef
38a20bd
1865d96
909d8ea
13a260d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,6 +231,9 @@ filter Set-GitHubContent | |
.PARAMETER Content | ||
The new file content. | ||
|
||
.PARAMETER ContentPath | ||
The local path to file content. | ||
|
||
.PARAMETER Sha | ||
The SHA value of the current file if present. If this parameter is not provided, and the | ||
file currently exists in the specified branch of the repo, it will be read to obtain this | ||
|
@@ -323,9 +326,16 @@ filter Set-GitHubContent | |
|
||
[Parameter( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may also want to allow this to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to file an issue for this, or should I? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're not addressing this in this PR, then go ahead and open it up as a suggestion once this PR lands. |
||
Mandatory, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to remain mandatory in its own There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there was a misunderstanding with how I phrased this. It does need to be in its own parameter set, but not at the exclusion of the other required information. For instance, in order to what repo we're changing the content of, we still need to have the information either in the Previously,
You should try running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take a look at |
||
Position = 4)] | ||
Position = 4, | ||
ParameterSetName = 'Content')] | ||
[string] $Content, | ||
|
||
[Parameter( | ||
Mandatory, | ||
Position = 4, | ||
ParameterSetName = 'Content')] | ||
[string] $ContentPath, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[string] $Sha, | ||
|
||
|
@@ -358,7 +368,14 @@ filter Set-GitHubContent | |
|
||
$uriFragment = "/repos/$OwnerName/$RepositoryName/contents/$Path" | ||
|
||
$encodedContent = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Content)) | ||
if ($ContentPath) | ||
{ | ||
$encodedContent = [Convert]::ToBase64String((Get-Content -Path $ContentPath -AsByteStream -Raw)) | ||
} | ||
else | ||
{ | ||
$encodedContent = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Content)) | ||
} | ||
|
||
$hashBody = @{ | ||
message = $CommitMessage | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,6 +335,67 @@ try | |
} | ||
} | ||
|
||
Context 'When setting new file content by path' { | ||
BeforeAll { | ||
$filePath = 'notes' | ||
$fileName = 'hello.txt' | ||
$commitMessage = 'Commit Message' | ||
$content = 'This is the content for test.txt' | ||
$branchName = 'master' | ||
$committerName = 'John Doe' | ||
$committerEmail = '[email protected]' | ||
$authorName = 'Jane Doe' | ||
$authorEmail = '[email protected]' | ||
|
||
$contentPath = New-TemporaryFile | ||
$content | Out-File -FilePath $contentPath | ||
|
||
$setGitHubContentParms = @{ | ||
Path = "$filePath/$fileName" | ||
CommitMessage = $commitMessage | ||
Branch = $branchName | ||
ContentPath = $contentPath | ||
Uri = $repo.svn_url | ||
CommitterName = $committerName | ||
CommitterEmail = $committerEmail | ||
authorName = $authorName | ||
authorEmail = $authorEmail | ||
} | ||
|
||
$result = Set-GitHubContent @setGitHubContentParms -PassThru | ||
} | ||
|
||
It 'Should have the expected type and additional properties' { | ||
$result.PSObject.TypeNames[0] | Should -Be 'GitHub.Content' | ||
$result.content.name | Should -Be $fileName | ||
$result.content.path | Should -Be "$filePath/$fileName" | ||
$result.content.url | Should -Be ("https://api.github.com/repos/$($script:ownerName)" + | ||
"/$repoName/contents/$filePath/$($fileName)?ref=$BranchName") | ||
$result.commit.author.name | Should -Be $authorName | ||
$result.commit.author.email | Should -Be $authorEmail | ||
$result.commit.committer.name | Should -Be $committerName | ||
$result.commit.committer.email | Should -Be $committerEmail | ||
$result.commit.message | Should -Be $commitMessage | ||
} | ||
|
||
It 'Should have written the correct content' { | ||
$getGitHubContentParms = @{ | ||
Path = "$filePath/$fileName" | ||
Uri = $repo.svn_url | ||
MediaType = 'Raw' | ||
ResultAsString = $true | ||
} | ||
|
||
$writtenContent = Get-GitHubContent @getGitHubContentParms | ||
|
||
$content | Should -Be $writtenContent | ||
} | ||
|
||
AfterAll { | ||
Remove-Item -Path $contentPath | ||
} | ||
} | ||
|
||
Context 'When overwriting file content' { | ||
BeforeAll { | ||
$filePath = 'notes' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.