Additional tweaks to protected branch types (#3375)

* Include id as an optional addition for when using the accessLevel property
This commit is contained in:
Justin Dalrymple 2023-08-11 02:17:36 -04:00 committed by GitHub
parent 3aa40e213e
commit 8aa48a5516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 14 deletions

View File

@ -17,8 +17,9 @@ export type CamelizeString<T extends PropertyKey> = T extends string
export type Camelize<T> = { [K in keyof T as CamelizeString<K>]: Camelize<T[K]> };
export type Never<T> = { [P in keyof T]?: never };
export type OneOf<T> = { [K in keyof T]: Pick<T, K> & Never<Omit<T, K>> }[keyof T];
export type Simplify<T> = T extends infer S ? { [K in keyof S]: S[K] } : never;
export type Never<T> = Simplify<{ [P in keyof T]?: never }>;
export type OneOf<T> = { [K in keyof T]: Simplify<Pick<T, K> & Never<Omit<T, K>>> }[keyof T];
export type OneOrNoneOf<T> = Never<T> | OneOf<T>;
export type AllOrNone<T extends Record<string, any>> = T | Partial<Record<keyof T, never>>;

View File

@ -28,21 +28,28 @@ export interface ProtectedBranchSchema extends Record<string, unknown> {
code_owner_approval_required: boolean;
}
export type ProtectedBranchAllowOptions = OneOf<{
user_id: number;
group_id: number;
access_level: number;
export type CreateProtectedBranchAllowOptions = OneOf<{
userId: number;
groupId: number;
accessLevel: ProtectedBranchAccessLevel;
}>;
export type EditsProtectedBranchAllowOptions = {
export type EditProtectedBranchAllowOptions = {
_destroy?: boolean;
} & ProtectedBranchAllowOptions;
} & (
| { userId: number }
| { groupId: number }
| {
accessLevel: ProtectedBranchAccessLevel;
id: number;
}
);
export type CreateProtectedBranchOptions = {
allowForcePush?: boolean;
allowedToMerge?: ProtectedBranchAllowOptions[];
allowedToPush?: ProtectedBranchAllowOptions[];
allowedToUnprotect?: ProtectedBranchAllowOptions[];
allowedToMerge?: CreateProtectedBranchAllowOptions[];
allowedToPush?: CreateProtectedBranchAllowOptions[];
allowedToUnprotect?: CreateProtectedBranchAllowOptions[];
codeOwnerApprovalRequired?: boolean;
mergeAccessLevel?: ProtectedBranchAccessLevel;
pushAccessLevel?: ProtectedBranchAccessLevel;
@ -51,9 +58,9 @@ export type CreateProtectedBranchOptions = {
export type EditProtectedBranchOptions = {
allowForcePush?: boolean;
allowedToMerge?: EditsProtectedBranchAllowOptions[];
allowedToPush?: EditsProtectedBranchAllowOptions[];
allowedToUnprotect?: EditsProtectedBranchAllowOptions[];
allowedToMerge?: EditProtectedBranchAllowOptions[];
allowedToPush?: EditProtectedBranchAllowOptions[];
allowedToUnprotect?: EditProtectedBranchAllowOptions[];
codeOwnerApprovalRequired?: boolean;
};