Skip to content

Commit c21c5f6

Browse files
committed
remove use of repository api to get repo slug
1 parent 74d320b commit c21c5f6

File tree

3 files changed

+30
-88
lines changed

3 files changed

+30
-88
lines changed

.changeset/hungry-lamps-slide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@roadiehq/backstage-plugin-github-pull-requests': patch
3+
---
4+
5+
Remove use of API to retrieve slug of the repository url.

plugins/frontend/backstage-plugin-github-pull-requests/src/components/PullRequestsListView/PullRequestsListView.tsx

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ import { Box, Grid, Link } from '@material-ui/core';
1717
import { Typography } from '@material-ui/core';
1818
import { getStatusIconType, CommentIcon } from '../Icons';
1919
import { makeStyles } from '@material-ui/core/styles';
20-
import { useGithubRepositoryData } from '../useGithubRepositoryData';
21-
import {
22-
GithubSearchPullRequestsDataItem,
23-
GithubRepositoryData,
24-
} from '../../types';
25-
import Alert from '@material-ui/lab/Alert';
20+
import { GithubSearchPullRequestsDataItem } from '../../types';
2621

2722
import Skeleton from '@material-ui/lab/Skeleton';
2823

@@ -111,18 +106,6 @@ type PullRequestItemProps = {
111106
const PullRequestItem = (props: PullRequestItemProps) => {
112107
const { pr } = props;
113108
const classes = useStyles();
114-
const {
115-
value: repoData,
116-
error,
117-
loading,
118-
}: {
119-
value?: GithubRepositoryData;
120-
error?: Error;
121-
loading: boolean;
122-
} = useGithubRepositoryData(pr.repositoryUrl);
123-
124-
if (loading) return <SkeletonPullRequestItem />;
125-
if (error) return <Alert severity="error">{error.message}</Alert>;
126109

127110
return (
128111
<Grid container item spacing={0} className={classes.pullRequestRow} xs={12}>
@@ -131,34 +114,30 @@ const PullRequestItem = (props: PullRequestItemProps) => {
131114
</Grid>
132115
<Grid item xs={10} className={classes.middleColumn}>
133116
<Typography variant="body1" noWrap className={classes.title}>
134-
{loading ? (
135-
<Skeleton variant="text" />
136-
) : (
137-
<>
138-
{repoData ? (
139-
<Link
140-
className={`${classes.secondaryText} ${classes.link}`}
141-
target="_blank"
142-
rel="noopener noreferrer"
143-
underline="none"
144-
href={repoData.htmlUrl}
145-
>
146-
{repoData.fullName}
147-
</Link>
148-
) : (
149-
<></>
150-
)}
151-
<Link
152-
className={classes.link}
153-
target="_blank"
154-
rel="noopener noreferrer"
155-
underline="none"
156-
href={pr.pullRequest.htmlUrl}
157-
>
158-
{pr.title}
159-
</Link>
160-
</>
161-
)}
117+
<>
118+
<Link
119+
className={`${classes.secondaryText} ${classes.link}`}
120+
target="_blank"
121+
rel="noopener noreferrer"
122+
underline="none"
123+
href={pr.htmlUrl}
124+
>
125+
{new URL(pr.htmlUrl).pathname
126+
.split('/')
127+
.filter(Boolean)
128+
.slice(0, 2)
129+
.join('/')}
130+
</Link>
131+
<Link
132+
className={classes.link}
133+
target="_blank"
134+
rel="noopener noreferrer"
135+
underline="none"
136+
href={pr.pullRequest.htmlUrl}
137+
>
138+
{pr.title}
139+
</Link>
140+
</>
162141
</Typography>
163142
<Typography variant="caption" className={classes.secondaryText}>
164143
#{pr.number} opened by{' '}

plugins/frontend/backstage-plugin-github-pull-requests/src/components/useGithubRepositoryData.tsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)