chris-peterson / pwsh-gitlab

:computer: PowerShell module for GitLab
MIT License
22 stars 10 forks source link

Added support for all documented attributes for protecting a repository branch #45

Closed jonathanmedd closed 2 years ago

jonathanmedd commented 2 years ago

Example use case:

$projectId = "47037290"
$Name = "main"
$PushAccessLevel = "40"
$MergeAccessLevel = "30"
$UnprotectAccessLevel = "30"
$AllowForcePush = $true
$CodeOwnerApprovalRequired = $true

$hash1 = @{
    user_id = 22882083   
}
$hash2 = @{
    user_id = 1264703
}
$hash3 = @{
    user_id = 6204519
}
$AllowedToPush = @($hash1,$hash2)
$AllowedToMerge = @($hash2)
$AllowedToUnprotect = @($hash3)

$protectParams = @{

    ProjectId                 = $projectId
    Name                      = $Name
    PushAccessLevel           = $PushAccessLevel
    MergeAccessLevel          = $MergeAccessLevel
    UnprotectAccessLevel      = $UnprotectAccessLevel
    AllowForcePush            = $AllowForcePush
    CodeOwnerApprovalRequired = $CodeOwnerApprovalRequired
    AllowedToPush             = $AllowedToPush
    AllowedToMerge            = $AllowedToMerge
    AllowedToUnprotect        = $AllowedToUnprotect
}

Protect-GitlabBranch @protectParams
chris-peterson commented 2 years ago

In favor of the change, but I don't like exposing the raw API mechanics (enum literal values, hash structures, etc) In other parts of the API, we've accepted access level by name (with a ValidateSet for autocomplete/input-validation) As for the AllowedTo properties -- a little harder to model as there are 3 possible shapes and 3 different fields -- let me 🤔 about that for a bit

jonathanmedd commented 2 years ago

OK, thanks for the feedback. In the meantime I'll replace the access level values with names.

chris-peterson commented 2 years ago

the granular/specific allowances feels like an uncommon scenario (in fact it was moved to Premium edition in 13.9), I know personally, I've always done role-based access (not specific user/groups)

as such, I'm inclined to go with the approach you had.

I'll keep an eye out for the integer -> string commit and will merge.

thanks again for contributing!

jonathanmedd commented 2 years ago

OK, understood. I actually need the granular levels for an automation requirement at work, hence the need for this contribution.....

Have updated with a more friendly way to supply the access levels. Based the approach on work you've done elsewhere in the project.

chris-peterson commented 2 years ago

This is now published

NOTE: I made a modification to allow the input objects to be PascalCase as that is more idiomatic / consistent with the rest of the CmdLets in this library