diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c7e834 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.env +n39env +.vscode \ No newline at end of file diff --git a/createMR.py b/createMR.py new file mode 100644 index 0000000..7026c71 --- /dev/null +++ b/createMR.py @@ -0,0 +1,55 @@ +import os +import json +import argparse +from git import Repo +from pyforgejo import AuthenticatedClient +from dotenv import load_dotenv +from pyforgejo.api.issue import issue_list_issues +from pyforgejo.api.repository import repo_create_branch, repo_create_pull_request +from pyforgejo.models import CreateBranchRepoOption, CreatePullRequestOption + +load_dotenv() + +parser = argparse.ArgumentParser(description="") +parser.add_argument("-i", "--issue") +args = parser.parse_args() + +FORJEGO_ACCESS_TOKEN = os.getenv("FORJEGO_ACCESS_TOKEN") +OWNER = os.getenv("OWNER") +USER = os.getenv("USER") +REPO = os.getenv("REPO") + +client = AuthenticatedClient( + base_url="https://git.n39.eu/api/v1/", token=FORJEGO_ACCESS_TOKEN +) + +issues = json.loads(issue_list_issues.sync_detailed(OWNER, REPO, client=client).content) + + +def filterIssues(issue): + return args.issue in issue["title"] + + +issues = list(filter(filterIssues, issues)) + +branchName = issues[0]["title"].replace(" ", "-") + +if len(issues) > 1: + raise ValueError("found more than one ticket") +if len(issues) == 0: + raise ValueError("found more than one ticket") +else: + repo_create_branch.sync_detailed( + OWNER, REPO, body=CreateBranchRepoOption(branchName, "main"), client=client + ) + res = json.loads( + repo_create_pull_request.sync_detailed( + OWNER, + REPO, + body=CreatePullRequestOption( + base="main", head=branchName, title="merge-" + branchName + ), + client=client, + ).content + ) + print(res) diff --git a/frontend/.gitignore b/frontend/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/frontend/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/frontend/src/shared/components/modals/BookModal.tsx b/frontend/src/shared/components/modals/BookModal.tsx index fb852c1..5c086b6 100644 --- a/frontend/src/shared/components/modals/BookModal.tsx +++ b/frontend/src/shared/components/modals/BookModal.tsx @@ -29,7 +29,20 @@ export const BookModal = ({ }, [book, reset]); const { scannerError, setScannerRef } = useScanner({ - onDetected: (result) => { + onDetected: async (result) => { + const googleBooks = await ( + await fetch( + "https://www.googleapis.com/books/v1/volumes?q=isbn:" + result + ) + ).json(); + if ("items" in googleBooks) { + console.log(googleBooks); + setValue( + "published", + googleBooks.items[0].volumeInfo.publishedDate.substring(0, 4) + ); + setValue("title", googleBooks.items[0].volumeInfo.title); + } setValue("isbn", result); setShowScanner(false); }, @@ -38,6 +51,7 @@ export const BookModal = ({ const values = useWatch({ control }); const [submitError, setSubmitError] = useState(); + const onSubmit = useCallback( async (data: Partial) => { setSubmitError(undefined); @@ -89,7 +103,7 @@ export const BookModal = ({ } + icon={} /> {!showScanner && (
{ ev.preventDefault(); onSubmit(values); }} > - - + + ISBN - -
+ +
setShowScanner(true)} > @@ -135,7 +149,7 @@ export const BookModal = ({
{!formState.errors.isbn ? "ISBN is required" @@ -143,8 +157,8 @@ export const BookModal = ({ - - + + Title @@ -153,15 +167,15 @@ export const BookModal = ({ isInvalid={!!formState.errors.title} /> - + {!values.title ? "Title is required" : formState.errors.title?.message} - - + + Year published @@ -187,15 +201,15 @@ export const BookModal = ({ isInvalid={!!formState.errors.published} /> - + {!values.published ? "Year published is required" : formState.errors.published?.message} - - + + Shelf @@ -205,21 +219,21 @@ export const BookModal = ({ > {Object.keys(bookShelfs).map((key) => ( ))} - + {!values.shelf ? "Shelf is required" : formState.errors.shelf?.message} -
+