Skip to content

goriy/pygogs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pygogs

Description

Simple Python helper class to work with Gogs API.

It doesn't provide full API support at the moment.

How does it work

pygogs uses requests python package as a backend for sending data to Gogs server.

Authorization on Gogs server

Authorization on Gogs server is done by means of Access Token.

So, first of all, you need to create Access Token on your Gogs server.

This token could be used as a string directly in your script or it could be read from separate file. Usage of separate file with token is more preferrable for several reasons:

  • your script could be in repository (even in public one) without revealing authorization info
  • separate file with token could have different (i.e. more restricted) file permissions
  • file with token could be ignored by version control systems (.gitignore, .hgignore, ...)

pygogs sends Access Token as a http(s) header.

Implemented

These API functions are implemented:

  • Administration Organizations - doc
    • create_new_organization
    • create_your_organization
    • create_team_of_organization
    • add_team_membership
    • remove_team_membership
    • add_or_update_team_repository
    • remove_team_repository
  • Administration Repositories - doc
    • create_user_repo
  • Administration Users - doc
    • create_user
    • edit_user
    • delete_user
    • create_user
    • create_a_public_key_for_user
  • Issues - doc
  • Issues Comments - doc
  • Issues Labels - doc
  • Issues Milestones - doc
  • Miscellaneous - doc
  • Organizations - doc
    • list_your_organizations
    • list_user_organizations
    • get_organization
    • edit_an_organization
  • Organizations Members - doc
    • add_or_update_organization_membership
  • Organizations Teams - doc
    • list_teams_of_an_organization
  • Repositories - doc
    • search_repos
    • list_your_repositories
    • list_user_repositories
    • list_organization_repositories
    • create_your_repo
    • create_organization_repo
    • migrate
    • get_repository
    • delete_repository
    • list_branches
    • get_branch
    • mirror_sync
  • Repositories Collaborators - doc
    • add_user_as_a_collaborator
  • Repositories Contents - doc
    • download_raw_content
    • download_archive
  • Repositories Deploy Keys - doc
  • Repositories Webhooks - doc
  • Users - doc
  • Users Emails - doc
  • Users Followers - doc
  • Users Public Keys - doc

Example 1

Simple script example:

    import pygogs

    # create helper class
    pg = pygogs.pygogs(server_url = 'https://example.com')

    # set verbosity level. 0 - quiet, 1 - print some information
    pg.verbosity(0)

    # setup access token from file
    pg.set_token_from_file ('example.token')
    # alternatively access token could be setup directly as string
    # pg.set_token ('1234567890abcdef...')

    # print some basic information about all user's repositories
    repolist = pg.list_your_repositories()
    if (repolist):
      for repo in repolist:
        print ('%s [id = %d]' % (repo['full_name'], repo['id']))

    # create private repository for current user
    result = pg.create_your_repo (name='project1', description='Super project for current user', private=True)

    # check http answer code
    if (pg.lastcode == 404):
      print ('not found')
    else:
      # print id from server response
      print (result['id'])

    # create public organization repository
    result = pg.create_organization_repo (organization='OCPCorp', name='project2', description='Mega Ultra Super project')

Example 2

File example_backup.py is a bit more useful example script. It does backup of all your repositories from server to current directory. It does something like incremental backup (by means of git) and could be run even from crontab.

About

Simple Python class to work with Gogs API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages