diff --git a/.changeset/warm-cows-wait.md b/.changeset/warm-cows-wait.md new file mode 100644 index 0000000000000..2029e38b3fa62 --- /dev/null +++ b/.changeset/warm-cows-wait.md @@ -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. diff --git a/plugins/jenkins/src/components/BuildsPage/lib/CITable/CITable.tsx b/plugins/jenkins/src/components/BuildsPage/lib/CITable/CITable.tsx index 3044094ccce03..57ffe48649205 100644 --- a/plugins/jenkins/src/components/BuildsPage/lib/CITable/CITable.tsx +++ b/plugins/jenkins/src/components/BuildsPage/lib/CITable/CITable.tsx @@ -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 ( { - const { owner, repo } = useProjectSlugFromEntity(); - const [{ builds, loading }] = useBuilds(owner, repo, branch); + const projectName = useProjectSlugFromEntity(); + const [{ builds, loading }] = useBuilds(projectName, branch); const latestRun = builds ?? {}; return ( diff --git a/plugins/jenkins/src/components/useBuilds.ts b/plugins/jenkins/src/components/useBuilds.ts index a1ff3a1eef79c..5a6f8b9f089ee 100644 --- a/plugins/jenkins/src/components/useBuilds.ts +++ b/plugins/jenkins/src/components/useBuilds.ts @@ -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, diff --git a/plugins/jenkins/src/components/useProjectSlugFromEntity.ts b/plugins/jenkins/src/components/useProjectSlugFromEntity.ts index ac2d6c7e8fa89..06261d36450b5 100644 --- a/plugins/jenkins/src/components/useProjectSlugFromEntity.ts +++ b/plugins/jenkins/src/components/useProjectSlugFromEntity.ts @@ -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] ?? ''; };