repocribro.models

Mixins

Anonymous

class repocribro.models.Anonymous

Bases: flask_login.mixins.AnonymousUserMixin

Anonymous (not logged) user representation

has_role(role)

Check whether has the role

Parameters:role (repocribro.models.RoleMixin) – Role to be checked
Returns:False, anonymous has no roles
Return type:bool
is_active

Check whether is user active

Returns:False, anonymous is not active
Return type:bool
owns_repo(repo)

Check if user owns the repository

Parameters:repo (repocribro.models.Repository) – Repository which shoudl be tested
Returns:False, anonymous can not own repository
Return type:bool
rolenames

Get names of all roles of that user

Returns:Empty list, anonymous has no roles
Return type:list of str
sees_repo(repo, has_secret=False)

Check if user is allowed to see the repo

Anonymous can see only public repos

Parameters:
  • repo (repocribro.models.Repository) – Repository which user want to see
  • has_secret (bool) – If current user knows the secret URL
Returns:

If user can see repo

Return type:

bool

RoleMixin

class repocribro.models.RoleMixin

Bases: object

Mixin for models representing roles

__eq__(other)

Equality of roles is based on names

Parameters:other (repocribro.models.RoleMixin or str) – Role or its name to be compared with
Returns:If names are equal
Return type:bool
__hash__()

Standard hashing via name

Returns:Hash of role
Return type:int
__ne__(other)

Inequality of roles is based on names

Parameters:other (repocribro.models.RoleMixin or str) – Role or its name to be compared with
Returns:If names are not equal
Return type:bool

SearchableMixin

class repocribro.models.SearchableMixin

Bases: object

Mixin for models that support fulltext query

classmethod fulltext_query(query_str, db_query)

Add fulltext filter to the DB query

Parameters:
  • query_str (str) – String to be queried
  • db_query (sqlalchemy.orm.query.Query) – Database query object
Returns:

Query with fulltext filter added

Return type:

sqlalchemy.orm.query.Query

UserMixin

class repocribro.models.UserMixin

Bases: flask_login.mixins.UserMixin

has_role(role)

Check whether has the role

Parameters:role (str) – Role to be checked
Returns:If user has a role
Return type:bool
is_active

Check whether is user active

Returns:If user is active (can login)
Return type:bool
owns_repo(repo)

Check if user owns the repository

Parameters:repo (repocribro.models.Repository) – Repository which shoudl be tested
Returns:If user owns repo
Return type:bool
rolenames

Get names of all roles of that user

Returns:List of names of roles of user
Return type:list of str
sees_repo(repo, has_secret=False)

Check if user is allowed to see the repo

Must be admin or owner to see not public repo

Parameters:
  • repo (repocribro.models.Repository) – Repository which user want to see
  • has_secret (bool) – If current user knows the secret URL
Returns:

If user can see repo

Return type:

bool

Models

Commit

class repocribro.models.Commit(sha, message, author_name, author_email, distinct, push)

Bases: flask_sqlalchemy.Model, repocribro.models.SearchableMixin, repocribro.models.SerializableMixin

Commit from GitHub

__init__(sha, message, author_name, author_email, distinct, push)
__repr__()

Standard string representation of DB object

Returns:Unique string representation
Return type:str
_sa_class_manager = <ClassManager of <class 'repocribro.models.Commit'> at 7fec12697b38>
author_email

The git author’s email address.

author_name

The git author’s name.

static create_from_dict(commit_dict, push)

Create new commit from GitHub and additional data

Parameters:
  • commit_dict (dict) – GitHub data containing commit
  • push (repocribro.models.Push) – Push where this commit belongs
Returns:

Created new commit

Return type:

repocribro.models.Commit

Todo

verify, there are some conflict in GitHub docs

distinct

Whether this commit is distinct from any that have been pushed before.

id

Unique identifier of the commit

message

The commit message.

push

Push where the commit belongs to

push_id

ID of push where the commit belongs to

sha

The SHA of the commit.

Organization

class repocribro.models.Organization(github_id, login, email, name, company, location, description, blog_url, avatar_url)

Bases: repocribro.models.RepositoryOwner, repocribro.models.SearchableMixin, repocribro.models.SerializableMixin

