py-gitea/README.md

76 wiersze
2.3 KiB
Markdown
Czysty Zwykły widok Historia

2017-09-07 17:12:30 +00:00
# py-gitea
2019-06-27 10:04:25 +00:00
A very simple API client for Gitea (min version `1.8.2`)
2017-09-07 17:12:30 +00:00
2019-04-19 08:41:56 +00:00
This has been somewhat tested (and used!), so most things should work as expected.
2017-09-07 17:12:30 +00:00
2019-04-19 08:41:56 +00:00
Note that not the full Swagger-API is accessible. The implemented part is
focused on Organization/Team/Repository/User-creation, also putting users in
2019-06-27 10:04:25 +00:00
Teams in Organizations and adding Repositories to Teams.
2019-07-02 14:43:10 +00:00
Originally forked from https://github.com/m301/py-gitea.
2019-06-27 10:04:25 +00:00
## Usage
First get a `gitea` object wrapping access and authentication (via an api token) for your gitea instance:
2019-06-27 11:43:57 +00:00
```python
2019-06-27 10:04:25 +00:00
gitea = Gitea(URL, TOKEN)
```
Operations like requesting the Gitea version or authentication user can be requested directly from the `gitea` object:
2019-06-27 11:43:57 +00:00
```python
2019-06-27 10:04:25 +00:00
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.
2019-06-27 11:43:57 +00:00
```python
2019-06-27 10:04:25 +00:00
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.
2019-06-27 11:43:57 +00:00
```python
2019-06-27 10:04:25 +00:00
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.
2019-06-27 11:43:57 +00:00
```python
2019-06-27 10:04:25 +00:00
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.
2019-06-27 11:43:57 +00:00
```python
2019-06-27 10:04:25 +00:00
org.delete()
```
All entity objects do have methods to execute some of the requests possible though the gitea-api:
2019-06-27 11:43:57 +00:00
```python
2019-06-27 10:04:25 +00:00
org = Organization.request(gitea, ORGNAME)
teams = org.get_teams()
for team in teams:
repos = team.get_repos()
2019-06-27 11:44:35 +00:00
for repo in repos:
print(repo.name)
2019-06-27 10:04:25 +00:00
```
2019-04-19 08:41:56 +00:00
2019-06-27 10:04:25 +00:00
## Tests
2019-04-18 13:01:43 +00:00
Can be run like this:
2017-09-07 17:12:30 +00:00
2019-07-02 14:59:24 +00:00
```python3 -m pytest test_api.py```
2017-09-07 17:12:30 +00:00
2019-04-18 13:01:43 +00:00
Make sure to have a gitea-instance running on `http://localhost:3000`, and an admin-user token at `.token`.