Changed the way project slug is handled in Jenkins plugin

Signed-off-by: Nir Gazit <nir.gzt@gmail.com>
This commit is contained in:
Nir Gazit
2021-03-11 20:50:14 +02:00
parent c8b54c3702
commit e8b2ed9cc6
5 changed files with 15 additions and 13 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-jenkins': minor
---
Changed the way project slug is extracted from an entity. Up until now, the plugin assumed that the project slug is always of the format "owner/repo". However, this is not something that is enforced by Jenkins and sometimes the project name doesn't contain an owner.
Since this split is not used anywhere and the entire project slug is always used as-is, removed this distinction and just read the project slug from the annotation as-is.
@@ -242,9 +242,9 @@ export const CITableView = ({
};
export const CITable = () => {
const { owner, repo } = useProjectSlugFromEntity();
const projectName = useProjectSlugFromEntity();
const [tableProps, { setPage, retry, setPageSize }] = useBuilds(owner, repo);
const [tableProps, { setPage, retry, setPageSize }] = useBuilds(projectName);
return (
<CITableView
@@ -82,8 +82,8 @@ export const LatestRunCard = ({
branch: string;
variant?: InfoCardVariants;
}) => {
const { owner, repo } = useProjectSlugFromEntity();
const [{ builds, loading }] = useBuilds(owner, repo, branch);
const projectName = useProjectSlugFromEntity();
const [{ builds, loading }] = useBuilds(projectName, branch);
const latestRun = builds ?? {};
return (
<InfoCard title={`Latest ${branch} build`} variant={variant}>
+4 -5
View File
@@ -18,7 +18,7 @@ import { useState } from 'react';
import { useAsyncRetry } from 'react-use';
import { jenkinsApiRef } from '../api';
export function useBuilds(owner: string, repo: string, branch?: string) {
export function useBuilds(projectName: string, branch?: string) {
const api = useApi(jenkinsApiRef);
const errorApi = useApi(errorApiRef);
@@ -38,9 +38,9 @@ export function useBuilds(owner: string, repo: string, branch?: string) {
try {
let build;
if (branch) {
build = await api.getLastBuild(`${owner}/${repo}/${branch}`);
build = await api.getLastBuild(`${projectName}/${branch}`);
} else {
build = await api.getFolder(`${owner}/${repo}`);
build = await api.getFolder(`${projectName}`);
}
const size = Array.isArray(build) ? build?.[0].build_num! : 1;
@@ -51,9 +51,8 @@ export function useBuilds(owner: string, repo: string, branch?: string) {
errorApi.post(e);
throw e;
}
}, [api, errorApi, owner, repo, branch]);
}, [api, errorApi, projectName, branch]);
const projectName = `${owner}/${repo}`;
return [
{
page,
@@ -19,8 +19,5 @@ import { JENKINS_ANNOTATION } from '../constants';
export const useProjectSlugFromEntity = () => {
const { entity } = useEntity();
const [owner, repo] = (
entity.metadata.annotations?.[JENKINS_ANNOTATION] ?? ''
).split('/');
return { owner, repo };
return entity.metadata.annotations?.[JENKINS_ANNOTATION] ?? '';
};