Skip to content

Instantly share code, notes, and snippets.

@Satak
Created December 1, 2019 11:25
Show Gist options
  • Save Satak/17b3c4587e5c341d46e422b3710c6bb3 to your computer and use it in GitHub Desktop.
Save Satak/17b3c4587e5c341d46e422b3710c6bb3 to your computer and use it in GitHub Desktop.
Gets file content from repository and deploys that as a Gist
<#
.Synopsis
Gets file content from repository and deploys that as a Gist.
.DESCRIPTION
Used in a GitHub action that automatically deploys your private repository file content as a secret Gist for example.
You must provide GitHub Personal access Token, target Gist ID and Gist filename
.PARAMETER Token
GitHub Personal Access Token with Gist scope
.PARAMETER GistID
GitHub Gist ID
.PARAMETER GistFileName
GitHub Gist filename
.PARAMETER ContentFileName
Local repository filename where you get the content for the Gist
.EXAMPLE
./Invoke-GistDeployment.ps1 -Token ${env:TOKEN} -GistID ${env:GIST_ID} -GistFileName 'secret.md'
#>
param(
[Parameter(Mandatory)]
[String]$Token,
[Parameter(Mandatory)]
[String]$GistID,
[Parameter(Mandatory)]
[String]$GistFileName,
[String]$ContentFileName = 'README.md'
)
[string]$fileContent = Get-Content $ContentFileName -Raw -Encoding utf8
# JSON payload for the GitHub API
$body = @{
"files" = @{
$gistFileName = @{
"content" = $fileContent
}
}
} | ConvertTo-Json
$APIWebRequestParams = @{
Uri = "https://api.github.com/gists/$GistID"
Method = 'Patch'
Body = $body
ContentType = 'application/json; charset=utf-8'
Headers = @{Authorization = "Token $Token"}
}
Invoke-RestMethod @APIWebRequestParams
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment