@adityasinghal26/plugin-github-codespaces

中文文档
1.0.4发布于 2024/03/16Apache-2.0TypeScriptCommonJS近 30 天下载 3740

Interact with your GitHub Codespaces directly from Backstage platform.

原始使用文档
文档目录7 节
  1. Features
  2. Screenshots
  3. Setup
  4. Generic Requirements
  5. Standalone app requirements
  6. App menu requirements
  7. Limitations

GitHub Codespaces Plugin

Interact with your GitHub Codespaces directly from Backstage platform.

GitHub Codespaces enable you to create a Devcontainer from your GitHub repository and get in Development mode right away. For more documentation, visit below documentation. You can also view your codespaces by following the website link below after logging in to GitHub.

Documentation: https://docs.github.com/en/codespaces

Website: https://github.com/codespaces

Features

  • Authenticate the user with Github (with 'repo' and 'codespace' permissions)
  • List all the codespaces for authenticated user
  • List codespaces in a project repository for authenticated user
  • List codespaces with display name as entity name for authenticated user
  • Create/Start a new codespace for an entity (with display name as entity name)
  • Pagination for codespaces

Screenshots

  1. GitHub Codespaces Menu

GitHub Codespaces

  1. Start Codespaces Widget

Start Codespaces

  1. Start and List Codespaces Card

Start and List Codespaces

  1. List Codespaces Content (filtered for Entity)

List Codespaces Entity

  1. List Codespaces Content (filtered for Project Repository)

List Codespaces Repository

Setup

Generic Requirements

  1. Provide OAuth credentials:

    1. Create an OAuth App in the GitHub organization with the callback URL set to http://localhost:7007/api/auth/github/handler/frame.
    2. Take the Client ID and Client Secret from the newly created app's settings page and put them into AUTH_GITHUB_CLIENT_ID and AUTH_GITHUB_CLIENT_SECRET environment variables.
  2. Annotate your component with a correct GitHub Actions repository and owner:

    The annotation key is github.com/project-slug.

    Example:

    apiVersion: backstage.io/v1alpha1
    kind: Component
    metadata:
      name: backstage
      description: backstage.io
      annotations:
        github.com/project-slug: 'backstage/backstage'
        # Add below annotation for a custom devcontainer configuration with
        # relative path of devcontainer.json file from root of the repository
        github.com/devcontainer-path: .devcontainer/devcontainer.json 
    spec:
      type: website
      lifecycle: production
      owner: user:guest
    

Standalone app requirements

  1. Install the plugin dependency in your Backstage app package:
# From your Backstage root directory
yarn add --cwd packages/app @adityasinghal26/plugin-github-codespaces
  1. Add to the app EntityPage component:
// In packages/app/src/components/catalog/EntityPage.tsx
import {
  EntityGithubCodespacesWidget,
  EntityGithubCodespacesCard,
  EntityGithubCodespacesContent,
  EntityGithubCodespacesRepoContent
  isGithubCodespacesAvailable,
} from '@adityasinghal26/plugin-github-codespaces';

// Create the codespaces tab content for Github Codespaces
const codespacesContent = (
  <>
    {/* Add this entity switch to view the list 
    of codespaces filtered with entity name */}
    <EntitySwitch>
      <EntitySwitch.Case if={isGithubCodespacesAvailable}>
        <Grid item xs={12}>
          <EntityGithubCodespacesContent />
        </Grid>
      </EntitySwitch.Case>
    </EntitySwitch>
    {/* Add this entity switch to view the list 
    of codespaces filtered with repository */}
    <EntitySwitch>
      <EntitySwitch.Case if={isGithubCodespacesAvailable}>
        <Grid item xs={12}>
          <EntityGithubCodespacesRepoContent />
        </Grid>
      </EntitySwitch.Case>
    </EntitySwitch>
  </>
);

