Skip to content

Commit

Permalink
Changed the way project slug is handled in Jenkins plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Nir Gazit <[email protected]>
  • Loading branch information
nirga committed Mar 11, 2021
1 parent c8b54c3 commit e8b2ed9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changeset/warm-cows-wait.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions plugins/jenkins/src/components/Cards/Cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand Down
9 changes: 4 additions & 5 deletions plugins/jenkins/src/components/useBuilds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand All @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions plugins/jenkins/src/components/useProjectSlugFromEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] ?? '';
};

0 comments on commit e8b2ed9

Please sign in to comment.