initial completion
This commit is contained in:
@@ -48,3 +48,92 @@ export function useMergePR(owner: string, repo: string) {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// ─── PR settings ──────────────────────────────────────────────────────────────
|
||||
|
||||
export interface DefaultReviewer {
|
||||
userId: number
|
||||
username: string
|
||||
avatarUrl: string
|
||||
}
|
||||
|
||||
const reviewerSchema = z.object({
|
||||
userId: z.number(),
|
||||
username: z.string(),
|
||||
avatarUrl: z.string(),
|
||||
})
|
||||
const reviewersSchema = z.array(reviewerSchema)
|
||||
|
||||
const descriptionSchema = z.object({ template: z.string() })
|
||||
const excludedFilesSchema = z.object({ patterns: z.string() })
|
||||
|
||||
export function useDefaultReviewers(owner: string, repo: string) {
|
||||
return useQuery({
|
||||
queryKey: ['repos', owner, repo, 'default-reviewers'],
|
||||
queryFn: () =>
|
||||
api.get<DefaultReviewer[]>(`/api/v1/repos/${owner}/${repo}/default-reviewers`, reviewersSchema),
|
||||
enabled: Boolean(owner && repo),
|
||||
})
|
||||
}
|
||||
|
||||
export function useAddDefaultReviewer(owner: string, repo: string) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (username: string) =>
|
||||
api.post<DefaultReviewer>(`/api/v1/repos/${owner}/${repo}/default-reviewers`, reviewerSchema, { username }),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['repos', owner, repo, 'default-reviewers'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useRemoveDefaultReviewer(owner: string, repo: string) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (username: string) =>
|
||||
api.delete(`/api/v1/repos/${owner}/${repo}/default-reviewers/${encodeURIComponent(username)}`, z.any()),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['repos', owner, repo, 'default-reviewers'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useDefaultDescription(owner: string, repo: string) {
|
||||
return useQuery({
|
||||
queryKey: ['repos', owner, repo, 'default-description'],
|
||||
queryFn: () =>
|
||||
api.get<{ template: string }>(`/api/v1/repos/${owner}/${repo}/default-description`, descriptionSchema),
|
||||
enabled: Boolean(owner && repo),
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateDefaultDescription(owner: string, repo: string) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (template: string) =>
|
||||
api.put<{ template: string }>(`/api/v1/repos/${owner}/${repo}/default-description`, descriptionSchema, { template }),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['repos', owner, repo, 'default-description'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useExcludedFiles(owner: string, repo: string) {
|
||||
return useQuery({
|
||||
queryKey: ['repos', owner, repo, 'excluded-files'],
|
||||
queryFn: () =>
|
||||
api.get<{ patterns: string }>(`/api/v1/repos/${owner}/${repo}/excluded-files`, excludedFilesSchema),
|
||||
enabled: Boolean(owner && repo),
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateExcludedFiles(owner: string, repo: string) {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (patterns: string) =>
|
||||
api.put<{ patterns: string }>(`/api/v1/repos/${owner}/${repo}/excluded-files`, excludedFilesSchema, { patterns }),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['repos', owner, repo, 'excluded-files'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user