Exemple #1
0
def repo_update(request):
    """
    Get the updates for the repo page.
    """
    if 'last_request' not in request.GET or 'limit' not in request.GET or 'repo_id' not in request.GET:
        return HttpResponseBadRequest('Missing parameters')

    this_request = TimeUtils.get_local_timestamp()
    repo_id = int(request.GET['repo_id'])
    limit = int(request.GET['limit'])
    last_request = int(float(request.GET['last_request'])) # in case it has decimals
    dt = timezone.localtime(timezone.make_aware(datetime.datetime.utcfromtimestamp(last_request)))
    repo = get_object_or_404(models.Repository, pk=repo_id)
    repos_status = RepositoryStatus.filter_repos_status([repo.pk], last_modified=dt)
    event_q = EventsStatus.get_default_events_query()
    event_q = event_q.filter(base__branch__repository=repo)[:limit]
    events_info = EventsStatus.multiline_events_info(event_q, last_modified=dt)
    # we also need to check if a PR closed recently
    closed = []
    for pr in models.PullRequest.objects.filter(repository=repo, closed=True, last_modified__gte=dt).values('id').all():
        closed.append({'id': pr['id']})

    return JsonResponse({'repo_status': repos_status,
        'closed': closed,
        'last_request': this_request,
        'events': events_info,
        'limit': limit,
        })
Exemple #2
0
def view_user(request, username):
    """
    Render the user page based on username
    Input:
        request[django.http.HttpRequest]
        username[str]: Name of the user
    """
    users = models.GitUser.objects.filter(name=username)
    if users.count() == 0:
        raise Http404('Bad username')

    repos = RepositoryStatus.get_user_repos_with_open_prs_status(username)
    pr_ids = []
    for r in repos:
        for pr in r["prs"]:
            pr_ids.append(pr["id"])
    event_list = EventsStatus.get_single_event_for_open_prs(pr_ids)
    evs_info = EventsStatus.multiline_events_info(event_list)
    data = {
        'username': username,
        'repos': repos,
        'events': evs_info,
        "update_interval": settings.EVENT_PAGE_UPDATE_INTERVAL,
    }
    return render(request, 'ci/user.html', data)
Exemple #3
0
def get_user_repos_info(request, limit=30, last_modified=None):
    """
    Get the information for the main view.
    This checks to see if the user has preferred repositories set, and if
    so then just shows those.
    You can also set the "default" parameter to show all the repositories.
    Input:
      request: django.http.HttpRequest
      limit: int: How many events to show
      last_modified: datetime: If not None, then only get information that has occured after this time.
    Return:
      (repo_info, evs_info, default):
        repo_info: list of dicts of repository status
        evs_info: list of dicts of event information
        default: Whether the default view was enforced
    """
    pks = []
    default = request.GET.get('default')
    if default is None:
        default = False
        for server in settings.INSTALLED_GITSERVERS:
            try:
                gitserver = models.GitServer.objects.get(
                    host_type=server["type"], name=server["hostname"])
            except models.GitServer.DoesNotExist:
                # Probably shouldn't happen in production but it does seem to
                # happen during selenium testing
                continue
            user = gitserver.signed_in_user(request.session)
            if user != None:
                for repo in user.preferred_repos.filter(
                        user__server=gitserver).all():
                    pks.append(repo.pk)
    else:
        default = True
    if pks:
        repos = RepositoryStatus.filter_repos_status(
            pks, last_modified=last_modified)
        evs_info = EventsStatus.events_filter_by_repo(
            pks, limit=limit, last_modified=last_modified)
    else:
        repos = RepositoryStatus.main_repos_status(last_modified=last_modified)
        evs_info = EventsStatus.all_events_info(limit=limit,
                                                last_modified=last_modified)
    return repos, evs_info, default
Exemple #4
0
def user_open_prs(request, username):
    """
    Get the updates for the main page.
    """
    users = models.GitUser.objects.filter(name=username)
    if users.count() == 0:
        return HttpResponseBadRequest('Bad username')

    if 'last_request' not in request.GET:
        return HttpResponseBadRequest('Missing parameters')

    this_request = TimeUtils.get_local_timestamp()
    last_request = int(float(request.GET['last_request'])) # in case it has decimals
    dt = timezone.localtime(timezone.make_aware(datetime.datetime.utcfromtimestamp(last_request)))
    repos = RepositoryStatus.get_user_repos_with_open_prs_status(username)
    repo_ids = []
    pr_ids = []
    for r in repos:
        repo_ids.append(r["id"])
        for pr in r["prs"]:
            pr_ids.append(pr["id"])
    event_list = EventsStatus.get_single_event_for_open_prs(pr_ids)
    evs_info = EventsStatus.multiline_events_info(event_list)
    ev_ids = []
    for e in evs_info:
        ev_ids.append(e["id"])
    # Now get the changed ones
    repos = RepositoryStatus.get_user_repos_with_open_prs_status(username, dt)
    evs_info = EventsStatus.multiline_events_info(event_list, dt)

    data = {'repos': repo_ids,
        'prs': pr_ids,
        'events': ev_ids,
        'repo_status': repos,
        'closed': [],
        'last_request': this_request,
        'changed_events': evs_info,
        }
    return JsonResponse(data)
Exemple #5
0
def do_repo_page(request, repo):
    """
    Render the repo page. This has the same layout as the main page but only for single repository.
    Input:
        request[django.http.HttpRequest]
        repo[models.Repository]
    """
    limit = 30
    repos_status = RepositoryStatus.filter_repos_status([repo.pk])
    events_info = EventsStatus.events_filter_by_repo([repo.pk], limit=limit)

    params = {
        'repo': repo,
        'repos_status': repos_status,
        'events_info': events_info,
        'event_limit': limit,
        'last_request': TimeUtils.get_local_timestamp(),
        'update_interval': settings.HOME_PAGE_UPDATE_INTERVAL
        }
    return render(request, 'ci/repo.html', params)