MCPcopy Index your code
hub / github.com/diffgram/diffgram / get_next_task_with_issues

Method get_next_task_with_issues

shared/database/task/task.py:398–433  ·  view source on GitHub ↗

Given the task_id, find the next task that is attached to an issue sorting by task creation date. :param session: :param task_id: :return: next task ID or None is not next task.

(session, task_id)

Source from the content-addressed store, hash-verified

396
397 @staticmethod
398 def get_next_task_with_issues(session, task_id):
399 """
400 Given the task_id, find the next task that is attached to an issue
401 sorting by task creation date.
402 :param session:
403 :param task_id:
404 :return: next task ID or None is not next task.
405 """
406 task = Task.get_by_id(session, task_id = task_id)
407
408 tasks_query = session.query(Task).filter(Task.status != 'archived',
409 Task.job_id == task.job_id)
410 tasks = tasks_query.all()
411 task_ids = [task.id for task in tasks]
412 discussions = session.query(dr.DiscussionRelation) \
413 .join(discussion.Discussion, dr.DiscussionRelation.discussion_id == discussion.Discussion.id) \
414 .filter(dr.DiscussionRelation.task_id.isnot(None)) \
415 .filter(dr.DiscussionRelation.task_id.in_(task_ids), discussion.Discussion.status == 'open') \
416 .order_by(discussion.Discussion.created_time.desc())
417
418 seen = set()
419 task_ids_with_issues = [x.task_id for x in discussions if not (x.task_id in seen or seen.add(x.task_id))]
420
421 if len(task_ids_with_issues) == 0:
422 return None
423
424 if task_id not in task_ids_with_issues:
425 # If the provided task_id has no issues we simply return the first one that has issues.
426 return task_ids_with_issues[0]
427 elif task_ids_with_issues.index(task_id) == len(task_ids_with_issues) - 1:
428 # If the provded task_id is the last one we circle back to the first task with issues
429 return task_ids_with_issues[0]
430 else:
431 # If the provided task anything else except the last element we return the next task in the list.
432 index_current = task_ids_with_issues.index(task_id)
433 return task_ids_with_issues[index_current + 1]
434
435 def request_next_task_by_project(
436 session,

Callers 1

task_next_issue_coreFunction · 0.80

Calls 2

get_by_idMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected