Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage-community/plugin-github-pull-requests-board': minor
---

Adds a composable home page component to view pull requests for a team's repositories
Copy link
Contributor

Choose a reason for hiding this comment

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

it would de nice to include some lines on the readme on "how to use this home page component"

Copy link
Contributor

Choose a reason for hiding this comment

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

Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"@backstage/frontend-plugin-api": "^0.10.0",
"@backstage/integration": "^1.16.2",
"@backstage/plugin-catalog-react": "^1.16.0",
"@backstage/plugin-home": "^0.8.7",
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove this line as we don't use anything from this package, there's a comment about this in the plugin.ts for full context,

"@backstage/plugin-home-react": "^0.1.25",
Comment on lines +65 to +66
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 Should we generate a different package for this component? something like home-module-github-pull-request-board

maybe the home is quite common, but not sure if is better to not add possible unneeded dependencies

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what you try to ask here @Sarabadu? They need to import this package as it's being used in code, in the plugin.ts file.

"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.61",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ const _default: FrontendPlugin<
defaultTitle: string;
defaultGroup?:
| (string & {})
| 'overview'
| 'documentation'
| 'development'
| 'deployment'
| 'operation'
| 'observability'
| undefined;
routeRef?: RouteRef<AnyRouteRefParams> | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
```ts
/// <reference types="react" />

import { CardExtensionProps } from '@backstage/plugin-home-react';
import { JSX as JSX_2 } from 'react';
import { JSX as JSX_3 } from 'react/jsx-runtime';

// @public (undocumented)
export const EntityTeamPullRequestsCard: (
Expand All @@ -29,5 +31,10 @@ export interface EntityTeamPullRequestsContentProps {
pullRequestLimit?: number;
}

// @public (undocumented)
export const HomePageTeamPullRequestsCard: (
props: CardExtensionProps<unknown>,
) => JSX_3.Element;

// (No @packageDocumentation comment for this package)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 React from 'react';
import { useTeamPullRequestsContext } from './Context';
import { EntityTeamPullRequestsCard } from '../EntityTeamPullRequestsCard';
import Typography from '@material-ui/core/Typography';
import { EntityProvider } from '@backstage/plugin-catalog-react';

export const Content = () => {
const { entity } = useTeamPullRequestsContext();

if (!entity) {
return (
<Typography variant="body1">
Please select a team to view pull requests for
</Typography>
);
}

return (
<EntityProvider entity={entity}>
<EntityTeamPullRequestsCard />
</EntityProvider>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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 type { GroupEntity } from '@backstage/catalog-model';
import { useApi } from '@backstage/frontend-plugin-api';
import {
catalogApiRef,
CATALOG_FILTER_EXISTS,
} from '@backstage/plugin-catalog-react';
import React, {
createContext,
useCallback,
useContext,
useEffect,
useState,
} from 'react';

type TeamPullRequestsContextValue = {
loading: boolean;
handleChangeType: Function;
entity: GroupEntity | null;
teams: GroupEntity[];
};

const TEAM_PULL_REQUEST_STORAGE_KEY = '/home/team-pull-requests-card';

const Context = createContext<TeamPullRequestsContextValue | undefined>(
undefined,
);

export const ContextProvider = (props: { children: JSX.Element }) => {
const { children } = props;

const [loading, setLoading] = useState(false);
const [entity, setEntity] = useState<GroupEntity | null>(() => {
const stored = localStorage.getItem(TEAM_PULL_REQUEST_STORAGE_KEY);
return stored ? JSON.parse(stored) : null;
});
const [teams, setTeams] = useState<GroupEntity[]>([]);

const catalogApi = useApi(catalogApiRef);

const handleChangeType = (group: GroupEntity | null) => {
setEntity(group);
};

const fetchTeams = useCallback(async () => {
const { items: githubTeams } = await catalogApi.getEntities({
filter: {
kind: 'Group',
'metadata.annotations.github.com/team-slug': CATALOG_FILTER_EXISTS,
},
});
setTeams(githubTeams as GroupEntity[]);
}, [catalogApi]);

useEffect(() => {
setLoading(true);
fetchTeams();
setLoading(false);
}, [fetchTeams]);

// Persist entity to localStorage whenever it changes
useEffect(() => {
if (entity) {
localStorage.setItem(
TEAM_PULL_REQUEST_STORAGE_KEY,
JSON.stringify(entity),
);
} else {
localStorage.removeItem(TEAM_PULL_REQUEST_STORAGE_KEY);
}
}, [entity]);

return (
<Context.Provider
value={{
handleChangeType,
loading,
entity,
teams,
}}
>
{children}
</Context.Provider>
);
};

export const useTeamPullRequestsContext = () => {
const context = useContext(Context);
if (!context) {
throw new Error(
'useTeamPullRequestsContext must be used within a ContextProvider',
);
}
return context;
};

export default ContextProvider;
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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 React from 'react';
import { useTeamPullRequestsContext } from './Context';
import FormControl from '@material-ui/core/FormControl';
import FormLabel from '@material-ui/core/FormLabel';
import Autocomplete from '@material-ui/lab/Autocomplete';
import type { GroupEntity } from '@backstage/catalog-model';
import TextField from '@material-ui/core/TextField';

export const Settings = () => {
const { handleChangeType, teams, entity } = useTeamPullRequestsContext();

return (
<FormControl component="fieldset">
<FormLabel component="legend">
Select Team to view pull requests for
</FormLabel>
<Autocomplete
options={teams || []}
getOptionLabel={option =>
`${option.metadata?.annotations?.['github.com/team-slug']}`
}
onChange={(_event, value) => {
handleChangeType(value as GroupEntity);
}}
value={entity}
renderInput={params => <TextField {...params} />}
/>
</FormControl>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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.
*/
export * from './Content';
export * from './Context';
export * from './Settings';
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
export {
EntityTeamPullRequestsCard,
EntityTeamPullRequestsContent,
HomePageTeamPullRequestsCard,
} from './plugin';
export type { EntityTeamPullRequestsCardProps } from './components/EntityTeamPullRequestsCard';
export type { EntityTeamPullRequestsContentProps } from './components/EntityTeamPullRequestsContent';
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
createRoutableExtension,
} from '@backstage/core-plugin-api';
import { rootRouteRef } from './routes';
import { createCardExtension } from '@backstage/plugin-home-react';
import { homePlugin } from '@backstage/plugin-home';
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this line


const githubPullRequestsBoardPlugin = createPlugin({
id: 'github-pull-requests-board',
Expand Down Expand Up @@ -52,3 +54,17 @@ export const EntityTeamPullRequestsContent =
mountPoint: rootRouteRef,
}),
);

/** @public */
export const HomePageTeamPullRequestsCard = homePlugin.provide(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export const HomePageTeamPullRequestsCard = homePlugin.provide(
export const HomePageTeamPullRequestsCard = githubPullRequestsBoardPlugin.provide(

You don't set this on the homePlugin but for the current plugin. Then you can remove line 23 above and the reference to this package in the package.json

createCardExtension({
name: 'HomePageTeamPullRequestsCard',
title: 'GitHub Team Pull Requests',
components: () => import('./components/HomePageTeamPullRequestsCard'),
description: 'Display GitHub pull requests for a team',
layout: {
height: { minRows: 4 },
width: { minColumns: 12 },
},
}),
);
Loading
Loading