Organization from GitHub

__init__(github_id, login, email, name, company, location, description, blog_url, avatar_url)
__repr__()

Standard string representation of DB object

Returns:Unique string representation
Return type:str
_sa_class_manager = <ClassManager of <class 'repocribro.models.Organization'> at 7fec12686a98>
avatar_url
blog_url
company
static create_from_dict(org_dict)

Create new organization from GitHub data

Parameters:org_dict (dict) – GitHub data containing organization
Returns:Created new organization
Return type:repocribro.models.Organization
description
email
github_id
id
location
login
name
repositories
type

Push

class repocribro.models.Push(github_id, ref, after, before, size, distinct_size, timestamp, sender_login, sender_id, repository)

Bases: flask_sqlalchemy.Model, repocribro.models.SearchableMixin, repocribro.models.SerializableMixin

Push from GitHub

__init__(github_id, ref, after, before, size, distinct_size, timestamp, sender_login, sender_id, repository)
__repr__()

Standard string representation of DB object

Returns:Unique string representation
Return type:str
_sa_class_manager = <ClassManager of <class 'repocribro.models.Push'> at 7fec12697638>
after

The SHA of the most recent commit on ref after the push. (HEAD)

before

The SHA of the most recent commit on ref before the push.

commits

Commits within this push

static create_from_dict(push_dict, sender_dict, repo, timestamp=None)

Create new push from GitHub and additional data

This also creates commits of this push

Parameters:
  • push_dict (dict) – GitHub data containing push
  • sender_dict (dict) – GitHub data containing sender
  • repo (repocribro.models.Repository) – Repository where this push belongs
Returns:

Created new push

Return type:

repocribro.models.Push

distinct_size

The number of distinct commits in the push.

github_id

GitHub Push ID

id

Unique identifier of the push

ref

The full Git ref that was pushed.

repository

Repository where push belongs to

repository_id

ID of the repository where push belongs to

sender_id

ID of the sender

sender_login

Login of the sender

size

The number of commits in the push.

timestamp

Timestamp of push (when it was registered)

Role

class repocribro.models.Role(name, description)

Bases: flask_sqlalchemy.Model, repocribro.models.RoleMixin

User account role in the application

__init__(name, description)
__repr__()

Standard string representation of DB object

Returns:Unique string representation
Return type:str
_sa_class_manager = <ClassManager of <class 'repocribro.models.Role'> at 7fec126ef9a8>
description

Description (purpose, notes, ...) of the role

id

Unique identifier of the role

name

Unique name of the role

user_accounts

User accounts assigned to the role

Release

class repocribro.models.Release(github_id, tag_name, created_at, published_at, url, prerelease, draft, name, body, author_id, author_login, sender_login, sender_id, repository)

Bases: flask_sqlalchemy.Model, repocribro.models.SearchableMixin, repocribro.models.SerializableMixin

Release from GitHub

__init__(github_id, tag_name, created_at, published_at, url, prerelease, draft, name, body, author_id, author_login, sender_login, sender_id, repository)
__repr__()

Standard string representation of DB object

Returns:Unique string representation
Return type:str
_sa_class_manager = <ClassManager of <class 'repocribro.models.Release'> at 7fec126ba0e8>
author_id

ID of author

author_login

Login of author

body

Body with some description

static create_from_dict(release_dict, sender_dict, repo)

Create new release from GitHub and additional data

Parameters:
  • release_dict (dict) – GitHub data containing release
  • sender_dict (dict) – GitHub data containing sender
  • repo (repocribro.models.Repository) – Repository where this release belongs
Returns:

Created new release

Return type:

repocribro.models.Release

created_at

Timestamp when the release was created

draft

Flag if it’s just a draft

github_id

GitHub unique identifier

id

Unique identifier of the release

name

Name

prerelease

Flag if it’s just a prerelease

published_at

Timestamp when the release was published

repository

Repository where release belongs to

repository_id

ID of the repository where release belongs to

sender_id

ID of sender

sender_login

Login of sender

tag_name

Tag of the release

url

URL to release page

Repository

class repocribro.models.Repository(github_id, fork_of, full_name, name, languages, url, description, private, webhook_id, owner, visibility_type, secret=None)

