A Gitea-API wrapper in Python
Go to file
Meik Specht 81dfd0d463 Added dict parameter to repo.get_commits() to define what shall be pulled.
In a large repository, get_commits() will run into too many recursions.
I added the possibility to define sha, page, limit (all from the API documentation)
and the additional non-API parameter pages, which defines how many pages of commits
shall be requested. The default for pages is -1, which will request pages indefinitely.

I also added the commit message property the the Commit class/object.
I also added the commit_date property that is read from the commiter structure
below the commit structure because that date represents the actual commit time.
In our case, the Commit.created property contains bogus values because we're importing from SVN.
2021-12-11 03:27:49 +01:00
gitea Added dict parameter to repo.get_commits() to define what shall be pulled. 2021-12-11 03:27:49 +01:00
tests fixing some of the hash functions 2021-11-12 14:21:54 +01:00
.gitignore added local virtual environment to gitignore 2021-05-06 15:03:43 +02:00
LICENSE
README.md increased version 2021-05-06 16:37:44 +02:00
__init__.py
requirements.txt removed httpcache for python 3.10 compatibility 2021-12-09 17:34:09 +01:00
setup.py fixed trying to parse more gitea payloadcommit objects where there are non (e.g. listing commits) 2021-11-12 18:33:21 +01:00

README.md

py-gitea

A very simple API client for Gitea 1.14.x

This has been somewhat tested (and used), so most things should work as expected.

Note that not the full Swagger-API is accessible. The whole implementation is focused on making access and working with Organizations, Teams, Repositories and Users as pain free as possible.

Originally forked from https://github.com/m301/py-gitea.

Usage

First get a gitea object wrapping access and authentication (via an api token) for your gitea instance:

from gitea import *

gitea = Gitea(URL, TOKEN)

Operations like requesting the Gitea version or authentication user can be requested directly from the gitea object:

print("Gitea Version: " + gitea.get_version())
print("API-Token belongs to user: " + gitea.get_user().username)

Adding entities like Users, Organizations, ... also is done via the gitea object.

user = gitea.create_user("Test Testson", "test@test.test", "password")

All operations on entities in gitea are then accomplished via the according wrapper objects for those entities. Each of those objects has a .request method that creates an entity according to your gitea instance.

other_user = User.request(gitea, "OtherUserName")
print(other_user.username)

Note that the fields of the User, Organization,... classes are dynamically created at runtime, and thus not visible during divelopment. Refer to the Gitea-API documentation for the fields names.

Fields that can not be altered via gitea-api, are read only. After altering a field, the .commit method of the according object must be called to synchronize the changed fields with your gitea instance.

org = Organization.request(gitea, test_org)
org.description = "some new description"
org.location = "some new location"
org.commit()

An entity in gitea can be deleted by calling delete.

org.delete()

All entity objects do have methods to execute some of the requests possible though the gitea-api:

org = Organization.request(gitea, ORGNAME)
teams = org.get_teams()
for team in teams:
	repos = team.get_repos()
	for repo in repos:
		print(repo.name)

Installation

Use pip install py-gitea to install.

Tests

Tests can be run with:

python3 -m pytest test_api.py

Make sure to have a gitea-instance running on http://localhost:3000, and an admin-user token at .token. The admin user must be named test, with email secondarytest@test.org.