Skip to content

New GitHubRepositoryBranchProtectionRule

Howard Wolosky edited this page Oct 5, 2020 · 1 revision

New-GitHubRepositoryBranchProtectionRule

SYNOPSIS

Creates a branch protection rule for a branch on a given GitHub repository.

SYNTAX

Elements (Default)

New-GitHubRepositoryBranchProtectionRule [-OwnerName <String>] [-RepositoryName <String>]
 [-BranchName] <String> [-StatusChecks <String[]>] [-RequireUpToDateBranches] [-EnforceAdmins]
 [-DismissalUsers <String[]>] [-DismissalTeams <String[]>] [-DismissStaleReviews] [-RequireCodeOwnerReviews]
 [-RequiredApprovingReviewCount <Int32>] [-RestrictPushUsers <String[]>] [-RestrictPushTeams <String[]>]
 [-RestrictPushApps <String[]>] [-RequireLinearHistory] [-AllowForcePushes] [-AllowDeletions]
 [-AccessToken <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

Uri

New-GitHubRepositoryBranchProtectionRule [-Uri] <String> [-BranchName] <String> [-StatusChecks <String[]>]
 [-RequireUpToDateBranches] [-EnforceAdmins] [-DismissalUsers <String[]>] [-DismissalTeams <String[]>]
 [-DismissStaleReviews] [-RequireCodeOwnerReviews] [-RequiredApprovingReviewCount <Int32>]
 [-RestrictPushUsers <String[]>] [-RestrictPushTeams <String[]>] [-RestrictPushApps <String[]>]
 [-RequireLinearHistory] [-AllowForcePushes] [-AllowDeletions] [-AccessToken <String>] [-WhatIf] [-Confirm]
 [<CommonParameters>]

DESCRIPTION

Creates a branch protection rules for a branch on a given GitHub repository.

The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub

EXAMPLES

EXAMPLE 1

New-GitHubRepositoryBranchProtectionRule -OwnerName microsoft -RepositoryName PowerShellForGitHub -BranchName master -EnforceAdmins

Creates a branch protection rule for the master branch of the PowerShellForGithub repository enforcing all configuration restrictions for administrators.

EXAMPLE 2

New-GitHubRepositoryBranchProtectionRule -Uri 'https://github.com/microsoft/PowerShellForGitHub' -BranchName master -RequiredApprovingReviewCount 1

Creates a branch protection rule for the master branch of the PowerShellForGithub repository requiring one approving review.

PARAMETERS

-AccessToken

If provided, this will be used as the AccessToken for authentication with the REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.

Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-AllowDeletions

Allows deletion of the protected branch by anyone with write access to the repository.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-AllowForcePushes

Permits force pushes to the protected branch by anyone with write access to the repository.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-BranchName

Name of the specific branch to create the protection rule on.

Type: System.String
Parameter Sets: (All)
Aliases:

Required: True
Position: 3
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-DismissalTeams

Specify which teams can dismiss pull request reviews.

Type: System.String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-DismissalUsers

Specify the user names of users who can dismiss pull request reviews. This can only be specified for organization-owned repositories.

Type: System.String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-DismissStaleReviews

If specified, approving reviews when someone pushes a new commit are automatically dismissed.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-EnforceAdmins

Enforce all configured restrictions for administrators.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-OwnerName

Owner of the repository. If not supplied here, the DefaultOwnerName configuration property value will be used.

Type: System.String
Parameter Sets: Elements
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-RepositoryName

Name of the repository. If not supplied here, the DefaultRepositoryName configuration property value will be used.

Type: System.String
Parameter Sets: Elements
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-RequireCodeOwnerReviews

Blocks merging pull requests until code owners review them.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-RequiredApprovingReviewCount

Specify the number of reviewers required to approve pull requests. Use a number between 1 and 6.

Type: System.Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

-RequireLinearHistory

Enforces a linear commit Git history, which prevents anyone from pushing merge commits to a branch. Your repository must allow squash merging or rebase merging before you can enable a linear commit history.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-RequireUpToDateBranches

Require branches to be up to date before merging. This setting will not take effect unless at least one status check is defined.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-RestrictPushApps

Specify which apps have push access.

Type: System.String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-RestrictPushTeams

Specify which teams have push access.

Type: System.String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-RestrictPushUsers

Specify which users have push access.

Type: System.String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-StatusChecks

The list of status checks to require in order to merge into the branch.

Type: System.String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Uri

Uri for the repository. The OwnerName and RepositoryName will be extracted from here instead of needing to provide them individually.

Type: System.String
Parameter Sets: Uri
Aliases: RepositoryUrl

Required: True
Position: 2
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

GitHub.Repository

GitHub.Branch

OUTPUTS

GitHub.BranchRepositoryRule

NOTES

Protecting a branch requires admin or owner permissions to the repository.

RELATED LINKS

PowerShellForGitHub

Docs

PowerShellForGitHub

Functions

Clone this wiki locally