Bases: flask_sqlalchemy.Model, repocribro.models.SearchableMixin, repocribro.models.SerializableMixin

Repository from GitHub

VISIBILITY_HIDDEN = 2

Constant representing hidden visibility within app

VISIBILITY_PRIVATE = 1

Constant representing private visibility within app

VISIBILITY_PUBLIC = 0

Constant representing public visibility within app

__init__(github_id, fork_of, full_name, name, languages, url, description, private, webhook_id, owner, visibility_type, secret=None)
__repr__()

Standard string representation of DB object

Returns:Unique string representation
Return type:str
_sa_class_manager = <ClassManager of <class 'repocribro.models.Repository'> at 7fec12697228>
static create_from_dict(repo_dict, owner, webhook_id=None, visibility_type=0, secret=None)

Create new repository from GitHub and additional data

Parameters:
  • repo_dict (dict) – GitHub data containing repository
  • owner (repocribro.model.RepositoryOwner) – Owner of this repository
  • webhook_id (int) – ID of registered webhook (if available)
  • visibility_type (int) – Visibility type within app (default: public)
  • secret (str) – Secret for hidden URL (if available)
Returns:

Created new repository

Return type:

repocribro.models.Repository

Todo

work with fork_of somehow

description
events_updated()

Set that now was performed last events update of repo

Todo

How about some past events before adding to app?

fork_of

GitHub id of repository which this is fork of

full_name

Full name (owner login + repository name)

generate_secret()

Generate new unique secret code for repository

github_id

GitHub unique identifier

id

Unique identifier of the repository

is_hidden

Check if repository is hidden within app

is_private

Check if repository is private within app

is_public

Check if repository is public within app

languages
last_event
static make_full_name(login, reponame)

Create full name from owner login name and repository name

Parameters:
  • login (str) – Owner login
  • reponame (str) – Name of repository (without owner login)
Returns:

Full name of repository

Return type:

str

members

Members of org repo within app

name
owner

Owner of repository

owner_id
owner_login

Get owner login from full name of repository

Returns:Owner login
Return type:str
private
pushes

Registered pushes to repository

releases

Registered releases for repository

secret
update_from_dict(repo_dict)

Update repository attributes from GitHub data dict

Parameters:repo_dict (dict) – GitHub data containing repository
url
visibility_type
webhook_id

User

class repocribro.models.User(github_id, login, email, name, company, location, bio, blog_url, avatar_url, hireable, user_account)

Bases: repocribro.models.RepositoryOwner, repocribro.models.SearchableMixin, repocribro.models.SerializableMixin

User from GitHub

__init__(github_id, login, email, name, company, location, bio, blog_url, avatar_url, hireable, user_account)
__repr__()

Standard string representation of DB object

Returns:Unique string representation
Return type:str
_sa_class_manager = <ClassManager of <class 'repocribro.models.User'> at 7fec126864a8>
avatar_url
blog_url
company
static create_from_dict(user_dict, user_account)

Create new user from GitHub data and related user account

Parameters:
  • user_dict (dict) – GitHub data containing user
  • user_account (repocribro.models.UserAccount) – User account in app for GH user
Returns:

Created new user

Return type:

repocribro.models.User

description
email
github_id
hireable

Flag whether is user hireable

id
location
login
name
org_repositories

Members of org repo within app

repositories
type
update_from_dict(user_dict)

Update user from GitHub data

Parameters:user_dict (dict) – GitHub data containing user
user_account

User’s account within app

user_account_id

ID of user’s account within app

UserAccount

class repocribro.models.UserAccount(**kwargs)

Bases: flask_sqlalchemy.Model, repocribro.models.UserMixin, repocribro.models.SearchableMixin

UserAccount in the repocribro app

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

__repr__()

Standard string representation of DB object

Returns:Unique string representation
Return type:str
_sa_class_manager = <ClassManager of <class 'repocribro.models.UserAccount'> at 7fec126d69a8>
active

Flag if the account is active or banned

created_at

Timestamp where account was created

github_user

Relation to the GitHub user connected to account

id

Unique identifier of the user account

login

Get login name for user account from related GH user

Returns:Login name
Return type:str
roles

Roles assigned to the user account