Skip to content

Zoomicon/CopyGitHubLabels

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CopyGitHubLabels

A small toolkit to copy GitHub repository label definitions (name, color, description) from one repository to another. The repository includes three platform-specific scripts with the same behavior and similar command syntax.


Scripts

Filename Platform Language Invocation
CopyGitHubLabels.sh Unix / macOS Bash ./CopyGitHubLabels.sh
CopyGitHubLabels.py Cross platform Python 3 python3 CopyGitHubLabels.py
CopyGitHubLabels.ps1 Cross platform (Windows/macOS/Linux) PowerShell 7+ (also works on Windows PowerShell) Windows: .\CopyGitHubLabels.ps1 • Unix/macOS: ./CopyGitHubLabels.ps1 (run in pwsh)

Usage Examples

PowerShell

Interactive prompts if defaults are not set

.\CopyGitHubLabels.ps1    (Windows)
./CopyGitHubLabels.ps1    (Unix/macOS in pwsh)

Provide all parameters

.\CopyGitHubLabels.ps1 -SrcOwner myorg -SrcRepo source-repo -DstOwner myorg -DstRepo dest-repo

Dry run

.\CopyGitHubLabels.ps1 -DryRun

Verbose logging

.\CopyGitHubLabels.ps1 -VerboseLogging

Bash

Interactive prompts if defaults are not set

./CopyGitHubLabels.sh

Provide all parameters

./CopyGitHubLabels.sh --src-owner myorg --src-repo source-repo --dst-owner myorg --dst-repo dest-repo

Dry run

./CopyGitHubLabels.sh --src-owner myorg --src-repo src --dst-owner myorg --dst-repo dst --dry-run

Verbose

./CopyGitHubLabels.sh --src-owner myorg --src-repo src --dst-owner myorg --dst-repo dst --verbose

Python

Interactive prompts if defaults are not set

python3 CopyGitHubLabels.py

Provide all parameters

python3 CopyGitHubLabels.py --src-owner myorg --src-repo source-repo --dst-owner myorg --dst-repo dest-repo

Dry run

python3 CopyGitHubLabels.py --dry-run

Verbose

python3 CopyGitHubLabels.py --verbose

Behavior Details

  • What is copied
    The scripts copy label definitions only: name, color, and description for each label defined in the source repository.

  • What is not copied
    The scripts do not copy which labels are applied to individual issues or pull requests. They do not touch Git tags or commit metadata.

  • Interactive prompts and defaults
    Each script contains top-of-file defaults you can edit. If a parameter is not supplied on the command line and the corresponding default is empty, the script will prompt you interactively for that value. If you set a non-empty default in the script, that value will be used unless overridden on the command line.

  • Update strategy
    For each label the scripts attempt to PATCH (update) the destination label first. If the PATCH indicates the label does not exist (HTTP 404 / Not Found), the scripts POST (create) the label in the destination repository.

  • Common options

    • Dry run: shows the actions the script would take without making changes (--dry-run for shell/python, -DryRun for PowerShell).
    • Verbose: prints API output for debugging (--verbose for shell/python, -VerboseLogging for PowerShell).

Notes and Recommendations

  • File naming
    Filenames use CopyGitHubLabels (no dashes) to match the chosen convention. Keep the extension to indicate the runtime: .sh, .py, .ps1.

  • Permissions
    Ensure the account used by the gh CLI has permission to read labels in the source repo and create/update labels in the destination repo.

  • Noninteractive environments
    If you run these scripts in CI or other noninteractive environments, set the top-of-file defaults or pass all required parameters on the command line to avoid prompts.

  • Cross-platform PowerShell notes

    • Unix/macOS: Make the script executable with chmod +x CopyGitHubLabels.ps1, then run ./CopyGitHubLabels.ps1 in pwsh.
    • Windows: Run with Windows PowerShell (powershell.exe) or PowerShell 7 (pwsh.exe): .\CopyGitHubLabels.ps1.

About

Copy Labels from one GitHub repository to another

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

No packages published