Esempio n. 1
0
def publish_tasks(tasks, issue_config, mentor_config_filename):
    client = GCIAPIClient(get_api_key('GCI'))
    projects = dict(get_projects(issue_config, yield_levels=False))

    for task_id, task in tasks.items():
        name = task['name']

        if 'status' in task:
            publish_flag = task['status']
            if publish_flag == 2:
                # TODO: unpublishing tasks if project disabled/blocked
                continue
            assert publish_flag == 1

        if not task['tags']:
            continue

        url = task['external_url']
        if not url:
            print(f'{task_id} {name} has no url')
            continue
        issue = get_issue(url)
        if not issue:
            print(f'{task_id} {name} {url} not recognised')
            continue

        project = projects.get(issue.repository.full_name.lower())

        if not project:
            print(f'{task_id} {url} project not recognised')
            continue

        disabled = project.get('disabled')
        if disabled:
            print(f'{task_id} {url} project disabled')
            continue

        repo_block = project.get('blocked')
        if repo_block and issue.number != repo_block:
            print(f'{task_id} {url} project blocked by {repo_block}')
            continue

        if not task['mentors'] and mentor_config_filename:
            allocate_mentors(task, mentor_config_filename)

            if not task['mentors']:
                print(f'{task_id} {url} no mentors available')
                continue

        task['status'] = 2

        pprint.pprint(task)
        if not ask_yes_no(f'Publish task {task_id}', 'no'):
            continue

        print(f'Publishing {task_id} {name} ..')
        client.UpdateTask(task_id, task)
Esempio n. 2
0
def index(request):
    try:
        client = get_api_key('GCI')
    except BaseException:
        client = None

    if client:
        s = gci_overview()
    else:
        s = ['GCI data not available']

    return HttpResponse('\n'.join(s))
Esempio n. 3
0
def unassigned_issues_activity_json(request):
    try:
        GH_TOKEN = get_api_key('GH')
    except Exception:
        return HttpResponse('[]')
    org_name = get_org_name()
    org_repo_name = org_name
    # Here 'org_repo_name' is the name of repository of a organization.
    # (assumed here, that name of repository is same as the organization name.)
    # But you can change 'org_repo_name' as per your requirement.
    repo_name = org_name + '/' + org_repo_name
    # 'repo_name' is a full name of repository e.g. `fossasia/susi_server`
    # which further used for query (assuming here 'org_name' is different from
    # 'org_repo_name')
    repo = GitHubRepository(GitHubToken(GH_TOKEN), repo_name)
    mr_requests = repo.merge_requests
    final_list = run(mr_requests)
    return HttpResponse(json.dumps(final_list))
Esempio n. 4
0
def inactive_issues_json(request):
    try:
        GH_TOKEN = get_api_key('GH')
    except Exception:
        return HttpResponse('[]')
    g1 = Github(GH_TOKEN)
    org_name = get_org_name()
    org = g1.get_organization(org_name)
    repo = org.get_repo(org_name)
    issues = repo.get_issues()
    issues_list = []
    for myissue in issues:
        labels = []
        for mylabel in myissue.labels:
            labels.append(mylabel.name)
        if 'status/blocked' not in labels:
            if myissue.state == 'open' and myissue.pull_request is None:
                issues_list.append(myissue)

    final_list = run(issues_list)
    return HttpResponse(json.dumps(final_list))
Esempio n. 5
0
def upload_tasks(tasks, mentor_config_filename):
    logger = logging.getLogger(__name__ + '.upload_tasks')
    client = GCIAPIClient(get_api_key('GCI'))

    for task in tasks:
        url = task['external_url']

        if not check_task(task):
            logger.warning(f'task check failed: {url}')
            continue

        existing_task = lookup_url(url, private=True)
        if existing_task:
            task_id = existing_task['id']
            logger.warning(f'{url} is task {task_id}')
            continue

        if not task['mentors'] and mentor_config_filename:
            allocate_mentors(task, mentor_config_filename)

        if task['status'] == 2 and not task['mentors']:
            logger.warning(f'{url}: Can not publish without mentors')
            continue

        pprint.pprint(task)
        if task['mentors']:
            if ask_yes_no(f'Publish task', 'no'):
                task['status'] = 2

        if task['status'] != 2:
            if not ask_yes_no(f'Create task', 'no'):
                continue

        client.NewTask(task)

        if task['status'] == 2:
            print('Task published.')
        else:
            print('Task created.')
Esempio n. 6
0
import logging

from gci.config import get_api_key

try:
    OH_TOKEN = get_api_key('OH')
except Exception as ex:
    OH_TOKEN = None
    logger = logging.getLogger(__name__)
    logger.critical('OH_TOKEN can not be obtained: %s' % ex)