Codacy Repo Adder logo

Backstage Codacy Repo Adder Plugin

Created by Codacy

Codacy Repo Adder is a small module for Backstage that connects your software templates to Codacy. It adds new repositories to Codacy as part of a scaffolding run so code quality analysis can start from day one without extra steps in your pipeline. The plugin exposes a simple action that your templates can call during creation of a new service. You keep engineers in Backstage while Codacy is set up behind the scenes.

At a high level, the action calls the Codacy API with the repo details and registers the project for analysis. From there, Codacy can scan pull requests and track issues and coverage based on your setup. You decide where this fits in your golden paths. For example, add it to your service template so every new repo is created, published, cataloged, then enrolled in code checks with no manual handoff.

It supports the major Git providers many teams already use. GitHub or GitLab or Bitbucket are covered, which makes adoption smooth in most stacks. This is helpful for platform teams that want consistent guardrails across many repos and for developers who want fast feedback in their normal flow. Use it when you are standardizing new service creation, when you are rolling out organization wide quality rules, or when you want to cut the time from repo create to first scan.

Check out the official announcement here.

Installation Instructions

These instructions apply to self-hosted Backstage only.

Install the package

  1. From your Backstage root. Add the plugin to the app package.

    Copy
    yarn --cwd packages/app add @codacy/backstage-plugin
  2. Add the plugin to the backend package. This is required so the backend can load it.

    Copy
    yarn --cwd packages/backend add @codacy/backstage-plugin

Configure the Codacy API key

  1. Open app-config.yaml in the repository root.

  2. Add your Codacy API key.

    Copy
    codacy:
      apiKey: 'your_codacy_api_key_here'

Register the backend module with the new backend system

  1. Open packages/backend/src/index.ts.

  2. Ensure your backend is created and then add the Codacy module with a single line.

  3. Place the add call next to your other modules.

    Copy
    // packages/backend/src/index.ts
    
    import { createBackend } from '@backstage/backend-defaults';
    
    const backend = createBackend();
    
    // other modules are added here
    backend.add(import('@backstage/plugin-app-backend'));
    backend.add(import('@backstage/plugin-catalog-backend'));
    backend.add(import('@backstage/plugin-scaffolder-backend'));
    
    // register Codacy scaffolder module
    backend.add(import('@codacy/backstage-plugin'));
    
    backend.start();

Register the backend module with the legacy backend

This plugin ships as a module for the new backend system. The legacy backend does not have a supported registration path in this plugin. If you still run the legacy backend, migrate the scaffolder backend to the new system to use this module.

Expose the action in the Scaffolder page

This action runs inside scaffolder templates. Make sure the Scaffolder frontend route is present so users can pick templates.

  1. Open packages/app/src/App.tsx.

  2. Confirm the Scaffolder routes are included. If not, add them.

    Copy
    // packages/app/src/App.tsx
    
    import React from 'react';
    import { apis } from './apis';
    import { AppProvider, AppRouter } from '@backstage/core-app-api';
    import { BrowserRouter } from 'react-router-dom';
    import { Root } from './components/Root';
    
    import { ScaffolderPage, scaffolderPlugin } from '@backstage/plugin-scaffolder';
    
    export const App = () => (
      <AppProvider apis={apis}>
        <BrowserRouter>
          <AppRouter>
            <Root>
              <ScaffolderPage />
            </Root>
          </AppRouter>
        </BrowserRouter>
      </AppProvider>
    );

Add a template that uses the action

You can keep templates in a folder that the catalog watches. A simple option is a single file target.

  1. Create a template file in the repo.

    Copy
    # catalog-templates/codacy-add-repo-template.yaml
    apiVersion: scaffolder.backstage.io/v1beta3
    kind: Template
    metadata:
      name: codacy-add-repo-example
      title: Add repository to Codacy
      description: Adds a repository to Codacy during scaffolding
    spec:
      owner: team
      type: service
      parameters:
        - title: Repository details
          required:
            - repoName
            - owner
            - provider
          properties:
            repoName:
              title: Repository name
              type: string
            owner:
              title: Owner or organization
              type: string
            provider:
              title: Provider
              type: string
              enum:
                - gh
                - gl
                - bb
              description: gh means GitHub. gl means GitLab. bb means Bitbucket
      steps:
        - id: add-repo
          name: Add Repository to Codacy
          action: codacy:add-repo
          input:
            provider: ${{ parameters.provider }}
            owner: ${{ parameters.owner }}
            repository: ${{ parameters.repoName }}
      output:
        links:
          - title: Open Scaffolder tasks
            url: /create
  2. Point the catalog to that file in app-config.yaml if you do not already include it.

    Copy
    catalog:
      locations:
        - type: file
          target: ./catalog-templates/codacy-add-repo-template.yaml

How it works at runtime

  1. The backend module reads codacy.apiKey from config.
  2. During scaffolding the action id codacy add repo calls the Codacy API using that key.
  3. The repository gets added to Codacy for code quality analysis.

Set up Backstage in minutes with Roadie