@roadiehq/backstage-plugin-github-pull-requests
Version:
52 lines (49 loc) • 2.26 kB
JavaScript
import { jsx } from 'react/jsx-runtime';
import { MissingAnnotationEmptyState } from '@backstage/core-components';
import { SkeletonPullRequestsListView, PullRequestsListView } from '../PullRequestsListView/PullRequestsListView.esm.js';
import { useGithubSearchPullRequest } from '../useGithubSearchPullRequest.esm.js';
import { isGithubTeamSlugSet, GITHUB_PULL_REQUESTS_TEAM_ANNOTATION } from '../../utils/isGithubSlugSet.esm.js';
import Alert from '@material-ui/lab/Alert';
import { isGroupEntity } from '@backstage/catalog-model';
import { useEntity } from '@backstage/plugin-catalog-react';
import { getHostname } from '../../utils/githubUtils.esm.js';
import { GitHubAuthorizationWrapper } from '@roadiehq/github-auth-utils-react';
const getPullRequestsQueryForGroup = (entity) => {
const githubTeamName = isGithubTeamSlugSet(entity);
return `is:open is:pr team-review-requested:${githubTeamName} archived:false`;
};
const PullRequestsCard = () => {
const { entity } = useEntity();
const hostname = getHostname(entity);
const query = getPullRequestsQueryForGroup(entity);
const { loading, error, value } = useGithubSearchPullRequest(query, hostname);
if (loading) return /* @__PURE__ */ jsx(SkeletonPullRequestsListView, {});
if (error) return /* @__PURE__ */ jsx(Alert, { severity: "error", children: error.message });
return /* @__PURE__ */ jsx(PullRequestsListView, { data: value, emptyStateText: "No requested reviews." });
};
const Content = () => {
const { entity } = useEntity();
const hostname = getHostname(entity);
const githubTeamName = isGithubTeamSlugSet(entity);
if (!githubTeamName || githubTeamName === "") {
return /* @__PURE__ */ jsx(
MissingAnnotationEmptyState,
{
annotation: GITHUB_PULL_REQUESTS_TEAM_ANNOTATION
}
);
}
if (!isGroupEntity(entity)) {
return /* @__PURE__ */ jsx(Alert, { severity: "error", children: "This card can only be used on Group Entities" });
}
return /* @__PURE__ */ jsx(
GitHubAuthorizationWrapper,
{
title: "GitHub Pull Requests Statistics",
hostname,
children: /* @__PURE__ */ jsx(PullRequestsCard, {})
}
);
};
export { Content, getPullRequestsQueryForGroup };
//# sourceMappingURL=Content.esm.js.map