55# Intializing the Variables
66# Hashed token
77BOT_TOKEN = 'Z2l0aHViX3BhdF8xMUFYS0pGVFkwd2xwT0dmYldFOTBBXzN3Nkx2THpiaUFKek5pTDdqNlpLUzVwUUpoTlJWR3dtNnM0NWNDa0RmWTJaTTZLSUpHRHhERlhrZlJS'
8- REPO_NAME = 'concore-studies' #repo name
9- OWNER_NAME = 'parteekcoder123' #bot account name
8+ BOT_REPO_NAME = 'concore-studies-staging' #bot repo name
9+ UPSTREAM_REPO_NAME = 'concore-studies' #bot repo name
10+ OWNER_NAME = 'ControlCore-Project' #account name
1011STUDY_NAME = sys .argv [1 ]
1112STUDY_NAME_PATH = sys .argv [2 ]
1213AUTHOR_NAME = sys .argv [3 ]
1314BRANCH_NAME = sys .argv [4 ]
1415PR_TITLE = sys .argv [5 ]
1516PR_BODY = sys .argv [6 ]
16- UPSTREAM_OWNER = 'ControlCore-Project' # upstream to which examples should be contributed
1717
1818# Defining Functions
1919def checkInputValidity ():
@@ -33,7 +33,7 @@ def getPRs(upstream_repo):
3333 exit (0 )
3434
3535def printPR (pr ):
36- print (f'Check your example here https://github.com/{ UPSTREAM_OWNER } /pulls/' + str (pr .number ),end = "" )
36+ print (f'Check your example here https://github.com/{ OWNER_NAME } / { UPSTREAM_REPO_NAME } /pulls/' + str (pr .number ),end = "" )
3737
3838def anyOpenPR (upstream_repo ):
3939 pr = getPRs (upstream_repo )
@@ -44,7 +44,7 @@ def anyOpenPR(upstream_repo):
4444 break
4545 return openPr
4646
47- def commitAndUpdateRef (upstream_repo , repo ,tree_content ,commit ,branch ):
47+ def commitAndUpdateRef (repo ,tree_content ,commit ,branch ):
4848 try :
4949 new_tree = repo .create_git_tree (tree = tree_content ,base_tree = commit .commit .tree )
5050 new_commit = repo .create_git_commit ("commit message" ,new_tree ,[commit .commit ])
@@ -63,20 +63,10 @@ def appendBlobInTree(repo,content,file_path,tree_content):
6363 tree_content .append ( github .InputGitTreeElement (path = file_path ,mode = "100644" ,type = "blob" ,sha = blob .sha ))
6464
6565
66- def fetchUpstream (repo ,base_sha ,branch ):
67- try :
68- result = repo .compare (base = base_sha ,head = branch .commit .commit .sha )
69- if result .behind_by > 0 :
70- ref = repo .get_git_ref ("heads/" + branch .name )
71- ref .edit (base_sha )
72- except Exception as e :
73- exit (0 )
74-
75-
7666def runWorkflow (repo ,upstream_repo ):
7767 openPR = anyOpenPR (upstream_repo )
7868 if openPR == None :
79- workflow_runned = repo .get_workflow (id_or_name = "pull_request.yml" ).create_dispatch (ref = BRANCH_NAME ,inputs = {'title' :PR_TITLE ,'body' :PR_BODY ,'upstreamRepo' :UPSTREAM_OWNER , 'botRepo ' :OWNER_NAME , 'repo' : REPO_NAME })
69+ workflow_runned = repo .get_workflow (id_or_name = "pull_request.yml" ).create_dispatch (ref = BRANCH_NAME ,inputs = {'title' :PR_TITLE ,'body' :PR_BODY ,'upstreamRepo' :UPSTREAM_REPO_NAME , 'account ' :OWNER_NAME })
8070 if not workflow_runned :
8171 print ("Some error occured.Please try after some time" )
8272 exit (0 )
@@ -103,12 +93,6 @@ def isImageFile(filename):
10393 _ , file_extension = os .path .splitext (filename )
10494 return file_extension .lower () in image_extensions
10595
106- # Encode Github Token
107- # def encode_token(token):
108- # encoded_bytes = base64.b64encode(token.encode('utf-8'))
109- # encoded_token = encoded_bytes.decode('utf-8')
110- # return encoded_token
111-
11296
11397# Decode Github Token
11498def decode_token (encoded_token ):
@@ -126,14 +110,14 @@ def decode_token(encoded_token):
126110 if BRANCH_NAME == "#" :
127111 BRANCH_NAME = AUTHOR_NAME + "_" + STUDY_NAME
128112 if PR_TITLE == "#" :
129- PR_TITLE = "Contributing Study " + AUTHOR_NAME + " " + STUDY_NAME
113+ PR_TITLE = f "Contributing Study { STUDY_NAME } by { AUTHOR_NAME } "
130114 if PR_BODY == "#" :
131- PR_BODY = "Study Contributed by " + AUTHOR_NAME
115+ PR_BODY = f "Study Name: { STUDY_NAME } \n Author Name: { AUTHOR_NAME } "
132116 AUTHOR_NAME = AUTHOR_NAME .replace (" " ,"_" )
133117 DIR_PATH = AUTHOR_NAME + '_' + STUDY_NAME
134118 g = Github (decode_token (BOT_TOKEN ))
135- repo = g .get_user (OWNER_NAME ).get_repo (REPO_NAME )
136- upstream_repo = g .get_repo (f'{ UPSTREAM_OWNER } /{ REPO_NAME } ' ) #controlcore-Project/concore
119+ repo = g .get_user (OWNER_NAME ).get_repo (BOT_REPO_NAME )
120+ upstream_repo = g .get_repo (f'{ OWNER_NAME } /{ UPSTREAM_REPO_NAME } ' ) #controlcore-Project/concore
137121 base_ref = upstream_repo .get_branch (repo .default_branch )
138122 branches = repo .get_branches ()
139123 BRANCH_NAME = BRANCH_NAME .replace (" " ,"_" )
@@ -172,7 +156,7 @@ def decode_token(encoded_token):
172156 file_path = f'{ DIR_PATH + path .removeprefix (STUDY_NAME_PATH )} '
173157 if (platform .uname ()[0 ]== 'Windows' ): file_path = file_path .replace ("\\ " ,"/" )
174158 appendBlobInTree (repo ,content ,file_path ,tree_content )
175- commitAndUpdateRef (upstream_repo , repo ,tree_content ,base_ref .commit ,branch )
159+ commitAndUpdateRef (repo ,tree_content ,base_ref .commit ,branch )
176160 runWorkflow (repo ,upstream_repo )
177161except Exception as e :
178162 print ("Some error Occured.Please try again after some time." ,end = "" )
0 commit comments