repocribro.models¶
Mixins¶
Anonymous¶
-
class
repocribro.models.
Anonymous
¶ Bases:
flask_login.mixins.AnonymousUserMixin
,repocribro.models.UserMixin
Anonymous (not logged) user representation
-
_roles
= []¶
-
has_role
(role)¶ Check whether has the role
Parameters: role ( repocribro.models.RoleMixin
) – Role to be checkedReturns: 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 testedReturns: False, anonymous can not own repository Return type: bool
-
rolename
= 'anonymous'¶
-
rolenames
¶ Get names of all roles of that user
Returns: Empty list, anonymous has no roles Return type: list of str
-
roles
¶
-
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
- repo (
-
classmethod
set_role
(role)¶
-
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 withReturns: 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 withReturns: If names are not equal Return type: bool
-
permits
(privilege)¶ Check if action priviledge is permitted in this role
Parameters: privilege – privilege to be tested Type: str Returns: if it is permitted Return type: bool
-
priv_regex
= re.compile('[a-z_\\?\\*]+')¶
-
valid_privileges
()¶ Checks if privileges string is valid
Returns: if privileges string is valid 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
-
classmethod
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 testedReturns: If user owns repo Return type: bool
-
privileges
(all_privileges=frozenset())¶ Filter given privileges if are applicable for the user
Parameters: all_privileges (set of str) – set of all privileges to be filtered Returns: set of applicable privileges Return type: set of str
-
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
- repo (
-
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
= {'author_email': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'author_name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'distinct': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'message': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'push': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'push_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'sha': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
The git author’s email address.
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
= {'avatar_url': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'blog_url': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'company': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'description': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'email': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'github_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'location': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'login': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'repositories': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'type': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
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
= {'after': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'before': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'commits': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'distinct_size': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'github_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'ref': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'repository': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'repository_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'sender_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'sender_login': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'size': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'timestamp': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
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, privileges, description)¶ Bases:
flask_sqlalchemy.Model
,repocribro.models.RoleMixin
User account role in the application
-
__init__
(name, privileges, description)¶
-
__repr__
()¶ Standard string representation of DB object
Returns: Unique string representation Return type: str
-
_sa_class_manager
= {'description': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'privileges': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'user_accounts': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
description
¶ Description (purpose, notes, …) of the role
-
id
¶ Unique identifier of the role
-
name
¶ Unique name of the role
-
privileges
¶ Serialized list of privileges
-
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
= {'author_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'author_login': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'body': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'created_at': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'draft': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'github_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'prerelease': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'published_at': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'repository': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'repository_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'sender_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'sender_login': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'tag_name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'url': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
ID of author
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, parent_name, full_name, name, languages, url, description, topics, 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, parent_name, full_name, name, languages, url, description, topics, 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
= {'description': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'full_name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'github_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'languages': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'last_event': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'members': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'owner': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'owner_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'parent_name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'private': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'pushes': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'releases': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'secret': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'topics': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'url': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'visibility_type': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'webhook_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
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
-
description
¶
-
events_updated
()¶ Set that now was performed last events update of repo
Todo
How about some past events before adding to app?
-
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
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
-
parent_name
¶ Full name of repository which this is fork of
-
private
¶
-
pushes
¶ Registered pushes to repository
-
releases
¶ Registered releases for repository
-
secret
¶
-
static
serialize_topics
(topics)¶ Make string from topics list from GitHub
Parameters: topics (list of str) – List of topics (strings without whitespaces) Returns: Serialized list of topics Return type: str
-
topics
¶
-
update_from_dict
(repo_dict)¶ Update repository attributes from GitHub data dict
Parameters: repo_dict (dict) – GitHub data containing repository
-
update_languages
(languages_dict)¶ Set languages field from GitHub dict
Parameters: languages_dict (dict) – language - bytes dict
-
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
= {'avatar_url': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'blog_url': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'company': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'description': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'email': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'github_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'hireable': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'location': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'login': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'org_repositories': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'repositories': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'type': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'user_account': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'user_account_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
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
= {'active': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'created_at': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'github_user': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'roles': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
active
¶ Flag if the account is active or banned
-
created_at
¶ Timestamp where account was created
-
default_rolename
= 'user'¶
-
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
-