Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ async def get_program_tickets_user():
try:
print('getting data for users leader board')
request_data = request.body._data

filter = ''
if request_data:
filter = json.loads(request_data.decode('utf-8'))
Expand All @@ -324,77 +325,81 @@ async def get_program_tickets_user():

issue_result = []

# 6-month cutoff date
# 6-month cutoff
six_months_ago = datetime.utcnow() - timedelta(days=180)

for issue in all_issues:
reqd_skills = []
project_type = []

# -------- Parse created_at --------
# -------- FIXED DATE PARSING --------
created_at_raw = issue["issue"]["created_at"]
created_at = None

if created_at_raw:
try:
created_at = datetime.strptime(created_at_raw, "%a, %d %b %Y %H:%M:%S %Z")
created_at = parser.parse(created_at_raw)
except:
created_at = None

# -------- FILTER: Skip if older than 6 months --------
# -------- FILTER OLD TICKETS --------
if created_at and created_at < six_months_ago:
continue

# -------- Process required skills --------
# -------- Skills --------
if issue["issue"]["technology"]:
reqd_skills = [
skill.strip().replace('"', '')
for skill in issue["issue"]["technology"].split(',')
]

# -------- Process project type --------
# -------- Project Type --------
if issue["issue"]["project_type"]:
project_type = [
ptype.strip().replace('"', '')
for ptype in issue["issue"]["project_type"].split(',')
p.strip().replace('"', '')
for p in issue["issue"]["project_type"].split(',')
]

# -------- Process labels --------
# -------- Labels --------
labels = issue["issue"]["labels"]
if len(labels) == 1:
labels = ['C4GT Coding']
else:
labels = [label for label in labels if label not in ['C4GT Community', 'C4GT Bounty']]
labels = [
label for label in labels
if label not in ['C4GT Community', 'C4GT Bounty']
]
if not labels:
labels = ['C4GT Coding']

# -------- Contributor name extraction --------
# -------- Contributor Name --------
contributors_data = issue["contributors_registration"]
contributors_name = None

if contributors_data:
contributors_name = contributors_data.get("name")
if not contributors_name:
contributors_url = contributors_data["github_url"].split('/')
contributors_name = contributors_url[-1] if contributors_url else None
url_parts = contributors_data["github_url"].split("/")
contributors_name = url_parts[-1] if url_parts else None

# -------- Final formatted response --------
# -------- Final Response --------
res = {
"created_at": created_at_raw if created_at_raw else None,
"created_at": created_at_raw,
"name": issue["issue"]["title"],
"complexity": issue["issue"]["complexity"],
"category": labels,
"reqd_skills": reqd_skills if reqd_skills else None,
"reqd_skills": reqd_skills or None,
"issue_id": issue["issue"]["issue_id"],
"url": issue["issue"]["link"],
"ticket_points": issue["points"]["points"] if issue["points"] else None,
"mentors": ["Amoghavarsh"],
"status": issue["issue"]["status"],
"domain": issue["issue"]["domain"],
"organization": issue["org"]["name"],
"closed_at": "2024-08-06T06:59:10+00:00",
"assignees": contributors_name if contributors_data else None,
"project_type": project_type if reqd_skills else None,
"is_assigned": True if contributors_data else False
"closed_at": issue["issue"]["closed_at"],
"assignees": contributors_name,
"project_type": project_type or None,
"is_assigned": bool(contributors_data),
}

issue_result.append(res)
Expand All @@ -405,8 +410,6 @@ async def get_program_tickets_user():
print('Exception occurred in getting users leaderboard data ', e)
return 'failed'



@app.route('/migrate-tickets')
async def migrate_tickets():
try:
Expand Down