Github Management

github-management.ps1 · Download Script

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# GitHub Management Functions
# Functions for managing GitHub repositories with automated workflows

function Manage-GitHubAppDev {
    <#
    .SYNOPSIS
    Manages GitHub repository development workflow
    
    .DESCRIPTION
    Automates GitHub repository management including commits, tags, and releases
    
    .PARAMETER managerPath
    Path to the GitHub management scripts directory
    
    .PARAMETER appName
    Name of the application/repository
    
    .PARAMETER commitTag
    Tag for the commit (e.g., v1.0.0)
    
    .PARAMETER commitMessage
    Commit message describing changes
    
    .PARAMETER method
    Method to use: 'update', 'init', or 'download'
    
    .EXAMPLE
    Manage-GitHubAppDev -appName "my-app" -commitTag "v0.3.1" -commitMessage "Updated features" -method "update"
    #>
    param (
        [string]$managerPath = "<path/to/github-management-folder>",
        [string]$appName,
        [string]$commitTag,
        [string]$commitMessage,
        [string]$method = "update"
    )
    
    if ($method[0].ToString().ToLower() -eq "u") {
        $method = "update"
    } elseif ($method[0].ToString().ToLower() -eq "i") {
        $method = "init"
    } elseif ($method[0].ToString().ToLower() -eq "d") {
        $method = "download"
    } else {
        Write-Host "Error: Invalid method parameter. Use 'update', 'init', or 'download'." -ForegroundColor Red
        return
    }

    Write-Host "--------------*GITHUB APP MANAGER*---------------------" -ForegroundColor Cyan
    Write-Host "Managing GitHub repository: $appName" -ForegroundColor Cyan
    $confirmation = Read-Host "You are about to make hard to revert changes to '$appName' on your GitHub repository. Type 'y' to continue, any other key to cancel"
    if ($confirmation -ne "y") {
        Write-Host "CANCELLED! Exiting without making changes" -ForegroundColor Red
        return
    }

    $originalDir = Get-Location
    
    Write-Host "--------------------------------------------------------"
    if (Test-Path $managerPath) {
        Set-Location -Path $managerPath
        Write-Host "Changed directory to '$managerPath'."
    } else {
        Write-Host "Directory '$managerPath' does not exist." -ForegroundColor Red
        return
    }
    
    if ($method -eq "update" -or $method -eq "init") {
        $managerApp = "app-manager.ps1"
        
        if ($null -eq $appName -or $appName -eq "" -or
            $null -eq $commitTag -or $commitTag -eq "" -or
            $null -eq $commitMessage -or $commitMessage -eq "") {
            Write-Host "Error: appName, commitTag, and commitMessage parameters are required." -ForegroundColor Red
            Set-Location -Path $originalDir
            return
        }

        $scriptPath = Join-Path $managerPath -ChildPath "$managerApp"
        if (Test-Path $scriptPath) {
            . $scriptPath -appName $appName -commitTag $commitTag -commitMessage $commitMessage -method $method
            Write-Host "Script '$managerApp' executed." -ForegroundColor Green
        } else {
            Write-Host "Script '$managerApp' not found in '$managerPath'." -ForegroundColor Red
        }
    }
    
    Set-Location -Path $originalDir
    Write-Host "--------------------------------------------------------"
}

function Manage-GitTags {
    <#
    .SYNOPSIS
    Manages Git tags for a repository
    
    .DESCRIPTION
    Lists, creates, or deletes Git tags for a repository
    
    .PARAMETER appName
    Name of the application/repository
    
    .PARAMETER commitTag
    Tag name to manage
    
    .PARAMETER method
    Method to use: 'update', 'list', or 'delete'
    
    .EXAMPLE
    Manage-GitTags -appName "my-app" -method "list"
    Manage-GitTags -appName "my-app" -commitTag "v0.3.1" -method "delete"
    #>
    param (
        [string]$managerPath = "<path/to/github-management-folder>",
        [string]$appName,
        [string]$commitTag,
        [string]$method = "list"
    )
    
    Write-Host "-------------*GITHUB TAG MANAGER*----------------------" -ForegroundColor Cyan
    Write-Host "Managing GitHub Tags for repository: $appName" -ForegroundColor Cyan
    
    if ($method[0].ToString().ToLower() -eq "l") {
        $method = "list"
        $managerApp = "tag-list.ps1"
    } elseif ($method[0].ToString().ToLower() -eq "d" -or $method[0].ToString().ToLower() -eq "u") {
        $method = "delete"
        $managerApp = "tag-delete.ps1"
    } else {
        Write-Host "Error: Invalid method parameter. Use 'list', 'delete', or 'update'." -ForegroundColor Red
        return
    }

    $originalDir = Get-Location
    
    if (Test-Path $managerPath) {
        Set-Location -Path $managerPath
    } else {
        Write-Host "Directory '$managerPath' does not exist." -ForegroundColor Red
        return
    }
    
    $scriptPath = Join-Path $managerPath -ChildPath "$managerApp"
    if (Test-Path $scriptPath) {
        . $scriptPath -appName $appName -commitTag $commitTag -method $method
        Write-Host "Script '$managerApp' executed." -ForegroundColor Green
    } else {
        Write-Host "Script '$managerApp' not found." -ForegroundColor Red
    }
    
    Set-Location -Path $originalDir
    Write-Host "--------------------------------------------------------"
}

# Export functions
Export-ModuleMember -Function Manage-GitHubAppDev, Manage-GitTags