Summary
Add a new ensureLabelsExist() function in src/utils/github.ts that checks whether labels exist on a GitHub repo and creates any missing ones.
Context
Child issue of #12. This is the core utility function.
Implementation Details
Function signature
export async function ensureLabelsExist(
labels: string[],
repo?: string
): Promise<string[]> // returns labels that exist or were successfully created
Behavior
- For each label, call
gh api repos/{owner}/{repo}/labels/{label_name} to check existence (URL-encode the label name)
- If a label doesn't exist (404), create it with
gh api -X POST repos/{owner}/{repo}/labels -f name={label} -f color=ededed
- If label creation fails (e.g., 403 permission denied), log a warning and exclude it from the returned list rather than failing
- Return the list of labels that exist or were successfully created
Error Handling
- Label check fails (network error): warn and skip label
- Label creation fails (permission denied): warn and skip label
- Label already exists: include in return list
Acceptance Criteria
Summary
Add a new
ensureLabelsExist()function insrc/utils/github.tsthat checks whether labels exist on a GitHub repo and creates any missing ones.Context
Child issue of #12. This is the core utility function.
Implementation Details
Function signature
Behavior
gh api repos/{owner}/{repo}/labels/{label_name}to check existence (URL-encode the label name)gh api -X POST repos/{owner}/{repo}/labels -f name={label} -f color=edededError Handling
Acceptance Criteria
repoparameter and without (current repo)executeGhCommandcovering all paths