// You can add the overview widget and card to overviewContent as below
// this overview content can be used any number of pages
const overviewContent = (
  <Grid container spacing={3} alignItems="stretch">
    {/* other grids... */}
    {/* Add this entity switch to add the Start Codespace widget  */}
    <EntitySwitch>
      <EntitySwitch.Case if={e => Boolean(isGithubCodespacesAvailable(e))}>
        <Grid item md={6} xs={12}>
          <EntityGithubCodespacesWidget />
        </Grid>
      </EntitySwitch.Case>
    </EntitySwitch>
    {/* Add this entity switch to add the Start and List Codespace card.
    You can set enableStart as 'true' to show the Start Codespace button.
    If left unset or set as 'false', the Start Codespace button will be unavailable.   */}
    <EntitySwitch>
      <EntitySwitch.Case if={e => Boolean(isGithubCodespacesAvailable(e))}>
        <Grid item md={6} xs={12}>
          <EntityGithubCodespacesCard enableStart={true} />
        </Grid>
      </EntitySwitch.Case>
    </EntitySwitch>
  </Grid>
);

// You can add the tab to any number of pages, the service page is shown as an
// example here
const serviceEntityPage = (
  <EntityLayout>
    {/* other tabs... */}
    <EntityLayout.Route 
        if={isGithubCodespacesAvailable} 
        path="/github-codespaces" 
        title="GitHub Codespaces">
      {codespacesContent}
    </EntityLayout.Route>
  1. Run the app with yarn start and the backend with yarn start-backend. Then navigate to /github-codespaces/ under any entity.

App menu requirements

Make sure that the required package is installed as in above section step #1.

  1. Add to the app App.tsx component:

// In packages/app/src/App.tsx
import { GithubCodespacesPage } from '@adityasinghal26/plugin-github-codespaces';

// Add the route to the App path routes
const routes = (
  <FlatRoutes>
  {/* other routes here */}
      <Route path="/github-codespaces" element={<GithubCodespacesPage />} />
  </FlatRoutes>
);
  1. Add to the app Root.tsx component:

// In packages/app/src/components/Root/App.tsx
import { GitHubIcon } from '@backstage/core-components';
import { GithubCodespacesPage } from '@adityasinghal26/plugin-github-codespaces';

// Add the menu to the Root menu sidebar
export const Root = ({ children }: PropsWithChildren<{}>) => (
  <SidebarPage>
    <Sidebar>
    {/* other sidebar items here */}
    {/* add inside "Menu" SidebarGroup */}
      <SidebarItem icon={GitHubIcon} to="github-codespaces" text="Codespaces" />
    {/* other sidebar items here */}
    </Sidebar>
    {children}
  </SidebarPage>
);

Limitations

  • Any codespace started using EntityGithubCodespacesWidget or EntityGithubCodespacesCard action will create a new codespace with the exact same display name as the entity name.
  • Once the codespace is created, you can only start the Codespace from the Widget/Card action.
  • The plugin does not support GitHub Enterprise yet. The feature will be extended in the next releases.

版本与发布记录

@adityasinghal26/plugin-github-codespaces 共发布 8 个版本,首次发布于 2023/12/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.4latest2024/03/162 年前
1.0.32024/01/122 年前
1.0.22024/01/112 年前
1.0.12024/01/052 年前
1.0.02023/12/302 年前
0.1.22023/12/212 年前

关于 @adityasinghal26/plugin-github-codespaces 的常见问题

@adityasinghal26/plugin-github-codespaces 是什么?

Interact with your GitHub Codespaces directly from Backstage platform.

如何安装 @adityasinghal26/plugin-github-codespaces?

在项目目录运行 npm install @adityasinghal26/plugin-github-codespaces,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^16.13.1 || ^17.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@adityasinghal26/plugin-github-codespaces 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adityasinghal26/plugin-github-codespaces 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adityasinghal26/plugin-github-codespaces 可以商用吗?

@adityasinghal26/plugin-github-codespaces 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adityasinghal26/plugin-github-codespaces 的下载量有多少?

根据 npm 官方下载统计,@adityasinghal26/plugin-github-codespaces 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,740 次,日均约 125 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adityasinghal26/plugin-github-codespaces 还在维护吗?

最新版本 1.0.4 发布于 2024/03/16(2 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/12/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。