diff --git a/src/components/IOC/GitRefLink/GitRefLink.js b/src/components/IOC/GitRefLink/GitRefLink.js index 4410f59d128fb6139e4ac718aaaec003a6a67d25..2584172f389f218d19d894bdf2e6ce1f1c14db55 100644 --- a/src/components/IOC/GitRefLink/GitRefLink.js +++ b/src/components/IOC/GitRefLink/GitRefLink.js @@ -13,7 +13,12 @@ const propTypes = { revision: string }; -export default function GitRefLink({ url, revision, ...props }) { +export default function GitRefLink({ + url, + revision, + displayReference, + ...props +}) { // if no git reference has been entered if (!url || url.trim === "") { return <></>; @@ -38,7 +43,7 @@ export default function GitRefLink({ url, revision, ...props }) { label={`External Git Link, revision ${revision}`} {...props} > - {revision} + {displayReference} </ExternalLink> ); } diff --git a/src/components/IOC/IOCLiveStatus/IOCLiveStatus.js b/src/components/IOC/IOCLiveStatus/IOCLiveStatus.js index 39c98c630bda38d198963811a972025650e2afbe..bf2db8faf27a5fc68926b53c82f0f35e85a6b3c9 100644 --- a/src/components/IOC/IOCLiveStatus/IOCLiveStatus.js +++ b/src/components/IOC/IOCLiveStatus/IOCLiveStatus.js @@ -37,6 +37,7 @@ export function IOCLiveStatus({ ioc }) { Revision: iocHasDeployment ? ( <GitRefLink url={ioc.activeDeployment?.sourceUrl} + displayReference={ioc.activeDeployment?.sourceVersion} revision={ioc.activeDeployment?.sourceVersion} /> ) : ( diff --git a/src/components/Job/JobDetails.js b/src/components/Job/JobDetails.js index 4e5865407360e190192cbc7f7e4f8fdc3d5843cf..2cc44a23ad4e27ec5b560cc994e23d28510ddc65 100644 --- a/src/components/Job/JobDetails.js +++ b/src/components/Job/JobDetails.js @@ -62,6 +62,7 @@ export function JobDetails({ operation, job }) { Revision: ( <GitRefLink url={operation.gitProjectUrl} + displayReference={operation.gitShortReference} revision={operation.gitShortReference} /> ), diff --git a/src/components/Job/JobTable/JobGitRefIcon.js b/src/components/Job/JobTable/JobGitRefIcon.js new file mode 100644 index 0000000000000000000000000000000000000000..ce4310598be95d0a32d504327f5eae46dcd35e0f --- /dev/null +++ b/src/components/Job/JobTable/JobGitRefIcon.js @@ -0,0 +1,49 @@ +import React, { useContext, useMemo } from "react"; +import { apiContext } from "../../../api/DeployApi"; +import { useAPIMethod } from "@ess-ics/ce-ui-common"; +import { Skeleton } from "@mui/material"; +import CommitIcon from "@mui/icons-material/Commit"; +import LabelOutlinedIcon from "@mui/icons-material/LabelOutlined"; +import QuestionMarkIcon from "@mui/icons-material/QuestionMark"; + +export const JobGitRefIcon = ({ job }) => { + const client = useContext(apiContext); + const params = useMemo( + () => ({ + project_id: job?.gitProjectId, + git_reference: job?.gitReference + }), + [job] + ); + + const { value: referenceTypeResponse } = useAPIMethod({ + fcn: client.apis.Git.gitReferenceType, + params: params + }); + + if (!referenceTypeResponse) { + return ( + <Skeleton + sx={{ marginLeft: "4px" }} + variant="circular" + width={20} + height={20} + /> + ); + } + + if (referenceTypeResponse.reference_type === "TAG") { + return <LabelOutlinedIcon sx={{ marginLeft: "4px" }} />; + } + + if (referenceTypeResponse.reference_type === "COMMIT") { + return <CommitIcon sx={{ marginLeft: "4px" }} />; + } + + return ( + <QuestionMarkIcon + sx={{ marginLeft: "4px" }} + fontSize="small" + /> + ); +}; diff --git a/src/components/Job/JobTable/JobGitRefLink.js b/src/components/Job/JobTable/JobGitRefLink.js index 21f9e7ae0e123f2ea45ef922cfa0ccc6e7b076ea..8004f0e014beda5ecc5b56dcb761de40c212f573 100644 --- a/src/components/Job/JobTable/JobGitRefLink.js +++ b/src/components/Job/JobTable/JobGitRefLink.js @@ -31,15 +31,21 @@ export const JobGitRefLink = ({ job }) => { }); if (!project || !commits) { - return <Skeleton width={100} />; + return <Skeleton width={80} />; } - const gitRef = commits?.at(0)?.shortReference ?? job.gitReference; + const firstCommit = commits?.at(0); + const gitRef = firstCommit?.shortReference ?? job.gitReference; + const displayReference = + firstCommit?.type === "TAG" + ? firstCommit?.reference + : firstCommit?.short_reference; return ( <GitRefLink url={project?.projectUrl} revision={gitRef} + displayReference={displayReference} label={`External Git Link, project ${project.name}, revision ${gitRef}`} disableExternalLinkIcon /> diff --git a/src/components/Job/JobTable/JobSummaryColumn.js b/src/components/Job/JobTable/JobSummaryColumn.js index 4a4dfe3495c4aa4e27eeaf50c305cc78bc7a1edf..f24c37c742a27594353ee27c890605ccdb78e23f 100644 --- a/src/components/Job/JobTable/JobSummaryColumn.js +++ b/src/components/Job/JobTable/JobSummaryColumn.js @@ -1,9 +1,9 @@ import React from "react"; import { Chip, Stack } from "@mui/material"; -import CommitIcon from "@mui/icons-material/Commit"; import { JobGitRefLink } from "./JobGitRefLink"; import { JobTypeIcon } from "../JobIcons"; import { InternalLink } from "@ess-ics/ce-ui-common"; +import { JobGitRefIcon } from "./JobGitRefIcon"; export const JobSummaryColumn = ({ job, colorStyle }) => { return ( @@ -32,8 +32,13 @@ export const JobSummaryColumn = ({ job, colorStyle }) => { </InternalLink> {job.type === "DEPLOY" ? ( <Chip + sx={{ + "& .MuiChip-label": { + paddingLeft: "4px" + } + }} size="small" - icon={<CommitIcon />} + icon={<JobGitRefIcon job={job} />} label={<JobGitRefLink job={job} />} /> ) : null} diff --git a/src/mocks/fixtures/ccce-api.json b/src/mocks/fixtures/ccce-api.json index 63e61171c333120dcdd9d837eee0eb48a6bf7692..954c90d81e76b536a3c0fd2ebb146fca38676806 100644 --- a/src/mocks/fixtures/ccce-api.json +++ b/src/mocks/fixtures/ccce-api.json @@ -2870,6 +2870,66 @@ } } }, + "/api/v1/git_helper/{project_id}/reference_type/{git_reference}": { + "get": { + "tags": ["Git"], + "summary": "Git reference tye", + "operationId": "gitReferenceType", + "parameters": [ + { + "name": "project_id", + "in": "path", + "description": "Git repo project ID", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + }, + { + "name": "git_reference", + "in": "path", + "description": "Git reference", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Git reference type", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ReferenceTypeResponse" + } + } + } + }, + "500": { + "description": "Service exception", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GeneralException" + } + } + } + }, + "503": { + "description": "Git exception", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GeneralException" + } + } + } + } + } + } + }, "/api/v1/git_helper/user_info": { "get": { "tags": ["Git"], @@ -4748,7 +4808,7 @@ }, "type": { "type": "string", - "enum": ["TAG", "COMMIT"] + "enum": ["TAG", "COMMIT", "UNKNOWN"] }, "short_reference": { "type": "string" @@ -4759,6 +4819,15 @@ } } }, + "ReferenceTypeResponse": { + "type": "object", + "properties": { + "reference_type": { + "type": "string", + "enum": ["TAG", "COMMIT", "UNKNOWN"] + } + } + }, "UserInfoResponse": { "type": "object", "properties": {