Skip to content

Commit

Permalink
Format precondition error in commit as in merge (#1548)
Browse files Browse the repository at this point in the history
  • Loading branch information
nopcoder authored Mar 1, 2021
1 parent d1e9adc commit e741a17
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 54 deletions.
7 changes: 5 additions & 2 deletions webui/src/components/ChangesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {resetRevertBranch, revertBranch} from "../actions/branches";
import ConfirmationModal from "./ConfirmationModal";
import {doCommit, resetCommit} from "../actions/commits";
import Alert from "react-bootstrap/Alert";
import {formatAlertText} from "./PreconditionErr";

const CommitButton = connect(
({ commits }) => ({ commitState: commits.commit }),
Expand All @@ -27,6 +28,7 @@ const CommitButton = connect(
if (commitDisabled) return;
setShow(false);
setMetadataFields([]);
resetCommit();
};

useEffect(() => {
Expand All @@ -52,9 +54,10 @@ const CommitButton = connect(
return <span/>;
}

const alertText = formatAlertText(repo.id, commitState.error);
return (
<>
<Modal show={show} onHide={onHide}>
<Modal show={show} onHide={onHide} size="lg">
<Modal.Header closeButton>
<Modal.Title>Commit Changes</Modal.Title>
</Modal.Header>
Expand Down Expand Up @@ -104,7 +107,7 @@ const CommitButton = connect(
Add Metadata field
</Button>
</Form>
{(!!commitState.error) ? (<Alert variant="danger">{commitState.error}</Alert>) : (<span/>)}
{(alertText) ? (<Alert variant="danger">{alertText}</Alert>) : (<span/>)}
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" disabled={commitDisabled} onClick={onHide}>
Expand Down
54 changes: 2 additions & 52 deletions webui/src/components/ComparePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import RefDropdown from "./RefDropdown";
import Changes from "./Changes";
import ConfirmationModal from "./ConfirmationModal";
import {PAGINATION_AMOUNT} from "../actions/refs";
import {API_ENDPOINT} from "../actions/api";
import ClipboardButton from "./ClipboardButton";
import {formatAlertText} from "./PreconditionErr";

const MergeButton = connect(
({ refs }) => ({
Expand Down Expand Up @@ -146,53 +145,10 @@ const ComparePage = ({repo, refId, compareRef, diff, diffPaginate, diffResults,
refreshData();
}, [refreshData, repo.id, refId.id, diff, diffPaginate, compareRef]);

const getRunID = (err) => {
if (!err) {
return '';
}
const m = /^Error: (\S+) hook aborted, run id '([^']+)'/.exec(err);
if (!m) {
return '';
}
return m[2];
};

const formatAlertText = (err) => {
if (!err) {
return '';
}
const lines = err.split('\n');
if (lines.length === 1) {
return <Alert.Heading>{err}</Alert.Heading>;
}
const runID = getRunID(err);
return lines.map((line, i) => {
if (runID) {
const m = /^\t\* hook run id '([^']+)' failed/.exec(line);
if (m) {
const hookRunID = m[1];
const link = `${API_ENDPOINT}/repositories/${repo.id}/actions/runs/${runID}/hooks/${hookRunID}/output`;
return <p key={i}><Alert.Link target="_blank" download={hookRunID} href={link}>{line}</Alert.Link></p>;
}
}
return <p key={i}>{line}</p>;
});
};

const formatMoreInformation = (err) => {
const runID = getRunID(err);
if (!runID) {
return '';
}
const cmd = `lakectl actions runs describe lakefs://${repo.id} ${runID}`;
return <>For detailed information run:<br/>{cmd}<ClipboardButton variant="link" text={cmd} tooltip="Copy"/></>;
};

const paginator =(!diffResults.loading && !!diffResults.payload && diffResults.payload.pagination && diffResults.payload.pagination.has_more);
const showMergeCompleted = !!(mergeResults && mergeResults.payload);
const compareWith = !compareRef || (refId.type === compareRef.type && refId.id === compareRef.id);
const alertText = formatAlertText(diffResults.error || mergeResults.error);
const alertMoreInformation = formatMoreInformation(mergeResults.error);
const alertText = formatAlertText(repo.id, diffResults.error || mergeResults.error);
return (
<div className="mt-3">
<div className="action-bar">
Expand All @@ -210,12 +166,6 @@ const ComparePage = ({repo, refId, compareRef, diff, diffPaginate, diffResults,

<Alert variant="danger" show={!!alertText}>
{alertText}
{alertMoreInformation &&
(<>
<hr/>
{alertMoreInformation}
</>)
}
</Alert>

{!(compareWith || alertText) &&
Expand Down
41 changes: 41 additions & 0 deletions webui/src/components/PreconditionErr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {Alert} from "react-bootstrap";
import {API_ENDPOINT} from "../actions/api";
import ClipboardButton from "./ClipboardButton";
import React from "react";


function extractActionRunID(err) {
const m = /^Error: (\S+) hook aborted, run id '([^']+)'/.exec(err);
return m ? m[2] : '';
}

function extractActionHookRunID(err) {
const m = /^\t\* hook run id '([^']+)' failed/.exec(err);
return m ? m[1] : '';
}

export function formatAlertText(repositoryId, err) {
if (!err) {
return '';
}
const lines = err.split('\n');
if (lines.length === 1) {
return <Alert.Heading>{err}</Alert.Heading>;
}
const runID = extractActionRunID(err);
let result = lines.map((line, i) => {
if (runID) {
const hookRunID = extractActionHookRunID(line);
if (hookRunID) {
const link = `${API_ENDPOINT}/repositories/${repositoryId}/actions/runs/${runID}/hooks/${hookRunID}/output`;
return <p key={i}><Alert.Link target="_blank" download={runID+'-'+hookRunID+'.log'} href={link}>{line}</Alert.Link></p>;
}
}
return <p key={i}>{line}</p>;
});
if (runID) {
const cmd = `lakectl actions runs describe lakefs://${repositoryId} ${runID}`;
result = <>{result}<hr/>For detailed information run:<br/>{cmd}<ClipboardButton variant="link" text={cmd} tooltip="Copy"/></>;
}
return result;
}

0 comments on commit e741a17

Please sign in to comment.