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/cicd-statistics/.changeset/two-vans-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage-community/plugin-cicd-statistics-module-github': minor
---

Updated Github Authentication methods to prompt for required scopes and refactored auth to align with Backstage GitHub plugin conventions
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ This is an extension module to the `cicd-statistics` plugin, providing a `CicdSt

```tsx
// packages/app/src/apis.ts
import { githubAuthApiRef } from '@backstage/core-plugin-api';
import { configApiRef } from '@backstage/core-plugin-api';
import { scmAuthApiRef } from '@backstage/integration-react';

import { cicdStatisticsApiRef } from '@backstage-community/plugin-cicd-statistics';
import { CicdStatisticsApiGithub } from '@backstage-community/plugin-cicd-statistics-module-github';
Expand All @@ -20,11 +21,11 @@ export const apis: AnyApiFactory[] = [
createApiFactory({
api: cicdStatisticsApiRef,
deps: {
githubAuthApi: githubAuthApiRef,
scmAuthApi: scmAuthApiRef,
configApi: configApiRef,
},
factory: ({ githubAuthApi, configApi }) => {
return new CicdStatisticsApiGithub(githubAuthApi, configApi);
factory: ({ scmAuthApi, configApi }) => {
return new CicdStatisticsApiGithub({ scmAuthApi, configApi });
},
}),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
import { cicdStatisticsApiRef } from '@backstage-community/plugin-cicd-statistics';
import { catalogApiRef } from '@backstage/plugin-catalog-react';
import { CicdStatisticsApiGithub } from '../src/api';
import { configApiRef, githubAuthApiRef } from '@backstage/core-plugin-api';
import { configApiRef } from '@backstage/core-plugin-api';
import { scmAuthApiRef } from '@backstage/integration-react';

createDevApp()
// We need the catalog plugin to get the example entities and make the front entity page functional
Expand Down Expand Up @@ -84,26 +85,34 @@ createDevApp()
}),
)
.registerApi({
api: githubAuthApiRef,
api: scmAuthApiRef,
deps: {},
factory: () => {
return {
getAccessToken: async () => {
getCredentials: async () => {
// This nonsense is only here to make been able to locally test this plugin without having to setup a backend app
return 'THIS_IS_ONLY_FOR_TESTING_LOCALLY_PLEASE_DO_NOT_NEVER_USE_THIS_IN_PRODUCTION';
return {
token:
'THIS_IS_ONLY_FOR_TESTING_LOCALLY_PLEASE_DO_NOT_NEVER_USE_THIS_IN_PRODUCTION',
headers: {},
};
},
} as typeof githubAuthApiRef.T;
} as typeof scmAuthApiRef.T;
},
})
.registerApi({
api: cicdStatisticsApiRef,
deps: {
catalogApiMock: catalogApiRef,
githubAuthApi: githubAuthApiRef,
scmAuthApi: scmAuthApiRef,
configApi: configApiRef,
},
factory: ({ githubAuthApi, configApi }) => {
return new CicdStatisticsApiGithub(githubAuthApi, configApi, {});
factory: ({ scmAuthApi, configApi }) => {
return new CicdStatisticsApiGithub({
scmAuthApi,
configApi,
cicdDefaults: {},
});
},
})
.render();
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@backstage/core-plugin-api": "backstage:^",
"@backstage/frontend-plugin-api": "backstage:^",
"@backstage/integration": "backstage:^",
"@backstage/integration-react": "backstage:^",
"@octokit/rest": "^21.1.1",
"p-limit": "^3.1.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,11 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts
import { AnyApiFactory } from '@backstage/core-plugin-api';
import { ApiFactory } from '@backstage/core-plugin-api';
import { ExtensionBlueprintParams } from '@backstage/frontend-plugin-api';
import { ExtensionDataRef } from '@backstage/frontend-plugin-api';
import { ExtensionDefinition } from '@backstage/frontend-plugin-api';
import { FrontendModule } from '@backstage/frontend-plugin-api';

// @alpha (undocumented)
const cicdStatisticsExtensionOverrides: FrontendModule;
export default cicdStatisticsExtensionOverrides;

// @alpha (undocumented)
export const cicdStatisticsGithubExtension: ExtensionDefinition<{
kind: 'api';
name: 'cicd-statistics-github-api';
config: {};
configInput: {};
output: ExtensionDataRef<AnyApiFactory, 'core.api.factory', {}>;
inputs: {};
params: <
TApi,
TImpl extends TApi,
TDeps extends {
[x: string]: unknown;
},
>(
params: ApiFactory<TApi, TImpl, TDeps>,
) => ExtensionBlueprintParams<AnyApiFactory>;
}>;
const _default: FrontendModule;
export default _default;

// (No @packageDocumentation comment for this package)
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ import { CicdStatisticsApi } from '@backstage-community/plugin-cicd-statistics';
import { ConfigApi } from '@backstage/core-plugin-api';
import { Entity } from '@backstage/catalog-model';
import { FetchBuildsOptions } from '@backstage-community/plugin-cicd-statistics';
import { OAuthApi } from '@backstage/core-plugin-api';
import { Octokit } from '@octokit/rest';
import { ScmAuthApi } from '@backstage/integration-react';

// @public
export class CicdStatisticsApiGithub implements CicdStatisticsApi {
constructor(
githubAuthApi: OAuthApi,
configApi: ConfigApi,
cicdDefaults?: Partial<CicdDefaults>,
);
constructor(options: {
scmAuthApi: ScmAuthApi;
configApi: ConfigApi;
cicdDefaults?: Partial<CicdDefaults>;
});
// (undocumented)
readonly configApi: ConfigApi;
// (undocumented)
createGithubApi(entity: Entity, scopes: string[]): Promise<GithubClient>;
createGithubClient(entity: Entity): Promise<GithubClient>;
// (undocumented)
fetchBuilds(options: FetchBuildsOptions): Promise<CicdState>;
// (undocumented)
Expand All @@ -32,10 +30,8 @@ export class CicdStatisticsApiGithub implements CicdStatisticsApi {

// @public
export type GithubClient = {
api: InstanceType<typeof Octokit>;
octokit: InstanceType<typeof Octokit>;
owner: string;
repo: string;
};

// (No @packageDocumentation comment for this package)
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { cicdStatisticsApiRef } from '@backstage-community/plugin-cicd-statistics';
import {
ApiBlueprint,
configApiRef,
createFrontendModule,
githubAuthApiRef,
} from '@backstage/frontend-plugin-api';
import { CicdStatisticsApiGithub } from './api';
import { createFrontendModule } from '@backstage/frontend-plugin-api';
import { cicdStatisticsGithubApi } from './alpha/index';

/**
* @alpha
*/
export const cicdStatisticsGithubExtension = ApiBlueprint.make({
name: 'cicd-statistics-github-api',
params: defineParams =>
defineParams({
api: cicdStatisticsApiRef,
deps: {
githubAuthApi: githubAuthApiRef,
configApi: configApiRef,
},
factory: ({ githubAuthApi, configApi }) => {
return new CicdStatisticsApiGithub(githubAuthApi, configApi);
},
}),
});

/**
* @alpha
*/
const cicdStatisticsExtensionOverrides = createFrontendModule({
export default createFrontendModule({
pluginId: 'cicd-statistics',
extensions: [cicdStatisticsGithubExtension],
extensions: [cicdStatisticsGithubApi],
});

export default cicdStatisticsExtensionOverrides;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2025 The Backstage Authors
*
* 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.
*/
import { configApiRef, ApiBlueprint } from '@backstage/frontend-plugin-api';
import { scmAuthApiRef } from '@backstage/integration-react';
import { cicdStatisticsApiRef } from '@backstage-community/plugin-cicd-statistics';
import { CicdStatisticsApiGithub } from '../api';

/**
* @alpha
*/
export const cicdStatisticsGithubApi = ApiBlueprint.make({
name: 'cicd-statistics/cicd-statistics-github-api',
params: defineParams =>
defineParams({
api: cicdStatisticsApiRef,
deps: { configApi: configApiRef, scmAuthApi: scmAuthApiRef },
factory: ({ configApi, scmAuthApi }) =>
new CicdStatisticsApiGithub({ configApi, scmAuthApi }),
}),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2024 The Backstage Authors
*
* 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 * from './apis';
Loading