Skip to content

Commit

Permalink
Load contact info from custom metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrabovsky committed May 2, 2023
1 parent a2d9881 commit 8543e91
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

import _ from 'lodash';
import { BrokerMessagesType, EtaBrokerMessagesType } from './types';
import { BrokerMessagesType, EtaBrokerMessagesType, Metadata } from './types';

export type ComposeArtifactType = 'productmd-compose';
export type ContainerImageArtifactType = 'redhat-container-image';
Expand Down Expand Up @@ -404,6 +404,7 @@ export interface KaiErrataToolAutomationStateType {

export type StateKaiType = {
broker_msg_body: BrokerMessagesType;
custom_metadata?: Metadata;
kai_state: KaiStateType;
};

Expand Down
9 changes: 9 additions & 0 deletions src/components/PageResultsNew/DetailsDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ function ContactWidget({ contact }: ContactWidgetProps) {
<ExternalLink href={contact.slackRoomUrl}>
<b>via Slack</b>
</ExternalLink>
,{' '}
<ExternalLink href={contact.gchatRoomUrl}>
<b>via Chat</b>
</ExternalLink>
, or via email at{' '}
<b>
<a href={`mailto:${contact.email}`}>{contact.email}</a>
Expand Down Expand Up @@ -243,6 +247,11 @@ export function DetailsDrawer(props: DetailsDrawerProps) {
/>
) : null;

/*
* TODO: Load (ArtifactsXunitQuery) and parse (xunitParser) xunit
* and pass the test suites/loading/error state to <DetailsDrawerTabs>.
*/

const panelContent = (
<DrawerPanelContent
defaultSize={drawerSize}
Expand Down
16 changes: 15 additions & 1 deletion src/components/PageResultsNew/TestSuitesAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
AccordionToggle,
Alert,
Badge,
DrawerPanelBody,
Flex,
FlexItem,
Label,
Expand Down Expand Up @@ -164,7 +165,20 @@ export function TestSuitesAccordion(props: TestSuitesAccordionProps) {
Partial<Record<string, boolean>>
>({});
const { suites } = props;
if (!suites) return null;
if (_.isEmpty(suites)) {
return (
<DrawerPanelBody>
<Alert
isInline
title="Detailed results not available"
variant="info"
>
The CI system did not provide detailed results for this test
run.
</Alert>
</DrawerPanelBody>
);
}

const onToggle = (name: string): void => {
const newExpandedIds = update(expandedSuites, {
Expand Down
52 changes: 44 additions & 8 deletions src/components/PageResultsNew/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
StateKaiType,
StateType,
} from '../../artifact';
import { MSG_V_1 } from '../../types';
import { MSG_V_1, MetadataContact } from '../../types';
import {
getDocsUrl,
getKaiExtendedStatus,
Expand Down Expand Up @@ -125,7 +125,7 @@ function transformGreenwaveOutcome(
return 'failed';
}

function extractCotactFromUmb(test: StateKaiType): CiContact | undefined {
function extractContactFromUmb(test: StateKaiType): CiContact | undefined {
// TODO: Incorporate contact info from metadata somehow.
if (!MSG_V_1.isMsg(test.broker_msg_body)) return;
const { contact } = test.broker_msg_body;
Expand All @@ -141,16 +141,45 @@ function extractCotactFromUmb(test: StateKaiType): CiContact | undefined {
};
}

function extractContact(test: StateType): CiContact | undefined {
// TODO: Pull data from "metadata" database.
// TODO: Handle the Greenwave-only case.
if (isGreenwaveState(test)) return;
function extractContact(test: StateType): CiContact {
let contact: CiContact = {};
let metadataContact: MetadataContact | undefined;

// TODO: Handle the Greenwave-only case. Is there any info in the Greenwave response?
// if (isGreenwaveState(test)) return;
if (isKaiState(test)) {
return extractCotactFromUmb(test);
_.merge(contact, extractContactFromUmb(test));
metadataContact = test.custom_metadata?.payload?.contact;
}
if (isGreenwaveKaiState(test)) {
return extractCotactFromUmb(test.ks);
_.merge(contact, extractContactFromUmb(test.ks));
metadataContact = test.ks.custom_metadata?.payload?.contact;
}

// Merge in data from the `custom_metadata` Kai state field.
if (metadataContact?.docs) {
contact.docsUrl = metadataContact.docs;
}
if (metadataContact?.email) {
contact.email = metadataContact.email;
}
if (metadataContact?.gchat_room_url) {
contact.gchatRoomUrl = metadataContact.gchat_room_url;
}
if (metadataContact?.name) {
contact.name = metadataContact.name;
}
if (metadataContact?.report_issue_url) {
contact.reportIssueUrl = metadataContact.report_issue_url;
}
if (metadataContact?.team) {
contact.team = metadataContact.team;
}
if (metadataContact?.url) {
contact.url = metadataContact.url;
}

return contact;
}

// TODO: This function is temporary only and will be removed once the UI is finalized.
Expand Down Expand Up @@ -185,6 +214,13 @@ function transformTest(
) {
status = transformGreenwaveOutcome(test.gs.result.outcome);
} else if (isGreenwaveKaiState(test) && stateName === 'additional-tests') {
/*
* TODO: For some osci and baseos-ci tests, this will return `failed`
* even if the failure is in infrastructure. The message is sent to
* `/topic/VirtualTopic.eng.ci.osci.brew-build.test.error` and has
* `error.reason`, but `test.result === 'failed'`. For an example, see
* https://datagrepper.engineering.redhat.com/id?id=ID:osci-jenkins-master-0-43277-1681457299489-309:1:1:1:1&is_raw=true&size=extra-large
*/
status = transformUmbStatus(getKaiExtendedStatus(test.ks));
}

Expand Down

0 comments on commit 8543e91

Please sign in to comment.