3
3
from io import BytesIO
4
4
import aiohttp , asyncio
5
5
import dotenv , os , json , urllib , sys , dateutil , datetime , sys
6
+
7
+ from githubdatapipeline .issues .processor import get_url
6
8
from utils .github_adapter import GithubAdapter
7
9
from utils .dispatcher import dispatch_event
10
+ from utils .link_pr_issue import AddIssueId
8
11
from utils .webhook_auth import verify_github_webhook
9
- from utils .db import SupabaseInterface , PostgresORM
12
+ from shared_migrations .db . server import ServerQueries
10
13
from events .ticketEventHandler import TicketEventHandler
11
14
from events .ticketFeedbackHandler import TicketFeedbackHandler
12
15
from githubdatapipeline .pull_request .scraper import getNewPRs
22
25
from datetime import datetime
23
26
from quart_cors import cors
24
27
from utils .migrate_tickets import MigrateTickets
28
+ from utils .migrate_users import MigrateContributors
25
29
26
30
scheduler = AsyncIOScheduler ()
27
31
@@ -43,7 +47,7 @@ async def get_github_data(code, discord_id):
43
47
async with aiohttp .ClientSession () as session :
44
48
github_response = await GithubAdapter .get_github_data (code )
45
49
auth_token = (github_response )["access_token" ]
46
-
50
+
47
51
headers = {
48
52
"Accept" : "application/json" ,
49
53
"Authorization" : f"Bearer { auth_token } "
@@ -67,15 +71,16 @@ async def get_github_data(code, discord_id):
67
71
"discord_id" : int (discord_id ),
68
72
"github_id" : github_id ,
69
73
"github_url" : f"https://github.com/{ github_username } " ,
70
- "email" : ',' .join (private_emails )
74
+ "email" : ',' .join (private_emails ),
75
+ "joined_at" : datetime .now ()
71
76
}
72
77
73
78
return user_data
74
-
79
+
75
80
async def comment_cleaner ():
76
81
while True :
77
82
await asyncio .sleep (5 )
78
- comments = await PostgresORM ().readAll ("app_comments" )
83
+ comments = await ServerQueries ().readAll ("app_comments" )
79
84
for comment in comments :
80
85
utc_now = datetime .datetime .utcnow ().replace (tzinfo = datetime .timezone .utc )
81
86
update_time = dateutil .parser .parse (comment ["updated_at" ])
@@ -87,7 +92,7 @@ async def comment_cleaner():
87
92
issue_id = comment ["issue_id" ]
88
93
comment = await TicketFeedbackHandler ().deleteComment (owner , repo , comment_id )
89
94
print (f"Print Delete Task,{ comment } " , file = sys .stderr )
90
- print (await PostgresORM ().deleteComment (issue_id ,"app_comments" ))
95
+ print (await ServerQueries ().deleteComment (issue_id ,"app_comments" ))
91
96
92
97
async def fetch_github_issues_from_repo (owner , repo ):
93
98
try :
@@ -96,11 +101,11 @@ async def fetch_github_issues_from_repo(owner, repo):
96
101
return response
97
102
else :
98
103
print (f"Failed to get issues: { response } " )
99
-
104
+
100
105
except Exception as e :
101
106
logger .info (e )
102
107
raise Exception
103
-
108
+
104
109
repositories_list = [
105
110
"KDwevedi/c4gt-docs" ,
106
111
"KDwevedi/testing_for_github_app"
@@ -159,23 +164,23 @@ async def verify(githubUsername):
159
164
160
165
@app .route ("/misc_actions" )
161
166
async def addIssues ():
162
- tickets = await PostgresORM ().readAll ("ccbp_tickets" )
167
+ tickets = await ServerQueries ().readAll ("ccbp_tickets" )
163
168
count = 1
164
169
for ticket in tickets :
165
170
print (f'{ count } /{ len (tickets )} ' )
166
171
count += 1
167
172
if ticket ["status" ] == "closed" :
168
173
# if ticket["api_endpoint_url"] in ["https://api.github.com/repos/glific/glific/issues/2824"]:
169
174
await TicketEventHandler ().onTicketClose ({"issue" :await get_url (ticket ["api_endpoint_url" ])})
170
-
171
175
172
- return ''
176
+
177
+ return ''
173
178
174
179
175
180
@app .route ("/update_profile" , methods = ["POST" ])
176
181
async def updateGithubStats ():
177
182
webhook_data = await request .json
178
- data = await PostgresORM ().read ("github_profile_data" , filters = {"dpg_points" : ("gt" , 0 )})
183
+ data = await ServerQueries ().read ("github_profile_data" , filters = {"dpg_points" : ("gt" , 0 )})
179
184
GithubProfileDisplay ().update (data )
180
185
return 'Done'
181
186
@@ -186,7 +191,7 @@ async def do_update():
186
191
while True :
187
192
print ("Starting Update" )
188
193
await asyncio .sleep (21600 )
189
- data = await PostgresORM ().read ("github_profile_data" , filters = {"dpg_points" : ("gt" , 0 )})
194
+ data = await ServerQueries ().read ("github_profile_data" , filters = {"dpg_points" : ("gt" , 0 )})
190
195
GithubProfileDisplay ().update (data )
191
196
192
197
@@ -216,7 +221,7 @@ async def test():
216
221
@app .route ("/register/<discord_userdata>" )
217
222
async def register (discord_userdata ):
218
223
print ("🛠️SUCCESSFULLY REDIECTED FROM GITHUB TO SERVER" , locals (), file = sys .stderr )
219
- postgres_client = PostgresORM ()
224
+ postgres_client = ServerQueries ()
220
225
221
226
discord_id = discord_userdata
222
227
print ("🛠️SUCCESFULLY DEFINED FUNCTION TO POST TO SUPABASE" , locals (), file = sys .stderr )
@@ -233,7 +238,7 @@ async def register(discord_userdata):
233
238
print ("🛠️PUSHED USER DETAILS TO SUPABASE" )
234
239
except Exception as e :
235
240
print ("🛠️ENCOUNTERED EXCEPTION PUSHING TO SUPABASE" ,e , file = sys .stderr )
236
-
241
+
237
242
print ("🛠️FLOW COMPLETED SUCCESSFULLY, REDIRECTING TO DISCORD" , file = sys .stderr )
238
243
return await render_template ('success.html' ), {"Refresh" : f'1; url=https://discord.com/channels/{ os .getenv ("DISCORD_SERVER_ID" )} ' }
239
244
@@ -243,14 +248,14 @@ async def event_handler():
243
248
try :
244
249
data = await request .json
245
250
print ('data is ' , data )
246
- secret_key = os .getenv ("WEBHOOK_SECRET" )
251
+ secret_key = os .getenv ("WEBHOOK_SECRET" )
247
252
248
253
verification_result , error_message = await verify_github_webhook (request ,secret_key )
249
-
250
- postgres_client = PostgresORM . get_instance ()
254
+
255
+ postgres_client = ServerQueries ()
251
256
event_type = request .headers .get ("X-GitHub-Event" )
252
257
await dispatch_event (event_type , data , postgres_client )
253
-
258
+
254
259
return data
255
260
except Exception as e :
256
261
logger .info (e )
@@ -268,11 +273,11 @@ async def discord_metrics():
268
273
data = {
269
274
"product_name" : product_name ,
270
275
"mentor_messages" : value ['mentor_messages' ],
271
- "contributor_messages" : value ['contributor_messages' ]
276
+ "contributor_messages" : value ['contributor_messages' ]
272
277
}
273
278
discord_data .append (data )
274
279
275
- data = await PostgresORM ().add_discord_metrics (discord_data )
280
+ data = await ServerQueries ().add_discord_metrics (discord_data )
276
281
return data
277
282
278
283
@app .route ("/metrics/github" , methods = ['POST' ])
@@ -287,16 +292,16 @@ async def github_metrics():
287
292
"closed_prs" : value ['closed_prs' ],
288
293
"open_issues" : value ['open_issues' ],
289
294
"closed_issues" : value ['closed_issues' ],
290
- "number_of_commits" : value ['number_of_commits' ],
295
+ "number_of_commits" : value ['number_of_commits' ],
291
296
}
292
297
github_data .append (data )
293
298
294
- data = await PostgresORM ().add_github_metrics (github_data )
299
+ data = await ServerQueries ().add_github_metrics (github_data )
295
300
return data
296
301
297
302
@app .route ("/role-master" )
298
303
async def get_role_master ():
299
- role_masters = await PostgresORM ().readAll ("role_master" )
304
+ role_masters = await ServerQueries ().readAll ("role_master" )
300
305
print ('role master ' , role_masters )
301
306
return role_masters .data
302
307
@@ -308,7 +313,7 @@ async def get_program_tickets_user():
308
313
filter = ''
309
314
if request_data :
310
315
filter = json .loads (request_data .decode ('utf-8' ))
311
- postgres_client = PostgresORM . get_instance ()
316
+ postgres_client = ServerQueries ()
312
317
all_issues = await postgres_client .fetch_filtered_issues (filter )
313
318
print ('length of all issue ' , len (all_issues ))
314
319
@@ -334,10 +339,10 @@ async def get_program_tickets_user():
334
339
335
340
contributors_data = issue ["contributors_registration" ]
336
341
if contributors_data :
337
- contributors_name = contributors_data ["name" ]
342
+ contributors_name = contributors_data ["name" ]
338
343
if contributors_name :
339
344
pass
340
- else :
345
+ else :
341
346
contributors_url = contributors_data ["github_url" ].split ('/' )
342
347
contributors_name = contributors_url [- 1 ] if contributors_url else None
343
348
@@ -377,5 +382,32 @@ async def migrate_tickets():
377
382
print ('exception occured ' , e )
378
383
return 'failed'
379
384
385
+
386
+ @app .route ('/migrate-contributors' )
387
+ async def migrate_contributors ():
388
+ try :
389
+ migrator = MigrateContributors () # Create an instance
390
+
391
+ asyncio .create_task (migrator .migration ())
392
+ return 'migration started'
393
+ except Exception as e :
394
+ print ('exception occured ' , e )
395
+ return 'failed'
396
+
397
+
398
+ @app .route ('/add-issue-id-pr' )
399
+ async def add_issue_id_pr ():
400
+ try :
401
+ migrator = AddIssueId () # Create an instance
402
+
403
+ asyncio .create_task (migrator .process_prs ())
404
+
405
+ # return await migrator.process_prs()
406
+ return 'migration started'
407
+ except Exception as e :
408
+ print ('exception occured ' , e )
409
+ return 'failed'
410
+
411
+
380
412
if __name__ == '__main__' :
381
413
app .run ()
0 commit comments