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
@@ -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] ?? '';
};