def single(parameters, argument): """Retrieve one (or more) extensions by id. EXTENSION_ID : integer Retrieve an extension identified by its unique numeric id.""" value = api.extension.fetch(parameters.critic, jsonapi.numeric_id(argument)) if "users" in parameters.context: if value.publisher != parameters.context["users"]: raise InvalidExtensionId(jsonapi.numeric_id(argument)) return value
def single(parameters, argument): """Retrieve one (or more) access tokens. TOKEN_ID : integer Retrieve an access token identified by its unique numeric id.""" value = api.accesstoken.fetch(parameters.critic, jsonapi.numeric_id(argument)) if "users" in parameters.context: if value.user != parameters.context["users"]: raise InvalidAccessTokenId(jsonapi.numeric_id(argument)) return value
def single(critic, context, argument, parameters): """Retrieve one (or more) users of this system. USER_ID : integer Retrieve a user identified by the user's unique numeric id.""" return api.user.fetch(critic, user_id=jsonapi.numeric_id(argument))
def single(critic, context, argument, parameters): """Retrieve one (or more) branches in the Git repositories. BRANCH_ID : integer Retrieve a branch identified by its unique numeric id.""" return api.branch.fetch(critic, branch_id=jsonapi.numeric_id(argument))
def single(parameters, argument): """Retrieve one (or more) files. FILE_ID : integer Retrieve a file identified by its unique numeric id.""" return api.file.fetch( parameters.critic, file_id=jsonapi.numeric_id(argument))
def single(critic, context, argument, parameters): """Retrieve one (or more) repositories on this system. REPOSITORY_ID : integer Retrieve a repository identified by its unique numeric id.""" return api.repository.fetch( critic, repository_id=jsonapi.numeric_id(argument))
def single(parameters, argument): """Retrieve one (or more) reviews in this system. REVIEW_ID : integer Retrieve a review identified by its unique numeric id.""" return Reviews.setAsContext(parameters, api.review.fetch( parameters.critic, review_id=jsonapi.numeric_id(argument)))
def single(parameters, argument): """Retrieve one (or more) rebases in this system. REBASE_ID : integer Retrieve a rebase identified by its unique numeric id.""" return Rebases.setAsContext(parameters, api.log.rebase.fetch( parameters.critic, rebase_id=jsonapi.numeric_id(argument)))
def single(parameters, argument): """Retrieve one (or more) repositories on this system. REPOSITORY_ID : integer Retrieve a repository identified by its unique numeric id.""" return Repositories.setAsContext(parameters, api.repository.fetch( parameters.critic, repository_id=jsonapi.numeric_id(argument)))
def single(critic, argument, parameters): """Retrieve one (or more) reviews in this system. REVIEW_ID : integer Retrieve a review identified by its unique numeric id.""" return Reviews.setAsContext( parameters, api.review.fetch(critic, review_id=jsonapi.numeric_id(argument)))
def deduce(critic, parameters): review = parameters.context.get("reviews") review_parameter = parameters.getQueryParameter("review") if review_parameter is not None: if review is not None: raise jsonapi.UsageError( "Redundant query parameter: review=%s" % review_parameter) review = api.review.fetch( critic, review_id=jsonapi.numeric_id(review_parameter)) return review
def single(parameters, argument): """Retrieve one (or more) reviewable file change. FILECHANGE_ID : integer Retrieve the reviewable changes to a file in a commit identified by its unique numeric id.""" return api.reviewablefilechange.fetch(parameters.critic, jsonapi.numeric_id(argument))
def deduce(parameters): batch = parameters.context.get("batches") batch_parameter = parameters.getQueryParameter("batch") if batch_parameter is not None: if batch is not None: raise jsonapi.UsageError( "Redundant query parameter: batch=%s" % batch_parameter) batch = api.batch.fetch( parameters.critic, jsonapi.numeric_id(batch_parameter)) return batch
def single(parameters, argument): """Retrieve one (or more) access control profiles. PROFILE_ID : integer Retrieve an access control profile identified by the profile's unique numeric id.""" return api.accesscontrolprofile.fetch( parameters.critic, profile_id=jsonapi.numeric_id(argument))
def single(parameters, argument): """Retrieve one (or more) reviewable file change. FILECHANGE_ID : integer Retrieve the reviewable changes to a file in a commit identified by its unique numeric id.""" return api.reviewablefilechange.fetch( parameters.critic, jsonapi.numeric_id(argument))
def single(critic, argument, parameters): """Retrieve one (or more) users of this system. USER_ID : integer Retrieve a user identified by the user's unique numeric id.""" return Users.setAsContext( parameters, api.user.fetch(critic, user_id=jsonapi.numeric_id(argument)))
def single(critic, argument, parameters): """Retrieve one (or more) branches in the Git repositories. BRANCH_ID : integer Retrieve a branch identified by its unique numeric id.""" return Branches.setAsContext( parameters, api.branch.fetch(critic, branch_id=jsonapi.numeric_id(argument)))
def deduce(parameters): profile = parameters.context.get("accesscontrolprofiles") profile_parameter = parameters.getQueryParameter("profile") if profile_parameter is not None: if profile is not None: raise jsonapi.UsageError( "Redundant query parameter: profile=%s" % profile_parameter) profile_id = jsonapi.numeric_id(profile_parameter) profile = api.accesscontrolprofile.fetch( parameters.critic, profile_id=profile_id) return profile
def single(critic, argument, parameters): """Retrieve one (or more) rebases in this system. REBASE_ID : integer Retrieve a rebase identified by its unique numeric id.""" return Rebases.setAsContext( parameters, api.log.rebase.fetch(critic, rebase_id=jsonapi.numeric_id(argument)))
def deduce(parameters): comment = parameters.context.get("comments") comment_parameter = parameters.getQueryParameter("comment") if comment_parameter is not None: if comment is not None: raise jsonapi.UsageError( "Redundant query parameter: comment=%s" % comment_parameter) comment = api.comment.fetch( parameters.critic, comment_id=jsonapi.numeric_id(comment_parameter)) return comment
def deduce(parameters): profile = parameters.context.get("accesscontrolprofiles") profile_parameter = parameters.getQueryParameter("profile") if profile_parameter is not None: if profile is not None: raise jsonapi.UsageError( "Redundant query parameter: profile=%s" % profile_parameter) profile_id = jsonapi.numeric_id(profile_parameter) profile = api.accesscontrolprofile.fetch(parameters.critic, profile_id=profile_id) return profile
def single(parameters, argument): """A primary email address by index. INDEX : integer Retrieve a primary email address identified by its index.""" emails = list(parameters.context["users"].primary_emails) try: return emails[jsonapi.numeric_id(argument) - 1] except IndexError: raise jsonapi.PathError("List index out of range")
def deduce(parameters): changeset = jsonapi.deduce("v1/changesets", parameters) if changeset is None: raise jsonapi.UsageError( "changeset needs to be specified, ex. &changeset=<id>") filechange = parameters.context.get(FileChanges.name) filechange_parameter = parameters.getQueryParameter("filechange") if filechange_parameter is not None: if filechange is not None: raise jsonapi.UsageError( "Redundant query parameter: filechange=%s" % filechange_parameter) filechange_id = jsonapi.numeric_id(filechange_parameter) filechange = api.filechange.fetch( parameters.critic, changeset, filechange_id) return filechange
def deduce(parameters): changeset = jsonapi.deduce("v1/changesets", parameters) if changeset is None: raise jsonapi.UsageError( "changeset needs to be specified, ex. &changeset=<id>") filechange = parameters.context.get(FileChanges.name) filechange_parameter = parameters.getQueryParameter("filechange") if filechange_parameter is not None: if filechange is not None: raise jsonapi.UsageError( "Redundant query parameter: filechange=%s" % filechange_parameter) filechange_id = jsonapi.numeric_id(filechange_parameter) filechange = api.filechange.fetch(parameters.critic, changeset, filechange_id) return filechange
def single(parameters, argument): """Retrieve one (or more) of a user's repository filters. FILTER_ID : integer Retrieve a filter identified by the filters's unique numeric id.""" user = parameters.context["users"] filter_id = jsonapi.numeric_id(argument) for repository_filters in user.repository_filters.values(): for repository_filter in repository_filters: if repository_filter.id == filter_id: return repository_filter raise KeyError("invalid filter id: %d" % filter_id)
def single(parameters, argument): """Retrieve one (or more) users of this system. USER_ID : integer or "me" Retrieve a user identified by the user's unique numeric id, or the identifier "me" to retrieve the current user.""" if argument == "me": user = parameters.critic.actual_user if user is None: raise api.user.UserError("'users/me' (not signed in)") else: user = api.user.fetch(parameters.critic, user_id=jsonapi.numeric_id(argument)) return Users.setAsContext(parameters, user)
def single(parameters, argument): """Retrieve one (or more) replies to comments. REPLY_ID : integer Retrieve a reply identified by its unique numeric id.""" reply = api.reply.fetch(parameters.critic, reply_id=jsonapi.numeric_id(argument)) comment = jsonapi.deduce("v1/comments", parameters) if comment and comment != reply.comment: raise jsonapi.PathError( "Reply does not belong to specified comment") return reply
def deduce(parameters): repository = jsonapi.deduce("v1/repositories", parameters) changeset = parameters.context.get(Changesets.name) changeset_parameter = parameters.getQueryParameter("changeset") if changeset_parameter is not None: if changeset is not None: raise jsonapi.UsageError( "Redundant query parameter: changeset=%s" % changeset_parameter) if repository is None: raise jsonapi.UsageError( "repository needs to be specified, ex. &repository=<id>") changeset_id = jsonapi.numeric_id(changeset_parameter) changeset = api.changeset.fetch( parameters.critic, repository, changeset_id=changeset_id) return changeset
def single(parameters, argument): """Retrieve one (or more) comments in reviews. COMMENT_ID : integer Retrieve a comment identified by its unique numeric id.""" comment = api.comment.fetch(parameters.critic, comment_id=jsonapi.numeric_id(argument)) review = jsonapi.deduce("v1/reviews", parameters) if review and review != comment.review: raise jsonapi.PathError( "Comment does not belong to specified review") return Comments.setAsContext(parameters, comment)
def single(parameters, argument): """Retrieve one (or more) batches in reviews. BATCH_ID : integer Retrieve a batch identified by its unique numeric id.""" batch = api.batch.fetch( parameters.critic, batch_id=jsonapi.numeric_id(argument)) review = jsonapi.deduce("v1/reviews", parameters) if review and review != batch.review: raise jsonapi.PathError( "Batch does not belong to specified review") return Batches.setAsContext(parameters, batch)
def single(parameters, argument): """Retrieve one (or more) comments in reviews. COMMENT_ID : integer Retrieve a comment identified by its unique numeric id.""" comment = api.comment.fetch( parameters.critic, comment_id=jsonapi.numeric_id(argument)) review = jsonapi.deduce("v1/reviews", parameters) if review and review != comment.review: raise jsonapi.PathError( "Comment does not belong to specified review") return Comments.setAsContext(parameters, comment)
def single(parameters, argument): """Retrieve one (or more) replies to comments. REPLY_ID : integer Retrieve a reply identified by its unique numeric id.""" reply = api.reply.fetch( parameters.critic, reply_id=jsonapi.numeric_id(argument)) comment = jsonapi.deduce("v1/comments", parameters) if comment and comment != reply.comment: raise jsonapi.PathError( "Reply does not belong to specified comment") return reply
def single(parameters, argument): """TODO: add documentation""" changeset = jsonapi.deduce("v1/changesets", parameters) if changeset is None: raise jsonapi.UsageError( "changeset needs to be specified, ex. &changeset=<id>") repository = jsonapi.deduce("v1/repositories", parameters) if repository is None: raise jsonapi.UsageError( "repository needs to be specified, " "ex. &repository=<id or name>") file = api.file.fetch(parameters.critic, jsonapi.numeric_id(argument)) filechange = api.filechange.fetch(parameters.critic, changeset, file) return api.filediff.fetch(parameters.critic, filechange)
def single(parameters, argument): """Retrieve one (or more) commits from a Git repository. COMMIT_ID : integer Retrieve a commit identified by its unique numeric id. repository : REPOSITORY : - Specify repository to access, identified by its unique numeric id or short-name. Required unless a repository is specified in the resource path.""" repository = jsonapi.deduce("v1/repositories", parameters) if repository is None: raise jsonapi.UsageError( "Commit reference must have repository specified.") return Commits.setAsContext(parameters, api.commit.fetch( repository, commit_id=jsonapi.numeric_id(argument)))
def single(parameters, argument): """Retrieve one (or more) filechanges (changed files). FILE_ID : integer Retrieve the changes to a file identified by its unique numeric id. changeset : CHANGESET : - Retrieve the changes from a changeset identified by its unique numeric id. reposititory : REPOSITORY : - The repository in which the files exist.""" changeset = jsonapi.deduce("v1/changesets", parameters) file = api.file.fetch(parameters.critic, jsonapi.numeric_id(argument)) return FileChanges.setAsContext( parameters, api.filechange.fetch(parameters.critic, changeset, file))
def single(parameters, argument): """Retrieve one (or more) filechanges (changed files). FILE_ID : integer Retrieve the changes to a file identified by its unique numeric id. changeset : CHANGESET : - Retrieve the changes from a changeset identified by its unique numeric id. reposititory : REPOSITORY : - The repository in which the files exist.""" changeset = jsonapi.deduce("v1/changesets", parameters) file = api.file.fetch(parameters.critic, jsonapi.numeric_id(argument)) return FileChanges.setAsContext( parameters, api.filechange.fetch( parameters.critic, changeset, file))
def single(parameters, argument): """Retrieve one (or more) commits from a Git repository. COMMIT_ID : integer Retrieve a commit identified by its unique numeric id. repository : REPOSITORY : - Specify repository to access, identified by its unique numeric id or short-name. Required unless a repository is specified in the resource path.""" repository = jsonapi.deduce("v1/repositories", parameters) if repository is None: raise jsonapi.UsageError( "Commit reference must have repository specified.") return Commits.setAsContext( parameters, api.commit.fetch(repository, commit_id=jsonapi.numeric_id(argument)))
def single(parameters, argument): """Retrieve one (or more) changesets. CHANGESET_ID : integer Retrieve a changeset identified by its unique numeric id. repository : REPOSITORY : - Specify repository to access, identified by its unique numeric id or short-name. Required unless a repository is specified in the resource path.""" repository = jsonapi.deduce("v1/repositories", parameters) if repository is None: raise jsonapi.UsageError( "repository needs to be specified, ex. &repository=<id>") return Changesets.setAsContext(parameters, api.changeset.fetch( parameters.critic, repository, jsonapi.numeric_id(argument)))
def fromParameter(value, parameters): return api.reply.fetch(parameters.critic, jsonapi.numeric_id(value))