Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an attribute to indicate task state #236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions gci/students.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def cleanse_instances(instances, tasks):
for instance_id, instance
in instances.items()
if instance['status'] not in PRIVATE_INSTANCE_STATUSES
and tasks[instance['task_definition_id']]
.__contains__('state').__eq__('COMPLETED')
and instance['task_definition_id'] in tasks
and instance['task_definition_id'] not in beginner_tasks(tasks)
)
Expand Down
42 changes: 41 additions & 1 deletion gci/task.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import requests
import os

from .config import load_cache

_tasks = None
Expand Down Expand Up @@ -81,12 +84,49 @@ def beginner_tasks(tasks):

def strip_mentors(tasks):
for task in tasks.values():
del task['mentors']
if task.__contains__('mentors'):
del task['mentors']


def cleanse_tasks(tasks):
tokens = {
'GH_TOKEN': os.environ.get('GH_TOKEN'),
}

KVGarg marked this conversation as resolved.
Show resolved Hide resolved
for task in tasks.values():
if (task['max_instances'] == 1 and
str(task['external_url']).__contains__('issues/')):
task['state'] = get_task_state(task['external_url'], tokens)

cleansed_tasks = published_tasks(tasks)

strip_mentors(tasks)

return cleansed_tasks


def get_task_state(task_url, tokens):
if task_url.__contains__('github'):
task_url = task_url.replace('github.com', 'api.github.com/repos')
headers = {'Authorization': 'token {}'.format(tokens['GH_TOKEN'])}
else:
issue_id = task_url.split('issues/')[1]
project_id = ((task_url.split('https://gitlab.com/')
[1]).split('/issues')[0]).replace('/', '%2F')
task_url = 'https://gitlab.com/api/v4/projects/{}/issues/{}'.format(
project_id, issue_id)
headers = {}

if tokens['GH_TOKEN']:
task_data = requests.get(task_url, headers=headers).json()
else:
task_data = requests.get(task_url).json()

if task_data['state'] == 'closed':
task_state = 'COMPLETED'
elif task_data['state'] == 'open' and len(task_data['assignees']) > 0:
task_state = 'CLAIMED'
else:
task_state = 'AVAILABLE'

return task_state