merge-try-google-books-api-for-book-identification-by-isbn #7
6 changed files with 141 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
.env
|
||||
n39env
|
||||
.vscode
|
55
createMR.py
Normal file
55
createMR.py
Normal file
|
@ -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)
|
79
createMR.sh
Normal file
79
createMR.sh
Normal file
|
@ -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
|
1
frontend/.gitignore
vendored
Normal file
1
frontend/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
node_modules
|
1
issues
Normal file
1
issues
Normal file
File diff suppressed because one or more lines are too long
2
middleware/.gitignore
vendored
Normal file
2
middleware/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
dist
|
||||
node_modules
|
Loading…
Reference in a new issue