fix(github-issues): fixes prettier rules

Signed-off-by: Jonathan Nagayoshi <jonathan@nagayoshi.com.br>
This commit is contained in:
Jonathan Nagayoshi
2023-10-02 21:07:32 +00:00
parent 7bd0a8ab3c
commit 1e95687e9f
5 changed files with 64 additions and 32 deletions
@@ -21,13 +21,21 @@ jest.mock('octokit', () => ({
import { ConfigApi, ErrorApi } from '@backstage/core-plugin-api';
import { ForwardedError } from '@backstage/errors';
import { createFilterByClause, githubIssuesApi, Repository, GithubIssuesFilters } from './githubIssuesApi';
import {
createFilterByClause,
githubIssuesApi,
Repository,
GithubIssuesFilters,
} from './githubIssuesApi';
function entityRepository(name: string, locationHostname: string = "github.com"): Repository {
function entityRepository(
name: string,
locationHostname: string = 'github.com',
): Repository {
return {
locationHostname,
name
}
name,
};
}
function getFragment(
filterBy = '',
@@ -133,7 +141,7 @@ describe('githubIssuesApi', () => {
entityRepository('mrwolny/yo-yo'),
entityRepository('mrwolny/yoyo'),
entityRepository('mrwolny/yo.yo'),
entityRepository('mrwolny/another-repo', "enterprise.github.com"), // This one should be filtered out
entityRepository('mrwolny/another-repo', 'enterprise.github.com'), // This one should be filtered out
],
10,
);
@@ -147,7 +155,7 @@ describe('githubIssuesApi', () => {
[
entityRepository('mrwolny/yo-yo'),
entityRepository('mrwolny/yoyo'),
entityRepository('mrwolny/yo.yo')
entityRepository('mrwolny/yo.yo'),
],
10,
{
@@ -369,7 +377,10 @@ describe('githubIssuesApi', () => {
mockErrorApi as unknown as ErrorApi,
);
await api.fetchIssuesByRepoFromGithub([entityRepository('mrwolny/notfound')], 10);
await api.fetchIssuesByRepoFromGithub(
[entityRepository('mrwolny/notfound')],
10,
);
expect(mockErrorApi.post).toHaveBeenCalledTimes(1);
expect(mockErrorApi.post).toHaveBeenCalledWith(
@@ -28,7 +28,7 @@ import { ForwardedError } from '@backstage/errors';
export type Repository = {
name: string;
locationHostname: string;
}
};
/** @internal */
export type Assignee = {
avatarUrl: string;
@@ -123,7 +123,7 @@ export const githubIssuesApi = (
const getOctokit = async () => {
const githubConfig = readGithubIntegrationConfigs(
configApi.getOptionalConfigArray('integrations.github') ?? [],
)[0]
)[0];
const baseUrl = githubConfig.apiBaseUrl;
const token = await githubAuthApi.getAccessToken(['repo']);
@@ -172,8 +172,8 @@ export const githubIssuesApi = (
let issuesByRepo: IssuesByRepo = {};
try {
if(repositories.length === 0) {
throw new Error(`No repositories found for ${hostname}`)
if (repositories.length === 0) {
throw new Error(`No repositories found for ${hostname}`);
}
issuesByRepo = await graphql(
createIssueByRepoQuery(repositories, itemsPerRepo, {
@@ -284,12 +284,12 @@ function createIssueByRepoQuery(
query {
${repositories.map(
({ safeName, name, owner }) => `
({ safeName, name, owner }) => `
${safeName}: repository(name: "${name}", owner: "${owner}") {
...issues
}
`,
)}
)}
}
`;
@@ -68,7 +68,8 @@ const entityComponent = {
metadata: {
annotations: {
'github.com/project-slug': 'backstage/backstage',
'backstage.io/source-location': "url:https://github.com/backstage/backstage"
'backstage.io/source-location':
'url:https://github.com/backstage/backstage',
},
name: 'backstage',
},
@@ -14,7 +14,11 @@
* limitations under the License.
*/
import { Entity, stringifyEntityRef, getEntitySourceLocation } from '@backstage/catalog-model';
import {
Entity,
stringifyEntityRef,
getEntitySourceLocation,
} from '@backstage/catalog-model';
import { useApi } from '@backstage/core-plugin-api';
import { catalogApiRef, useEntity } from '@backstage/plugin-catalog-react';
import { useCallback, useEffect, useState } from 'react';
@@ -27,9 +31,9 @@ export const getProjectNameFromEntity = (entity: Entity): string => {
};
export const getHostnameFromEntity = (entity: Entity): string => {
const { target } = getEntitySourceLocation(entity)
return new URL(target).hostname
}
const { target } = getEntitySourceLocation(entity);
return new URL(target).hostname;
};
export function useEntityGithubRepositories() {
const { entity } = useEntity();
@@ -40,12 +44,14 @@ export function useEntityGithubRepositories() {
const getRepositoriesNames = useCallback(async () => {
if (entity.kind === 'Component' || entity.kind === 'API') {
const entityName = getProjectNameFromEntity(entity);
const locationHostname = getHostnameFromEntity(entity)
const locationHostname = getHostnameFromEntity(entity);
if (entityName) {
setRepositories([{
name: entityName,
locationHostname
}]);
setRepositories([
{
name: entityName,
locationHostname,
},
]);
}
return;
@@ -58,14 +64,24 @@ export function useEntityGithubRepositories() {
},
});
const repositoryEntities: Repository[] = entitiesList.items.reduce((acc: Repository[], componentEntity: Entity) => {
const entityName = getProjectNameFromEntity(componentEntity);
const entityLocationHostname = getHostnameFromEntity(componentEntity);
if (entityName && !acc.some((it: Repository) => it.name === entityName) && entityName.length) {
acc.push({ name: entityName, locationHostname: entityLocationHostname });
}
return acc;
}, []);
const repositoryEntities: Repository[] = entitiesList.items.reduce(
(acc: Repository[], componentEntity: Entity) => {
const entityName = getProjectNameFromEntity(componentEntity);
const entityLocationHostname = getHostnameFromEntity(componentEntity);
if (
entityName &&
!acc.some((it: Repository) => it.name === entityName) &&
entityName.length
) {
acc.push({
name: entityName,
locationHostname: entityLocationHostname,
});
}
return acc;
},
[],
);
setRepositories(repositoryEntities);
}, [catalogApi, entity]);
@@ -16,7 +16,11 @@
import { useApi } from '@backstage/core-plugin-api';
import useAsyncRetry from 'react-use/lib/useAsyncRetry';
import { Repository, githubIssuesApiRef, GithubIssuesByRepoOptions } from '../api';
import {
Repository,
githubIssuesApiRef,
GithubIssuesByRepoOptions,
} from '../api';
export const useGetIssuesByRepoFromGithub = (
repos: Array<Repository>,