Skip to content

Commit

Permalink
Adjust to Anitya related API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lbarcziova committed Aug 21, 2024
1 parent ffc05fc commit c4d4805
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 49 deletions.
64 changes: 32 additions & 32 deletions frontend/src/apiDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ export interface CoprBuildPackage {

// /api/copr-builds/$id
export interface CoprBuild {
antiya_package: unknown | null;
anitya_project_id: unknown | null;
anitya_project_name: unknown | null;
anitya_project_version: unknown | null;
anitya_package: string | null;
anitya_project_id: number | null;
anitya_project_name: string | null;
anitya_version: string | null;
branch_name: string | null;
build_finished_time: number;
build_id: string;
Expand Down Expand Up @@ -152,10 +152,10 @@ export interface KojiBuildGroup {

// /api/koji-builds/$id
export interface KojiBuild {
antiya_package: unknown | null;
anitya_project_id: unknown | null;
anitya_project_name: unknown | null;
anitya_project_version: unknown | null;
anitya_package: string | null;
anitya_project_id: number | null;
anitya_project_name: string | null;
anitya_version: string | null;
branch_name: string | null;
build_finished_time: number;
build_logs_urls: [string: string];
Expand Down Expand Up @@ -197,10 +197,10 @@ export interface SRPMBuildGroup {

// /api/srpm-builds/$id
export interface SRPMBuild {
antiya_package: unknown | null;
anitya_project_id: unknown | null;
anitya_project_name: unknown | null;
anitya_project_version: unknown | null;
anitya_package: string | null;
anitya_project_id: number | null;
anitya_project_name: string | null;
anitya_version: string | null;
branch_name: string | null;
build_finished_time: number;
build_start_time: number;
Expand Down Expand Up @@ -242,10 +242,10 @@ export interface BodhiUpdateGroup {
// /api/bodhi-updates/$id
export interface BodhiUpdate {
alias: string | null;
antiya_package: unknown | null;
anitya_project_id: unknown | null;
anitya_project_name: unknown | null;
anitya_project_version: unknown | null;
anitya_package: string | null;
anitya_project_id: number | null;
anitya_project_name: string | null;
anitya_version: string | null;
branch: string;
branch_name: string | null;
issue_id: number | null;
Expand Down Expand Up @@ -280,10 +280,10 @@ export interface TestingFarmRunGroup {

// /api/testing-farm/$id
export interface TestingFarmRun {
antiya_package: unknown | null;
anitya_project_id: unknown | null;
anitya_project_name: unknown | null;
anitya_project_version: unknown | null;
anitya_package: string | null;
anitya_project_id: number | null;
anitya_project_name: string | null;
anitya_version: string | null;
branch_name: string | null;
chroot: string;
commit_sha: string;
Expand All @@ -305,10 +305,10 @@ export interface TestingFarmRun {
// /api/propose-downstream
// /api/pull-from-upstream
export interface SyncReleaseJobGroup {
antiya_package: unknown | null;
anitya_project_id: unknown | null;
anitya_project_name: unknown | null;
anitya_project_version: unknown | null;
anitya_package: string | null;
anitya_project_id: number | null;
anitya_project_name: string | null;
anitya_version: string | null;
issue_id: number | null;
non_git_upstream: boolean;
packit_id: number;
Expand All @@ -326,10 +326,10 @@ export interface SyncReleaseJobGroup {
// /api/propose-downstream/$id
// /api/pull-from-upstream/$id
export interface SyncReleaseJob {
antiya_package: unknown | null;
anitya_project_id: unknown | null;
anitya_project_name: unknown | null;
anitya_project_version: unknown | null;
anitya_package: string | null;
anitya_project_id: number | null;
anitya_project_name: string | null;
anitya_version: string | null;
branch: string;
branch_name: string | null;
downstream_pr_id: number | null;
Expand Down Expand Up @@ -372,10 +372,10 @@ export interface PipelineRun {
time_submitted: number;
trigger:
| {
antiya_package: unknown | null;
anitya_project_id: unknown | null;
anitya_project_name: unknown | null;
anitya_project_version: unknown | null;
anitya_package: string | null;
anitya_project_id: number | null;
anitya_project_name: string | null;
anitya_version: string | null;
branch_name: string | null;
issue_id: number | null;
non_git_upstream: boolean;
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/components/icons/ForgeIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import React from "react";
import { Tooltip } from "@patternfly/react-core";

import { getHostName } from "../../components/forgeUrls";
import { GithubIcon, GitlabIcon, GitIcon } from "@patternfly/react-icons";
import {
GithubIcon,
GitlabIcon,
GitIcon,
PackageIcon,
} from "@patternfly/react-icons";

export interface ForgeIconProps {
url: string;
Expand All @@ -26,6 +31,9 @@ export const ForgeIconByForge: React.FC<{ forge?: string }> = ({ forge }) => {
case "gitlab.com":
forgeIcon = <GitlabIcon />;
break;
case "release-monitoring.org":
forgeIcon = <PackageIcon />;
break;
default:
// patternfly doesn't have an icon for pagure
forgeIcon = <GitIcon />;
Expand Down
69 changes: 53 additions & 16 deletions frontend/src/components/trigger/TriggerLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,28 @@ interface TriggerLinkProps {
issue_id?: number | null;
branch_name?: string | null;
release?: string | null;
anitya_project_name?: string | null;
anitya_version?: string | null;
anitya_package?: string | null;
};
children?: React.ReactNode;
}

const TriggerLink: React.FC<TriggerLinkProps> = ({ trigger, children }) => {
let link = "";
const gitRepo = trigger.project_url ? trigger.project_url : "";
const projectUrl = trigger.project_url ? trigger.project_url : "";

if (trigger.pr_id) {
link = getPRLink(gitRepo, trigger.pr_id);
link = getPRLink(projectUrl, trigger.pr_id);
} else if (trigger.issue_id) {
link = getIssueLink(gitRepo, trigger.issue_id);
link = getIssueLink(projectUrl, trigger.issue_id);
} else if (trigger.branch_name) {
link = getBranchLink(gitRepo, trigger.branch_name);
link = getBranchLink(projectUrl, trigger.branch_name);
} else if (trigger.release) {
link = getReleaseLink(gitRepo, trigger.release);
link = getReleaseLink(projectUrl, trigger.release);
} else if (trigger.anitya_version) {
// there is no link to the particular version, just the whole project
link = projectUrl;
}

if (link) {
Expand All @@ -44,22 +50,45 @@ const TriggerLink: React.FC<TriggerLinkProps> = ({ trigger, children }) => {
return children;
};

interface TriggerSuffixProps {
trigger: {
branch_name?: string | null;
issue_id?: number | null;
pr_id?: number | null;
release?: string | null;
repo_name: string;
repo_namespace: string;
};
interface TriggerSuffixInterface {
branch_name?: string | null;
issue_id?: number | null;
pr_id?: number | null;
release?: string | null;
}

interface TriggerSuffixGitRepo extends TriggerSuffixInterface {
repo_name: string;
repo_namespace: string;
anitya_project_name?: string | null;
anitya_version?: string | null;
anitya_package?: string | null;
}

interface TriggerSuffixAnityaProject extends TriggerSuffixInterface {
anitya_project_name: string;
anitya_version: string;
anitya_package: string;
repo_name?: string | null;
repo_namespace?: string | null;
}

type TriggerSuffixProps = {
trigger: TriggerSuffixGitRepo | TriggerSuffixAnityaProject;
};

const TriggerSuffix: React.FC<TriggerSuffixProps> = ({ trigger }) => {
// set suffix to be either PR ID or Branch Name depending on trigger
let jobSuffix = "";

if (trigger.pr_id) {
if (isAnityaTrigger(trigger)) {
jobSuffix = `#version:${trigger.anitya_version}`;
return (
<>
{trigger.anitya_project_name}
{jobSuffix}
</>
);
} else if (trigger.pr_id) {
jobSuffix = `#${trigger.pr_id}`;
} else if (trigger.issue_id) {
jobSuffix = `#${trigger.issue_id}`;
Expand All @@ -77,4 +106,12 @@ const TriggerSuffix: React.FC<TriggerSuffixProps> = ({ trigger }) => {
);
};

function isAnityaTrigger(
trigger: TriggerSuffixProps["trigger"],
): trigger is TriggerSuffixAnityaProject {
return (
typeof trigger.anitya_version === "string" &&
trigger.anitya_version.length > 0
);
}
export { TriggerLink, TriggerSuffix };

0 comments on commit c4d4805

Please sign in to comment.