Example 1: Retrieving a repository

Below is an example illustrating how to retrieve information about a repository:

import gogs_client

token = gogs_client.Token("my_token")
username = "username"  # username of owner of repo
repository_name = "repo_name"

api = GogsApi("https://try.gogs.io/")

if not api.repo_exists(token, username, repository_name):
    print("Repository does not exist")
    repo = api.lookup_repo(token, username, repository_name)
    if repo.fork:
        print("Repository is a fork")
        print("Repository is not a fork")

Example 2: Updating a user

Below is an example demonstrating how to update a user (requires admin privileges):

import gogs_client

login_name = "my_login"
user_email = "user_to_update@example.com"

update = gogs_client.GogsUserUpdate.Builder(login_name, user_email)\
            .set_full_name("New Full Name")\
            .set_password("New Password")\
            .set_admin(False)\  # set the updated user as non-admin

api = gogs_client.GogsApi("https://try.gogs.io/")
    gogs_client.Token("my_token"),  # must be admin

Example 3: Creating a token

Below is an example illustrating how to create a token:

import gogs_client

api = gogs_client.GogsApi("https://try.gogs.io/")

auth = gogs_client.UsernamePassword("username", "password")
token = api.create_token(auth, "my_token")

print("token: {}, name: {}".format(token.token, token.name))