Skip to content

Commit

Permalink
Add some new stuffs :)
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusStorhaug committed Sep 18, 2023
1 parent 4c7f012 commit fcdd186
Show file tree
Hide file tree
Showing 39 changed files with 675 additions and 494 deletions.
2 changes: 2 additions & 0 deletions src/GitHub/GitHub.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Author of this module
Author = 'Marius Storhaug'

ModuleVersion = '0.0.1'

# Description of the functionality provided by this module
Description = 'PowerShell Module for GitHub'

Expand Down
2 changes: 2 additions & 0 deletions src/GitHub/private/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
$script:Owner = ''
$script:Repo = ''
$script:Token = ''
$Script:Version = ''
$script:ContentType = 'application/vnd.github+json'
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.PARAMETER Owner
Parameter description
.PARAMETER Repo
Parameter description
.PARAMETER Token
Parameter description
.PARAMETER ID
Parameter description
.EXAMPLE
An example
.NOTES
https://docs.github.com/en/rest/reference/actions#disable-a-workflow
#>
Function Disable-GitHubWorkflow {
Function Disable-GitHubWorkflow {
<#
.NOTES
https://docs.github.com/en/rest/reference/actions#disable-a-workflow
#>
[CmdletBinding()]
param (
[Parameter()]
Expand All @@ -46,17 +25,15 @@ Function Disable-GitHubWorkflow {

process {
$InputObject = @{
Owner = $Owner
Repo = $Repo
Token = $Token
Method = 'PUT'
APIEndpoint = "repos/$Owner/$Repo/actions/workflows/$ID/disable"
APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/disable"
}

$Response = Invoke-GitHubAPI @InputObject

$Response
}
end {
return $Response
}

end {}
}
39 changes: 39 additions & 0 deletions src/GitHub/public/Actions/Enable-GitHubWorkflow.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Function Enable-GitHubWorkflow {
<#
.NOTES
https://docs.github.com/en/rest/reference/actions#enable-a-workflow
#>
[CmdletBinding()]
param (
[Parameter()]
[string] $Owner = $script:Owner,

[Parameter()]
[string] $Repo = $script:Repo,

[Parameter()]
[string] $Token = $script:Token,

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName
)]
[string[]] $ID
)

begin {}

process {
$InputObject = @{
Token = $Token
Method = 'PUT'
APIEndpoint = "/repos/$Owner/$Repo/actions/workflows/$ID/enable"
}

$Response = Invoke-GitHubAPI @InputObject

$Response
}

end {}
}
40 changes: 40 additions & 0 deletions src/GitHub/public/Actions/Get-GitHubWorkflow.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function Get-GitHubWorkflow {
<#
.NOTES
https://docs.github.com/en/rest/reference/actions#list-repository-workflows
#>
[CmdletBinding(DefaultParameterSetName = 'ByName')]
param (
[Parameter()]
[string] $Owner = $script:Owner,

[Parameter()]
[string] $Repo = $script:Repo,

[Parameter()]
[string] $Token = $script:Token,

[Parameter(ParameterSetName = 'ByName')]
[string] $Name,

[Parameter(ParameterSetName = 'ByID')]
[string] $ID,

[Parameter()]
[int] $PageSize = 100
)

$processedPages = 0
$workflows = @()
do {
$processedPages++
$InputObject = @{
Token = $Token
Method = 'GET'
APIEndpoint = "/repos/$Owner/$Repo/actions/workflows?per_page=$PageSize&page=$processedPages"
}
$Response = Invoke-GitHubAPI @InputObject -Verbose
$workflows += $Response.workflows | Where-Object name -Match $name | Where-Object id -Match $id
} while ($workflows.count -ne $Response.total_count)
$workflows
}
47 changes: 47 additions & 0 deletions src/GitHub/public/Actions/Get-GitHubWorkflowRun.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Function Get-GitHubWorkflowRun {
<#
.NOTES
https://docs.github.com/en/rest/reference/actions#list-workflow-runs-for-a-repository
#>
[CmdletBinding()]
param (
[Parameter()]
[string] $Owner = $script:Owner,

[Parameter()]
[string] $Repo = $script:Repo,

[Parameter()]
[string] $Token = $script:Token,

[Parameter(ParameterSetName = 'ByName')]
[string] $Name,

[Parameter(ParameterSetName = 'ByID')]
[string] $ID,

[Parameter()]
[int] $PageSize = 100
)

$processedPages = 0
$workflowRuns = @()
do {
$processedPages++
$InputObject = @{
Token = $Token
Method = 'GET'
APIEndpoint = "/repos/$Owner/$Repo/actions/runs?per_page=$PageSize&page=$processedPages"
}
$Response = Invoke-GitHubAPI @InputObject
$workflowRuns += $Response.workflows | Where-Object name -Match $name | Where-Object id -Match $id
} until ($workflowRuns.count -eq $Response.total_count)
$workflowRuns


do {
$WorkflowRuns = $Response.workflow_runs
$Results += $WorkflowRuns
} while ($WorkflowRuns.count -eq 100)
return $Results | Where-Object Name -Match $Name | Where-Object workflow_id -Match $ID
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
DefaultParameterSetName = 'ByName'
)]
param (
$Owner = $script:Owner,
$Repo = $script:Repo,
$Token = $script:Token ,
[Parameter()]
[string] $Owner = $script:Owner,

[Parameter()]
[string] $Repo = $script:Repo,

[Parameter()]
[string] $Token = $script:Token,

[Parameter(
Mandatory,
ValueFromPipelineByPropertyName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ General notes
function Start-GitHubWorkflow {
[CmdletBinding()]
param (
$Owner = $script:Owner,
$Repo = $script:Repo,
$Token = $script:Token ,
[Parameter()]
[string] $Owner = $script:Owner,

[Parameter()]
[string] $Repo = $script:Repo,

[Parameter()]
[string] $Token = $script:Token,

[Alias('workflow_id')]
[Parameter(
Mandatory,
Expand All @@ -60,7 +66,9 @@ function Start-GitHubWorkflow {
[Parameter()]
[hashtable] $Inputs = @{}
)

begin {}

process {
# API Reference
# https://docs.github.com/en/free-pro-team@latest/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event
Expand All @@ -86,5 +94,6 @@ function Start-GitHubWorkflow {
}
return $Response
}

end {}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
function Start-GitHubWorkflowReRun {
[CmdletBinding()]
param (
$Owner = $script:Owner,
$Repo = $script:Repo,
$Token = $script:Token ,
[Parameter()]
[string] $Owner = $script:Owner,

[Parameter()]
[string] $Repo = $script:Repo,

[Parameter()]
[string] $Token = $script:Token,

[Alias('workflow_id')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName
)]
[string] $ID
)

begin {}

process {
# API Reference
# https://docs.github.com/en/rest/reference/actions#re-run-a-workflow
Expand All @@ -34,5 +42,6 @@
}
return $Response
}

end {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@
[CmdletBinding()]
[alias('Cancel-GitHubWorkflowRun')]
param (
$Owner = $script:Owner,
$Repo = $script:Repo,
$Token = $script:Token ,
[Parameter()]
[string] $Owner = $script:Owner,

[Parameter()]
[string] $Repo = $script:Repo,

[Parameter()]
[string] $Token = $script:Token,

[Alias('workflow_id')]
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName
)]
[string] $ID
)

begin {}

process {
# API Reference
# https://docs.github.com/en/rest/reference/actions#cancel-a-workflow-run
Expand All @@ -35,5 +43,6 @@
}
return $Response
}

end {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
)

$InputObject = @{
Owner = $Owner
Repo = $Repo
Token = $Token
Method = 'Get'
APIEndpoint = "repos/$Owner/$Repo/branches"
APIEndpoint = "/repos/$Owner/$Repo/branches"
}

$Response = Invoke-GitHubAPI @InputObject
Expand Down
46 changes: 0 additions & 46 deletions src/GitHub/public/Connect-GitHubAccount.ps1

This file was deleted.

Loading

0 comments on commit fcdd186

Please sign in to comment.