()
Find all pull requests acted on by Kodiak.
Find all pull requests acted on by Kodiak.
Find all pull requests acted on by Kodiak .
def generate() -> None:
        """
        Find all pull requests acted on by Kodiak.
        """
        user_pull_request_activity_progress: Optional[
            UserPullRequestActivityProgress
        ] = UserPullRequestActivityProgress.objects.order_by("-min_date").first()
        where_clause = []
        if user_pull_request_activity_progress is not None:
            where_clause.append(
                f"created_at > '{user_pull_request_activity_progress.min_date.isoformat()}'::timestamp"
            )

        if where_clause:
            where = " AND " + " AND ".join(where_clause)
        else:
            where = ""
        with connection.cursor() as cursor:
            cursor.execute(
                f"""
INSERT INTO user_pull_request_activity (
    "id",
    "created_at",
    "modified_at",
    "github_installation_id",
    "github_repository_name",
    "github_pull_request_number",
    "github_user_login",
    "github_user_id",
    "is_private_repository",
    "activity_date",
    "opened_pull_request")
SELECT
    uuid_generate_v4 () "id",
    NOW() created_at,
    NOW() modified_at,
    (payload -> 'installation' ->> 'id')::int github_installation_id,
    (payload -> 'repository' ->> 'name') github_repository_name,
    (payload -> 'pull_request' ->> 'number')::int github_pull_request_number,
    max(payload -> 'sender' ->> 'login') github_user_login,
    (payload -> 'sender' ->> 'id')::integer github_user_id,
    bool_or((payload -> 'repository' ->> 'private')::boolean) is_private_repository,
    created_at::date activity_date,
    bool_or(payload ->> 'action' = 'opened') opened_pull_request
FROM
    github_event
WHERE
    event_name in ('pull_request', 'pull_request_review')
    {where}
GROUP BY
    github_installation_id,
    github_repository_name,
    github_pull_request_number,
    github_user_id,
    activity_date
HAVING (payload -> 'installation' ->> 'id')::int IS NOT NULL
    AND (payload -> 'repository' ->> 'name') IS NOT NULL
    AND (payload -> 'pull_request' ->> 'number')::int IS NOT NULL
    AND max(payload -> 'sender' ->> 'login') IS NOT NULL
    AND (payload -> 'sender' ->> 'id')::integer IS NOT NULL
ON CONFLICT ON CONSTRAINT unique_user_pull_request_activity
    DO UPDATE
        SET opened_pull_request = (excluded.opened_pull_request OR user_pull_request_activity.opened_pull_request),
        is_private_repository = (excluded.is_private_repository OR user_pull_request_activity.is_private_repository);
"""
            )
        UserPullRequestActivityProgress.objects.create(min_date=timezone.now())
def generate ( ) -> None : user_pull_request_activity_progress : Optional [ UserPullRequestActivityProgress ] = UserPullRequestActivityProgress . objects . order_by ( "-min_date" ) . first ( ) where_clause = [ ] if user_pull_request_activity_progress is not None : where_clause . append ( f"created_at > '{user_pull_request_activity_progress.min_date.isoformat()}'::timestamp" ) if where_clause : where = " AND " + " AND " . join ( where_clause ) else : where = "" with connection . cursor ( ) as cursor : cursor . execute ( f"""
INSERT INTO user_pull_request_activity (
    "id",
    "created_at",
    "modified_at",
    "github_installation_id",
    "github_repository_name",
    "github_pull_request_number",
    "github_user_login",
    "github_user_id",
    "is_private_repository",
    "activity_date",
    "opened_pull_request")
SELECT
    uuid_generate_v4 () "id",
    NOW() created_at,
    NOW() modified_at,
    (payload -> 'installation' ->> 'id')::int github_installation_id,
    (payload -> 'repository' ->> 'name') github_repository_name,
    (payload -> 'pull_request' ->> 'number')::int github_pull_request_number,
    max(payload -> 'sender' ->> 'login') github_user_login,
    (payload -> 'sender' ->> 'id')::integer github_user_id,
    bool_or((payload -> 'repository' ->> 'private')::boolean) is_private_repository,
    created_at::date activity_date,
    bool_or(payload ->> 'action' = 'opened') opened_pull_request
FROM
    github_event
WHERE
    event_name in ('pull_request', 'pull_request_review')
    {where}
GROUP BY
    github_installation_id,
    github_repository_name,
    github_pull_request_number,
    github_user_id,
    activity_date
HAVING (payload -> 'installation' ->> 'id')::int IS NOT NULL
    AND (payload -> 'repository' ->> 'name') IS NOT NULL
    AND (payload -> 'pull_request' ->> 'number')::int IS NOT NULL
    AND max(payload -> 'sender' ->> 'login') IS NOT NULL
    AND (payload -> 'sender' ->> 'id')::integer IS NOT NULL
ON CONFLICT ON CONSTRAINT unique_user_pull_request_activity
    DO UPDATE
        SET opened_pull_request = (excluded.opened_pull_request OR user_pull_request_activity.opened_pull_request),
        is_private_repository = (excluded.is_private_repository OR user_pull_request_activity.is_private_repository);
""" ) UserPullRequestActivityProgress . objects . create ( min_date = timezone . now ( ) )