Skip to content
Snippets Groups Projects
Commit b0bc80d0 authored by Štěpán Šonovský's avatar Štěpán Šonovský
Browse files

feat: Added csv test files download

parent c2788b2c
No related branches found
No related tags found
No related merge requests found
import React, { useState, useEffect } from 'react';
import React, { useState } from 'react';
import CsvDownloadPositivity from "@/app/csvDownload/CsvDownload";
import CsvDownloadSize from "@/app/csvDownload/CsvDownloadSize";
import CsvDownloadTestFiles from "@/app/csvDownload/CsvDownloadTestFiles";
import { useCommitsAll } from "@/app/hooks/useCommits";
const CsvButtons = ({ projectId, token, host }) => {
const [showCsvDownloadPositivity, setShowCsvDownloadPositivity] = useState(false);
const [showCsvDownloadSize, setShowCsvDownloadSize] = useState(false);
const [showCsvDownloadTestFiles, setShowCsvDownloadTestFiles] = useState(false);
const [fetchCommits, setFetchCommits] = useState(false);
const { commits, loading, error } = useCommitsAll(projectId, token, host, fetchCommits);
......@@ -20,6 +22,11 @@ const CsvButtons = ({ projectId, token, host }) => {
setFetchCommits(true);
};
const handleFetchTestFiles = () => {
setShowCsvDownloadTestFiles(true);
setFetchCommits(true);
};
return (
<>
{!showCsvDownloadSize ? (
......@@ -47,6 +54,19 @@ const CsvButtons = ({ projectId, token, host }) => {
<CsvDownloadPositivity commits={commits} projectId={projectId} token={token}/>
</div>
)}
{!showCsvDownloadTestFiles ? (
<button
onClick={handleFetchTestFiles}
className="mt-4 bg-blue-500 text-white font-bold py-2 px-4 rounded hover:bg-blue-700 m-2"
>
Fetch CSV test files
</button>
) : (
<div className="mt-4">
<CsvDownloadTestFiles commits={commits} projectId={projectId} token={token}/>
</div>
)}
</>
);
};
......
......@@ -4,14 +4,12 @@ import useCommitDetails, { useCommitsPositivity } from "@/app/hooks/useCommitDet
const CsvDownloadPositivity = ({ commits, projectId, token }) => {
const { data, isLoading } = useCommitsPositivity(projectId, commits, token);
const csvlink = createRef();
return (
<div>
{!isLoading && data ? (
<CSVLink
data={data}
ref={csvlink}
target="_blank"
enclosingCharacter={``}
className="mt-4 bg-blue-500 text-white font-bold py-2 px-4 rounded hover:bg-blue-700"
......
import {useState, useEffect, createRef} from 'react';
import useCommitDetails, {useCommitSize, useCommitsPositivity} from "@/app/hooks/useCommitDetails";
import {useCommitSize} from "@/app/hooks/useCommitDetails";
import { CSVLink } from "react-csv";
type CommitDetails = {
author: string;
createdAt: string;
projectId: string;
};
const CsvDownloadSize = ({ commits, projectId, token }) => {
const {data, isLoading} = useCommitSize(projectId, commits, token);
const csvlink = createRef();
// useEffect(() => {
// if (!isLoading && data) {
// console.log("das");
// csvlink.current.link.click();
// }
// }, [csvlink, data, isLoading]);
console.log(data);
......@@ -30,7 +16,6 @@ const CsvDownloadSize = ({ commits, projectId, token }) => {
<div>
<CSVLink
data={data}
ref={csvlink}
target="_blank"
enclosingCharacter={``}
className="mt-4 bg-blue-500 text-white font-bold py-2 px-4 rounded hover:bg-blue-700"
......
......@@ -27,3 +27,4 @@ export const useCommitFiles = (projectId, commitId, token) => {
return { files, loadingE, errorE };
};
import {useQuery} from "@tanstack/react-query";
import axios from "axios";
import {host} from "@/utils";
export const useCommitTestFiles = (projectId, commitIds, token) => {
const { data, isLoading, error } = useQuery({
queryKey: ['commitDetails', projectId, commitIds],
queryFn: async () => {
const promises = commitIds.map(async (commitId) => {
const commitResponse = await axios.get(`${host}/api/v4/projects/${projectId}/repository/commits/${commitId.id}`, {
headers: {'PRIVATE-TOKEN': token}
});
const commitData = commitResponse.data;
const diffResponse = await axios.get(`${host}/api/v4/projects/${projectId}/repository/commits/${commitId.id}/diff`, {
headers: {'PRIVATE-TOKEN': token}
});
const files = diffResponse.data;
const isTestCommit = files.all(file => /test/i.test(file.new_path) || /test/i.test(file.old_path));
const isMixedCommit = files.some(file => /test/i.test(file.new_path) || /test/i.test(file.old_path));
return {
project_id: projectId,
author_name: commitData.author_name,
created_at: commitData.created_at,
testFile: isMixedCommit ? (isTestCommit ? 'Test commit' : 'Mixed test commit') : 'No test commit'
};
});
return Promise.all(promises);
}
});
return { data, isLoading, error };
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment