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..699c2ac --- /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=branchName, head="main", title="merge" + branchName + ), + client=client, + ).content + ) + print(res) diff --git a/createMR.sh b/createMR.sh new file mode 100644 index 0000000..d7da326 --- /dev/null +++ b/createMR.sh @@ -0,0 +1,79 @@ +source './.env' + +PASSED_ISSUE='' + +while test $# -gt 0; do + case "$1" in + -i|--issue) + shift + if test $# -gt 0 + then + export PASSED_ISSUE=$1 + fi + shift + ;; + -h|--help) print_usage ;; + *) print_usage + break + ;; + esac +done + +if [[ -z $PASSED_ISSUE ]] +then + echo -e "missing issue; use -i \e[3missue\e[0m" + exit 1 +fi + +printf "\n" + +ISSUES=$(curl -X 'GET' \ + 'https://git.n39.eu/api/v1/repos/'$OWNER'/'$REPO'/issues' \ + -H 'accept: application/json' | tr ' ' -) + +printf "\n" +echo $ISSUES + +ISSUE=$(jq '.[] | select(.title|test("'$PASSED_ISSUE'"))' <<< $ISSUES) + +printf "\n" +echo $ISSUE + +NAME=$(jq '.title' <<< $ISSUE) + +printf "\n" +echo $NAME + +BRANCH=$(curl -X 'POST' 'https://git.n39.eu/api/v1/repos/'$OWNER'/'$REPO'/branches' \ + -H "accept: application/json" \ + -H 'Authorization: token '${FORJEGO_ACCESS_TOKEN} \ + -H "Content-Type: application/json" -d '{"new_branch_name": '$NAME', "old_branch_name": "main"}' -i) + +echo $BRANCH + +USER=$(git config --global user.name) + +MR=$(curl -X 'POST' 'https://git.n39.eu/api/v1/repos/'$OWNER'/'$REPO'/pulls' \ + -H "accept: application/json" \ + -H 'Authorization: token '${FORJEGO_ACCESS_TOKEN} \ + -H "Content-Type: application/json" -d '{ + "assignee": "'$USER'", + "assignees": [ + "string" + ], + "base": "string", + "body": "string", + "head": "string", + "labels": [ + 0 + ], + "milestone": 0, + "title": "string" + }' -i) + +USER=$(git checkout $BRANCH) + + +#git browse -- issues +#git checkout -b '' +#git push -o merge_request.create origin my-branch \ No newline at end of file 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/issues b/issues new file mode 100644 index 0000000..7bb88ed --- /dev/null +++ b/issues @@ -0,0 +1 @@ +[{"id":844,"url":"https://git.n39.eu/api/v1/repos/0Ry5/n39librarian/issues/5","html_url":"https://git.n39.eu/0Ry5/n39librarian/issues/5","number":5,"user":{"id":118,"login":"0Ry5","login_name":"","full_name":"","email":"0ry5@git.n39.eu","avatar_url":"https://git.n39.eu/avatar/b3977e6b4b95a3a537127207119712a2","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2024-09-09T20:35:12+02:00","restricted":false,"active":false,"prohibit_login":false,"location":"","website":"","description":"","visibility":"public","followers_count":0,"following_count":0,"starred_repos_count":0,"username":"0Ry5"},"original_author":"","original_author_id":0,"title":"checkout modal can be submitted if its invalid","body":"","ref":"","assets":[],"labels":[],"milestone":null,"assignee":null,"assignees":null,"state":"open","is_locked":false,"comments":0,"created_at":"2024-09-13T14:25:22+02:00","updated_at":"2024-09-13T14:25:22+02:00","closed_at":null,"due_date":null,"pull_request":null,"repository":{"id":65,"name":"n39librarian","owner":"0Ry5","full_name":"0Ry5/n39librarian"},"pin_order":0},{"id":843,"url":"https://git.n39.eu/api/v1/repos/0Ry5/n39librarian/issues/4","html_url":"https://git.n39.eu/0Ry5/n39librarian/issues/4","number":4,"user":{"id":118,"login":"0Ry5","login_name":"","full_name":"","email":"0ry5@git.n39.eu","avatar_url":"https://git.n39.eu/avatar/b3977e6b4b95a3a537127207119712a2","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2024-09-09T20:35:12+02:00","restricted":false,"active":false,"prohibit_login":false,"location":"","website":"","description":"","visibility":"public","followers_count":0,"following_count":0,"starred_repos_count":0,"username":"0Ry5"},"original_author":"","original_author_id":0,"title":"undefined should not be a valid input for the checkout modal","body":"","ref":"","assets":[],"labels":[],"milestone":null,"assignee":null,"assignees":null,"state":"open","is_locked":false,"comments":0,"created_at":"2024-09-13T14:25:07+02:00","updated_at":"2024-09-13T14:25:07+02:00","closed_at":null,"due_date":null,"pull_request":null,"repository":{"id":65,"name":"n39librarian","owner":"0Ry5","full_name":"0Ry5/n39librarian"},"pin_order":0},{"id":839,"url":"https://git.n39.eu/api/v1/repos/0Ry5/n39librarian/issues/3","html_url":"https://git.n39.eu/0Ry5/n39librarian/issues/3","number":3,"user":{"id":118,"login":"0Ry5","login_name":"","full_name":"","email":"0ry5@git.n39.eu","avatar_url":"https://git.n39.eu/avatar/b3977e6b4b95a3a537127207119712a2","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2024-09-09T20:35:12+02:00","restricted":false,"active":false,"prohibit_login":false,"location":"","website":"","description":"","visibility":"public","followers_count":0,"following_count":0,"starred_repos_count":0,"username":"0Ry5"},"original_author":"","original_author_id":0,"title":"add unit tests","body":"","ref":"","assets":[],"labels":[],"milestone":null,"assignee":null,"assignees":null,"state":"open","is_locked":false,"comments":0,"created_at":"2024-09-09T20:49:52+02:00","updated_at":"2024-09-09T20:49:52+02:00","closed_at":null,"due_date":null,"pull_request":null,"repository":{"id":65,"name":"n39librarian","owner":"0Ry5","full_name":"0Ry5/n39librarian"},"pin_order":0},{"id":838,"url":"https://git.n39.eu/api/v1/repos/0Ry5/n39librarian/issues/2","html_url":"https://git.n39.eu/0Ry5/n39librarian/issues/2","number":2,"user":{"id":118,"login":"0Ry5","login_name":"","full_name":"","email":"0ry5@git.n39.eu","avatar_url":"https://git.n39.eu/avatar/b3977e6b4b95a3a537127207119712a2","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2024-09-09T20:35:12+02:00","restricted":false,"active":false,"prohibit_login":false,"location":"","website":"","description":"","visibility":"public","followers_count":0,"following_count":0,"starred_repos_count":0,"username":"0Ry5"},"original_author":"","original_author_id":0,"title":"try google-books api for book identification by isbn","body":"https://www.npmjs.com/package/@googleapis/books\r\n\r\nadd to CreateBookModal","ref":"","assets":[],"labels":[],"milestone":null,"assignee":null,"assignees":null,"state":"open","is_locked":false,"comments":0,"created_at":"2024-09-09T20:49:15+02:00","updated_at":"2024-09-09T20:49:15+02:00","closed_at":null,"due_date":null,"pull_request":null,"repository":{"id":65,"name":"n39librarian","owner":"0Ry5","full_name":"0Ry5/n39librarian"},"pin_order":0},{"id":837,"url":"https://git.n39.eu/api/v1/repos/0Ry5/n39librarian/issues/1","html_url":"https://git.n39.eu/0Ry5/n39librarian/issues/1","number":1,"user":{"id":118,"login":"0Ry5","login_name":"","full_name":"","email":"0ry5@git.n39.eu","avatar_url":"https://git.n39.eu/avatar/b3977e6b4b95a3a537127207119712a2","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2024-09-09T20:35:12+02:00","restricted":false,"active":false,"prohibit_login":false,"location":"","website":"","description":"","visibility":"public","followers_count":0,"following_count":0,"starred_repos_count":0,"username":"0Ry5"},"original_author":"","original_author_id":0,"title":"Darkmode","body":"","ref":"","assets":[],"labels":[],"milestone":null,"assignee":null,"assignees":null,"state":"open","is_locked":false,"comments":0,"created_at":"2024-09-09T20:48:27+02:00","updated_at":"2024-09-09T20:48:27+02:00","closed_at":null,"due_date":null,"pull_request":null,"repository":{"id":65,"name":"n39librarian","owner":"0Ry5","full_name":"0Ry5/n39librarian"},"pin_order":0}] diff --git a/middleware/.gitignore b/middleware/.gitignore new file mode 100644 index 0000000..db4c6d9 --- /dev/null +++ b/middleware/.gitignore @@ -0,0 +1,2 @@ +dist +node_modules \ No newline at end of file