Skip to content

Commit

Permalink
feat: integrate commit type classification in the frontend
Browse files Browse the repository at this point in the history
Ref:#237
Time-spent: 1h32m
  • Loading branch information
TBalint2000 committed Jul 15, 2024
1 parent 9669452 commit d744e77
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
16 changes: 16 additions & 0 deletions binocular-frontend/src/utils/getCommitType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

export default async function (commitMessage: string) {

const payload = commitMessage.trim() == '' ? '' : '?q=' + commitMessage.trim();
if (!payload) {
return [];
}

const res = await fetch(window.location.protocol + '//' + window.location.hostname + ':48763/api/getCommitType?commitMessage=' + encodeURIComponent(payload));

if (!res.ok) {
return [];
}
return await res.json();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {Author, Committer, Palette} from '../../../../types/authorTypes.ts';
import {Author, Committer} from '../../../../types/authorTypes.ts';
import {Commit} from "../../../../types/commitTypes.ts";
import getCommitType from '../../../../utils/getCommitType.ts';
import * as React from "react";

interface Props {
commits: Commit[];
Expand Down Expand Up @@ -32,7 +34,19 @@ interface CommitChartData {
}

export default (props: Props) => {
console.log(extractCommitData(props))
const extractedCommitData = extractCommitData(props);
const [commitChartData, setCommitChartData] = React.useState(extractedCommitData.commitChartData);
const [maxTime, setMaxTime] = React.useState(extractedCommitData.maxTime);
const [maxChange, setMaxChange] = React.useState(extractedCommitData.maxChange);

React.useEffect(() => {
const extractedCommitData = extractCommitData(props);
setCommitChartData(extractedCommitData.commitChartData);
setMaxTime(extractedCommitData.maxTime);
setMaxChange(extractedCommitData.maxChange);
}, [props]);
console.log(commitChartData);

return (<div>Content</div>);
};

Expand All @@ -54,7 +68,6 @@ const extractCommitData = (props: Props): { commitChartData: CommitChartData[];
});

const maxTime = {estimated: 0, actual: 0};

return { commitChartData: commitChartData, maxTime: maxTime, maxChange: 0 };
};

Expand All @@ -64,8 +77,8 @@ function addTimeToCommits(commits: any[]) {
});
}

function addTypeToCommits(commits: any[]) {
return commits.map(c => {
return {...c, commitType : "unknown"};
function addTypeToCommits(commits: Commit[]) {
return commits.map((c) => {
return {...c, commitType : getCommitType(c.message)};
})
}

0 comments on commit d744e77

Please sign in to comment.