Giter Club home page Giter Club logo

pygogs's Introduction

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.

pygogs's People

Contributors

goriy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.