From 7ab55053a1e7f68f447f20f316b6132e14827bec Mon Sep 17 00:00:00 2001 From: Parteek Goyal Date: Thu, 3 Aug 2023 08:57:53 +0530 Subject: [PATCH 1/3] Update contribute.py --- contribute.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/contribute.py b/contribute.py index 19ee2e4..6f156ea 100644 --- a/contribute.py +++ b/contribute.py @@ -1,6 +1,6 @@ import github from github import Github -import os,sys,platform,base64 +import os,sys,platform,base64,time # Intializing the Variables # Hashed token @@ -85,6 +85,7 @@ def printPRStatus(upstream_repo): max_num = max(max_num,i.number) for i in pulls: max_num = max(max_num,i.number) + time.sleep(4) print(f'Check your example here https://github.com/{UPSTREAM_ACCOUNT}/{REPO_NAME}/pulls/{max_num+1}',end="") except Exception as e: print("Your example successfully uploaded but unable to fetch status.Please try again") @@ -94,6 +95,11 @@ def isImageFile(filename): image_extensions = ['.jpeg', '.jpg', '.png','.gif'] return any(filename.endswith(ext) for ext in image_extensions) +def remove_prefix(text, prefix): + if text.startswith(prefix): + return text[len(prefix):] + return text + # Decode Github Token def decode_token(encoded_token): @@ -154,7 +160,7 @@ def decode_token(encoded_token): else: with open(path, 'r') as file: content = file.read() - file_path = f'{DIR_PATH+path.removeprefix(STUDY_NAME_PATH)}' + file_path = f'{DIR_PATH+remove_prefix(path,STUDY_NAME_PATH)}' if(platform.uname()[0]=='Windows'): file_path=file_path.replace("\\","/") appendBlobInTree(repo,content,file_path,tree_content) commitAndUpdateRef(repo,tree_content,base_ref.commit,branch) From 415452fa080953f953de84eee5fb429ef9ab1e1d Mon Sep 17 00:00:00 2001 From: Pradeeban Kathiravelu Date: Thu, 3 Aug 2023 09:08:16 -0400 Subject: [PATCH 2/3] Fix logs --- contribute.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/contribute.py b/contribute.py index 6f156ea..1ee1b0d 100644 --- a/contribute.py +++ b/contribute.py @@ -68,12 +68,12 @@ def runWorkflow(repo,upstream_repo): if openPR==None: workflow_runned = repo.get_workflow(id_or_name="pull_request.yml").create_dispatch(ref=BRANCH_NAME,inputs={'title':f"[BOT]: {PR_TITLE}",'body':PR_BODY,'upstreamRepo':UPSTREAM_ACCOUNT,'botRepo':BOT_ACCOUNT,'repo':REPO_NAME}) if not workflow_runned: - print("Some error occured.Please try after some time") + print("Some error occured. Please try after some time") exit(0) else: printPRStatus(upstream_repo) else: - print("Successfully uploaded all files,your example is in waiting.Please wait for us to accept it.",end="") + print("Successfully uploaded all files, your example is in waiting.Please wait for us to accept it.",end="") printPR(openPR) def printPRStatus(upstream_repo): @@ -88,7 +88,7 @@ def printPRStatus(upstream_repo): time.sleep(4) print(f'Check your example here https://github.com/{UPSTREAM_ACCOUNT}/{REPO_NAME}/pulls/{max_num+1}',end="") except Exception as e: - print("Your example successfully uploaded but unable to fetch status.Please try again") + print("Your example successfully uploaded but unable to fetch status. Please try again") def isImageFile(filename): @@ -131,7 +131,7 @@ def decode_token(encoded_token): DIR_PATH = DIR_PATH.replace(" ","_") is_present = any(branch.name == BRANCH_NAME for branch in branches) except Exception as e: - print("Some error occured.Authentication failed",end="") + print("Authentication failed", end="") exit(0) @@ -143,7 +143,7 @@ def decode_token(encoded_token): # Get current branch branch = repo.get_branch(branch=BRANCH_NAME) except Exception as e: - print("Not able to create study for you.Please try again after some time",end="") + print("Not able to create study for you. Please try again after some time", end="") exit(0) @@ -166,5 +166,6 @@ def decode_token(encoded_token): commitAndUpdateRef(repo,tree_content,base_ref.commit,branch) runWorkflow(repo,upstream_repo) except Exception as e: - print("Some error Occured.Please try again after some time.",end="") + print("An error encountered: ", end="") + print(e) exit(0) \ No newline at end of file From 63b9475f799575b878d35dd69ce1a3a9563e6655 Mon Sep 17 00:00:00 2001 From: Parteek Goyal Date: Fri, 4 Aug 2023 19:27:45 +0530 Subject: [PATCH 3/3] Update contribute.py --- contribute.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/contribute.py b/contribute.py index 6f156ea..aa66d32 100644 --- a/contribute.py +++ b/contribute.py @@ -103,8 +103,10 @@ def remove_prefix(text, prefix): # Decode Github Token def decode_token(encoded_token): - decoded_bytes = base64.b64decode(encoded_token.encode('utf-8')) - decoded_token = decoded_bytes.decode('utf-8') + decoded_bytes = encoded_token.encode("ascii") + convertedbytes = base64.b64decode(decoded_bytes) + decoded_token = convertedbytes.decode("ascii") + print('token decoded successfully') return decoded_token @@ -156,6 +158,7 @@ def decode_token(encoded_token): if isImageFile(filename): with open(path, 'rb') as file: image = file.read() + print('image processing') content = base64.b64encode(image).decode('utf-8') else: with open(path, 'r') as file: @@ -166,5 +169,6 @@ def decode_token(encoded_token): commitAndUpdateRef(repo,tree_content,base_ref.commit,branch) runWorkflow(repo,upstream_repo) except Exception as e: + print(e) print("Some error Occured.Please try again after some time.",end="") exit(0) \ No newline at end of file