logo
0
0
WeChat Login

CNB GitHub Migration Plugin

One-click migration of GitHub repositories to CNB, with support for code and Release migration.

中文文档


Features

  • Auto-detect if CNB repository exists, create if not
  • Create repository on CNB (auto-sync description, license, visibility)
  • Mirror push all branches and tags via git push --mirror
  • Incremental migration of GitHub Releases with assets (existing Releases are skipped, missing assets are auto-uploaded)
  • Sync GitHub Release markings to CNB (Latest and Pre-release labels match GitHub)
  • Sync repository Topics and Homepage
  • Support migrating public repos without a GitHub Token

Docker Direct Usage

Besides using in pipelines, you can also call this plugin directly via docker run:

docker run --rm \
  -e TZ=Asia/Shanghai \
  -e PLUGIN_CNB_TOKEN='cnb_xxxx' \
  -e PLUGIN_GITHUB_REPO='owner/repo' \
  -e PLUGIN_CNB_SLUG='your-cnb-org-slug' \
  -e PLUGIN_GITHUB_TOKEN='ghp_xxxx' \
  -e PLUGIN_CNB_REPO_NAME='your-cnb-repo-name' \
  -e PLUGIN_MIGRATE_RELEASES='true' \
  -e PLUGIN_VISIBILITY='private' \
  docker.cnb.cool/dailybo/github2cnb:latest

Note: cnb_token is required, needing repo-contents:r and repo-code:rw permissions. For public repositories, github_token can be omitted.


Usage

Use in .cnb.yml pipeline configuration:

main:
  push:
    - stages:
      - name: migrate-to-cnb
        image: docker.cnb.cool/your-org/github-to-cnb:latest
        settings:
          github_repo: owner/repo
          cnb_slug: your-cnb-org-slug
          # cnb_token: cnb_xxxx           # Optional, required for cross-org operations
          # github_token: ghp_xxxx        # Optional, required for private repos
          # cnb_repo_name: custom-name  # Optional, defaults to GitHub repo name
          # migrate_releases: true      # Optional, defaults to true
          # visibility: private         # Optional, defaults to private

Parameter Configuration

ParameterTypeRequiredDefaultDescription
github_repostringYes-GitHub repository address, format owner/repo
cnb_slugstringYes-CNB organization slug
cnb_tokenstringDocker requiredPipeline auto-providedCNB access token, required for cross-org operations
github_tokenstringPrivate repos required-GitHub Personal Access Token
cnb_repo_namestringNoGitHub repo nameCNB repository name
migrate_releasesbooleanNotrueWhether to migrate Releases
visibilitystringNoprivateRepository visibility

github_repo

  • Type: string
  • Required: Yes
  • Description: GitHub repository address in owner/repo format.

Example:

settings:
  github_repo: "octocat/hello-world"

cnb_slug

  • Type: string
  • Required: Yes
  • Description: CNB organization slug, used to specify the target organization for repository creation.

Example:

settings:
  cnb_slug: "my-org"

cnb_token

  • Type: string
  • Required: Required for Docker, auto-provided in pipeline
  • Default: Pipeline-provided CNB_TOKEN
  • Description: CNB access token, requiring repo-contents:r and repo-code:rw permissions. Auto-provided in pipelines; required for Docker direct usage; must be specified for cross-organization operations with a token that has target organization permissions.

Example:

settings:
  cnb_token: "cnb_xxxxxxxxxxxx"

github_token

  • Type: string
  • Required: No (required for private repos)
  • Default: None
  • Description: GitHub Personal Access Token. Can be omitted for public repos; required for private repos with repo permission.

Example:

settings:
  github_token: "ghp_xxxxxxxxxxxx"

cnb_repo_name

  • Type: string
  • Default: GitHub repository name
  • Required: No
  • Description: CNB repository name. Defaults to the GitHub repository name if not specified.

Example:

settings:
  cnb_repo_name: "my-custom-repo"

migrate_releases

  • Type: boolean
  • Default: true
  • Required: No
  • Description: Whether to migrate GitHub Releases with assets. Supports incremental migration — existing Releases are skipped and missing assets are auto-uploaded. Also syncs Latest and Pre-release labels from GitHub to CNB.

Example:

settings:
  migrate_releases: false

visibility

  • Type: string
  • Default: private
  • Required: No
  • Description: CNB repository visibility, options are private or public. Only takes effect when creating a new repository; existing repositories will not be modified.

Example:

settings:
  visibility: "public"

Output Variables

After migration, the following pipeline variables are output:

##[set-output github2cnb-repo-url=https://cnb.cool/my-org/my-repo]
##[set-output github2cnb-repo-slug=my-org/my-repo]

Can be referenced in subsequent steps via @{github2cnb-repo-url} and @{github2cnb-repo-slug}.


Full Example

main:
  push:
    - stages:
      - name: migrate-to-cnb
        image: docker.cnb.cool/your-org/github-to-cnb:latest
        settings:
          github_repo: octocat/hello-world
          cnb_slug: my-org
          migrate_releases: true
          visibility: public
        exports:
          github2cnb-repo-url: GITHUB2CNB_REPO_URL
          github2cnb-repo-slug: GITHUB2CNB_REPO_SLUG
      - name: echo result
        script:
          - echo "GITHUB2CNB_REPO_URL $GITHUB2CNB_REPO_URL"
          - echo "GITHUB2CNB_REPO_SLUG $GITHUB2CNB_REPO_SLUG"

Migration Flow

  1. Fetch GitHub repository info (description, license, topics, etc.)
  2. Check if CNB repository exists, auto-create if not
  3. Mirror push code via git clone --bare + git push --mirror
  4. Update CNB repository info (Topics, Homepage)
  5. Incrementally migrate GitHub Releases: fetch existing CNB Releases, skip already-created ones and upload missing assets, create new Releases normally. Sync Latest and Pre-release labels — the last non-Draft non-Pre-release Release is marked as Latest

Error Handling

On API errors or missing parameters, the plugin will exit with a non-zero status code, causing the pipeline to fail.


License

MIT License

About

CNB GitHub迁移插件,一键将GitHub仓库迁移至CNB。核心功能:git push --mirror镜像推送分支与标签;增量迁移Release及附件,已有跳过、缺失补传,同步Latest/Pre-release标记;同步仓库描述、许可证、可见性、Topics与Homepage;CNB仓库不存在则自动创建;公开仓库无需GitHub Token。支持流水线插件和Docker调用,输出仓库URL及slug供后续引用。

Language
Go98.4%
Dockerfile1.6%