Skip to content

Add ensureLabelsExist() utility function to github.ts #14

Description

@helixclaw

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

  1. For each label, call gh api repos/{owner}/{repo}/labels/{label_name} to check existence (URL-encode the label name)
  2. If a label doesn't exist (404), create it with gh api -X POST repos/{owner}/{repo}/labels -f name={label} -f color=ededed
  3. If label creation fails (e.g., 403 permission denied), log a warning and exclude it from the returned list rather than failing
  4. 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

  • Function checks for label existence via GitHub API
  • Missing labels are created with a default color
  • Permission errors handled gracefully (warn + skip)
  • Works with explicit repo parameter and without (current repo)
  • Unit tests with mocked executeGhCommand covering all paths

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions