mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
added diff endpoint which returns a parsed diff as json
This commit is contained in:
@@ -50,10 +50,15 @@ class LoadingDiff extends React.Component<Props, State> {
|
||||
this.setState({ loading: true });
|
||||
apiClient
|
||||
.get(url)
|
||||
.then(response => response.text())
|
||||
.then(parser.parse)
|
||||
// $FlowFixMe
|
||||
.then((diff: any) => {
|
||||
.then(response => {
|
||||
const contentType = response.headers.get("Content-Type");
|
||||
if (contentType && contentType.toLowerCase() === "application/vnd.scmm-diffparsed+json;v=2") {
|
||||
return response.json().then(data => data.files);
|
||||
} else {
|
||||
return response.text().then(parser.parse);
|
||||
}
|
||||
})
|
||||
.then((diff: File[]) => {
|
||||
this.setState({
|
||||
loading: false,
|
||||
diff: diff
|
||||
|
||||
@@ -46,10 +46,17 @@ type Props = {
|
||||
className?: string;
|
||||
};
|
||||
|
||||
const determineLanguage = (file: File) => {
|
||||
if (file.language) {
|
||||
return file.language.toLowerCase();
|
||||
}
|
||||
return "text";
|
||||
};
|
||||
|
||||
const TokenizedDiffView: FC<Props> = ({ file, viewType, className, children }) => {
|
||||
const { tokens } = useTokenizeWorker(tokenize, {
|
||||
hunks: file.hunks,
|
||||
language: file.language || "text"
|
||||
language: determineLanguage(file)
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -11,13 +11,14 @@ type Props = WithTranslation & {
|
||||
|
||||
class ChangesetDiff extends React.Component<Props> {
|
||||
isDiffSupported(changeset: Changeset) {
|
||||
return !!changeset._links.diff;
|
||||
return changeset._links.diff || !!changeset._links.diffParsed;
|
||||
}
|
||||
|
||||
createUrl(changeset: Changeset) {
|
||||
if (changeset._links.diff) {
|
||||
const link = changeset._links.diff as Link;
|
||||
return link.href + "?format=GIT";
|
||||
if (changeset._links.diffParsed) {
|
||||
return (changeset._links.diffParsed as Link).href;
|
||||
} else if (changeset._links.diff) {
|
||||
return (changeset._links.diff as Link).href + "?format=GIT";
|
||||
}
|
||||
throw new Error("diff link is missing");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user