Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions workspaces/scorecard/.changeset/add-codecov-module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-codecov': minor
---

Add new codecov backend module for the scorecard plugin with 7 code coverage metrics.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
description: A collection of all the scorecards
spec:
targets:
- ./components/codecov-scorecard-only.yaml
- ./components/dependabot-scorecard-only.yaml
- ./components/github-scorecard-only.yaml
- ./components/jira-scorecard-only.yaml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
# Component with Codecov Scorecard only
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: codecov-scorecard-only
annotations:
codecov.io/repo: redhat-developer/rhdh-plugins
github.com/project-slug: redhat-developer/rhdh-plugins
spec:
type: service
owner: group:development/guests
lifecycle: experimental
1 change: 1 addition & 0 deletions workspaces/scorecard/packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@backstage/plugin-search-backend-node": "^1.4.2",
"@backstage/plugin-techdocs-backend": "^2.1.6",
"@red-hat-developer-hub/backstage-plugin-scorecard-backend": "workspace:^",
"@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-codecov": "workspace:^",
"@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-dependabot": "workspace:^",
"@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-filecheck": "workspace:^",
"@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-github": "workspace:^",
Expand Down
27 changes: 9 additions & 18 deletions workspaces/scorecard/packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,25 @@ backend.add(
import('@red-hat-developer-hub/backstage-plugin-scorecard-backend'),
);
backend.add(
import(
'@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-github'
),
import('@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-github'),
);
backend.add(
import(
'@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-jira'
),
import('@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-jira'),
);
backend.add(
import(
'@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-filecheck'
),
import('@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-filecheck'),
);
backend.add(
import(
'@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-openssf'
),
import('@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-openssf'),
);
backend.add(
import(
'@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-dependabot'
),
import('@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-codecov'),
);
backend.add(
import(
'@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-sonarqube'
),
import('@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-dependabot'),
);
backend.add(
import('@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-sonarqube'),
);
backend.add(import('@backstage/plugin-mcp-actions-backend'));
backend.start();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Scorecard Backend Module: Codecov

Adds [Codecov](https://about.codecov.io/) code coverage metrics to the scorecard plugin. All 7 metrics are fetched from a single Codecov API call per entity.

## Metrics

| Metric ID | Type | Description |
| ------------------------ | ------ | --------------------------------------- |
| `codecov.coverage` | number | Current code coverage percentage |
| `codecov.coverage_trend` | number | Code coverage trend for the last 7 days |
| `codecov.tracked_files` | number | Number of files tracked by Codecov |
| `codecov.tracked_lines` | number | Total lines of code tracked by Codecov |
| `codecov.covered_lines` | number | Number of lines covered by tests |
| `codecov.partial_lines` | number | Number of partially covered lines |
| `codecov.missed_lines` | number | Number of lines not covered by tests |

## Installation

```bash
yarn workspace backend add @red-hat-developer-hub/backstage-plugin-scorecard-backend-module-codecov
```

Then register the module in your backend:

```ts
// packages/backend/src/index.ts
backend.add(
import('@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-codecov'),
);
```

## Entity annotation

Entities need the `codecov.io/repo` annotation to opt in:

```yaml
metadata:
annotations:
codecov.io/repo: owner/repo
```

The module resolves the Codecov service from the entity's annotations. If the entity also has a `github.com/project-slug` annotation, the service defaults to `github`. Otherwise, set the service explicitly:

```yaml
metadata:
annotations:
codecov.io/repo: owner/repo
codecov.io/service: github
```

### Optional annotations

| Annotation | Description |
| -------------------- | ---------------------------------------------------------------------------------------------------------- |
| `codecov.io/repo` | **Required.** The Codecov repository in `owner/repo` or `repo` format. |
| `codecov.io/service` | Git hosting service (`github`, `gitlab`, `bitbucket`). Inferred from `github.com/project-slug` if present. |
| `codecov.io/owner` | Override the repository owner (if not using `owner/repo` format). |
| `codecov.io/account` | Codecov account name for multi-account setups (maps to config accounts). |

## Configuration

Configuration is optional for public repositories. For private repositories, configure an auth token:

```yaml
# app-config.yaml
codecov:
accounts:
- name: default
authToken: ${CODECOV_API_TOKEN}
```

### Multiple accounts

```yaml
# app-config.yaml
codecov:
defaultAccount: primary
accounts:
- name: primary
authToken: ${CODECOV_PRIMARY_TOKEN}
- name: oss
# authToken optional for public repos
```

Then set the `codecov.io/account` annotation on entities to route them to the correct account:

```yaml
metadata:
annotations:
codecov.io/repo: owner/repo
codecov.io/account: oss
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export interface Config {
/** Optional configurations for the Codecov plugin */
codecov?: {
/**
* The default account name to use when the codecov.io/account annotation is not set.
* Defaults to "default".
* @visibility frontend
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] scope-alignment

The defaultAccount field is marked @visibility frontend, but this is a backend-only module with no frontend counterpart.

defaultAccount?: string;

/**
* The list of codecov accounts.
*/
accounts?: Array<{
/**
* The name of the codecov account.
* @visibility frontend
*/
name: string;

/**
* The auth token for the codecov account. Optional for public repositories.
* @visibility secret
*/
authToken?: string;
}>;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-codecov",
"version": "0.0.0",
"license": "Apache-2.0",
"description": "The codecov backend module for the scorecard plugin.",
"main": "src/index.ts",
"types": "src/index.ts",
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/redhat-developer/rhdh-plugins",
"directory": "workspaces/scorecard/plugins/scorecard-backend-module-codecov"
},
"backstage": {
"role": "backend-plugin-module",
"pluginId": "scorecard",
"pluginPackage": "@red-hat-developer-hub/backstage-plugin-scorecard-backend"
},
"scripts": {
"start": "backstage-cli package start",
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"clean": "backstage-cli package clean",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@backstage/backend-plugin-api": "^1.8.0",
"@backstage/catalog-client": "^1.14.0",
"@backstage/catalog-model": "^1.7.7",
"@backstage/config": "^1.3.6",
"@red-hat-developer-hub/backstage-plugin-scorecard-common": "workspace:^",
"@red-hat-developer-hub/backstage-plugin-scorecard-node": "workspace:^"
},
"devDependencies": {
"@backstage/backend-test-utils": "^1.11.1",
"@backstage/cli": "^0.36.0"
},
"configSchema": "config.d.ts",
"files": [
"config.d.ts",
"dist"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## API Report File for "@red-hat-developer-hub/backstage-plugin-scorecard-backend-module-codecov"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts
import { BackendFeature } from '@backstage/backend-plugin-api';

// @public (undocumented)
const scorecardModuleCodecov: BackendFeature;
export default scorecardModuleCodecov;
```
Loading
Loading