A Gitea-API wrapper in Python
Go to file
Daniel Dietsch 00c2f97063 add API methods Repository.create_issue, Repository.is_collaborator, Organisation.is_member, disable debug logging of all API methods 2019-12-07 19:59:01 +01:00
gitea add API methods Repository.create_issue, Repository.is_collaborator, Organisation.is_member, disable debug logging of all API methods 2019-12-07 19:59:01 +01:00
.gitignore ignore tokenfiles 2019-07-02 16:55:23 +02:00
LICENSE Create LICENSE 2017-09-07 17:13:06 +00:00
README.md changed version in README.md 2019-08-15 10:30:57 +02:00
__init__.py cc 2019-07-10 16:40:31 +02:00
requirements.txt used "pip install pipreqs" and "pipreqs --force pygitea/" to generate correct requirements.txt 2019-12-05 17:22:31 +01:00
test_api.py fixed retrieving email; fixed throwing all secondary emails away, are now accessible in user.emails list; enabled adding issues via api 2019-12-04 13:37:17 +01:00

README.md

py-gitea

A very simple API client for Gitea version 1.9.0.

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

Note that not the full Swagger-API is accessible. The implemented part is focused on Organization/Team/Repository/User-creation, also putting users in Teams in Organizations and adding Repositories to Teams.

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:

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)

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.