kopia lustrzana https://github.com/Langenfeld/py-gitea
add delete_time, fix some bugs
rodzic
1a3f93b33d
commit
60486a0ce9
121
gitea/gitea.py
121
gitea/gitea.py
|
@ -2,7 +2,7 @@ import json
|
||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List, Tuple, Dict, Sequence
|
from typing import List, Tuple, Dict, Sequence, Optional
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from httpcache import CachingHTTPAdapter
|
from httpcache import CachingHTTPAdapter
|
||||||
|
@ -261,7 +261,7 @@ class Repository(GiteaApiObject):
|
||||||
|
|
||||||
def get_issues(self) -> List["Issue"]:
|
def get_issues(self) -> List["Issue"]:
|
||||||
"""Get all Issues of this Repository (open and closed)"""
|
"""Get all Issues of this Repository (open and closed)"""
|
||||||
return self.get_issues_state(Issue.open) + self.get_issues_state(Issue.closed)
|
return self.get_issues_state(Issue.OPENED) + self.get_issues_state(Issue.CLOSED)
|
||||||
|
|
||||||
def get_commits(self) -> List["Commit"]:
|
def get_commits(self) -> List["Commit"]:
|
||||||
"""Get all the Commits of this Repository."""
|
"""Get all the Commits of this Repository."""
|
||||||
|
@ -439,6 +439,7 @@ class Issue(GiteaApiObject):
|
||||||
GET_TIME = """/repos/%s/%s/issues/%s/times""" # <owner, repo, index>
|
GET_TIME = """/repos/%s/%s/issues/%s/times""" # <owner, repo, index>
|
||||||
GET_COMMENTS = """/repos/%s/%s/issues/comments"""
|
GET_COMMENTS = """/repos/%s/%s/issues/comments"""
|
||||||
CREATE_ISSUE = """/repos/{owner}/{repo}/issues"""
|
CREATE_ISSUE = """/repos/{owner}/{repo}/issues"""
|
||||||
|
DELETE_TIME = """/repos/{owner}/{repo}/issues/{index}/times/{id}"""
|
||||||
|
|
||||||
OPENED = "closed"
|
OPENED = "closed"
|
||||||
CLOSED = "open"
|
CLOSED = "open"
|
||||||
|
@ -478,7 +479,7 @@ class Issue(GiteaApiObject):
|
||||||
result = gitea.requests_post(Issue.CREATE_ISSUE.format(**args), data=data)
|
result = gitea.requests_post(Issue.CREATE_ISSUE.format(**args), data=data)
|
||||||
return Issue.parse_response(gitea, result)
|
return Issue.parse_response(gitea, result)
|
||||||
|
|
||||||
def get_time(self, user: User) -> int:
|
def get_time_sum(self, user: User) -> int:
|
||||||
results = self.gitea.requests_get(
|
results = self.gitea.requests_get(
|
||||||
Issue.GET_TIME % (self.owner.username, self.repo, self.number)
|
Issue.GET_TIME % (self.owner.username, self.repo, self.number)
|
||||||
)
|
)
|
||||||
|
@ -488,6 +489,16 @@ class Issue(GiteaApiObject):
|
||||||
if result and result["user_id"] == user.id
|
if result and result["user_id"] == user.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_times(self) -> Optional[Dict]:
|
||||||
|
return self.gitea.requests_get(
|
||||||
|
Issue.GET_TIME % (self.owner.username, self.repo, self.number)
|
||||||
|
)
|
||||||
|
|
||||||
|
def delete_time(self, time_id: str):
|
||||||
|
self.gitea.requests_delete(
|
||||||
|
Issue.DELETE_TIME % (self.owner.username, self.repo, self.number, time_id)
|
||||||
|
)
|
||||||
|
|
||||||
def get_comments(self) -> List[GiteaApiObject]:
|
def get_comments(self) -> List[GiteaApiObject]:
|
||||||
results = self.gitea.requests_get(
|
results = self.gitea.requests_get(
|
||||||
Issue.GET_COMMENTS % (self.owner.username, self.repo)
|
Issue.GET_COMMENTS % (self.owner.username, self.repo)
|
||||||
|
@ -692,8 +703,8 @@ class Gitea:
|
||||||
)
|
)
|
||||||
if request.status_code not in [200, 201]:
|
if request.status_code not in [200, 201]:
|
||||||
if (
|
if (
|
||||||
"already exists" in request.text
|
"already exists" in request.text
|
||||||
or "e-mail already in use" in request.text
|
or "e-mail already in use" in request.text
|
||||||
):
|
):
|
||||||
self.logger.warning(request.text)
|
self.logger.warning(request.text)
|
||||||
raise AlreadyExistsException()
|
raise AlreadyExistsException()
|
||||||
|
@ -777,7 +788,7 @@ class Gitea:
|
||||||
return self.requests_get(path)
|
return self.requests_get(path)
|
||||||
|
|
||||||
def post_org_repos(
|
def post_org_repos(
|
||||||
self, name, description, private, auto_init, gitignores, license, readme, org
|
self, name, description, private, auto_init, gitignores, license, readme, org
|
||||||
):
|
):
|
||||||
path = "/org/" + org + "/repos"
|
path = "/org/" + org + "/repos"
|
||||||
return self.requests_post(
|
return self.requests_post(
|
||||||
|
@ -809,15 +820,15 @@ class Gitea:
|
||||||
return self.requests_get(path)
|
return self.requests_get(path)
|
||||||
|
|
||||||
def post_repos_migrate(
|
def post_repos_migrate(
|
||||||
self,
|
self,
|
||||||
clone_addr,
|
clone_addr,
|
||||||
auth_username,
|
auth_username,
|
||||||
auth_password,
|
auth_password,
|
||||||
uid,
|
uid,
|
||||||
repo_name,
|
repo_name,
|
||||||
mirror,
|
mirror,
|
||||||
private,
|
private,
|
||||||
description,
|
description,
|
||||||
):
|
):
|
||||||
path = "/repos/migrate"
|
path = "/repos/migrate"
|
||||||
return self.requests_post(
|
return self.requests_post(
|
||||||
|
@ -835,7 +846,7 @@ class Gitea:
|
||||||
)
|
)
|
||||||
|
|
||||||
def post_user_repos(
|
def post_user_repos(
|
||||||
self, name, description, private, auto_init, gitignores, license, readme
|
self, name, description, private, auto_init, gitignores, license, readme
|
||||||
):
|
):
|
||||||
path = "/user/repos"
|
path = "/user/repos"
|
||||||
return self.requests_post(
|
return self.requests_post(
|
||||||
|
@ -880,14 +891,14 @@ class Gitea:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def create_user(
|
def create_user(
|
||||||
self,
|
self,
|
||||||
user_name: str,
|
user_name: str,
|
||||||
email: str,
|
email: str,
|
||||||
password: str,
|
password: str,
|
||||||
login_name: str = None,
|
login_name: str = None,
|
||||||
change_pw=True,
|
change_pw=True,
|
||||||
send_notify=True,
|
send_notify=True,
|
||||||
source_id=0,
|
source_id=0,
|
||||||
):
|
):
|
||||||
""" Create User.
|
""" Create User.
|
||||||
Throws:
|
Throws:
|
||||||
|
@ -923,16 +934,16 @@ class Gitea:
|
||||||
return user
|
return user
|
||||||
|
|
||||||
def create_repo(
|
def create_repo(
|
||||||
self,
|
self,
|
||||||
repoOwner,
|
repoOwner,
|
||||||
repoName: str,
|
repoName: str,
|
||||||
description: str = "",
|
description: str = "",
|
||||||
private: bool = False,
|
private: bool = False,
|
||||||
autoInit=True,
|
autoInit=True,
|
||||||
gitignores: str = None,
|
gitignores: str = None,
|
||||||
license: str = None,
|
license: str = None,
|
||||||
readme: str = "Default",
|
readme: str = "Default",
|
||||||
issue_labels: str = None,
|
issue_labels: str = None,
|
||||||
):
|
):
|
||||||
""" Create a Repository.
|
""" Create a Repository.
|
||||||
Throws:
|
Throws:
|
||||||
|
@ -964,13 +975,13 @@ class Gitea:
|
||||||
return Repository.parse_response(self, result)
|
return Repository.parse_response(self, result)
|
||||||
|
|
||||||
def create_org(
|
def create_org(
|
||||||
self,
|
self,
|
||||||
owner: User,
|
owner: User,
|
||||||
orgName: str,
|
orgName: str,
|
||||||
description: str,
|
description: str,
|
||||||
location="",
|
location="",
|
||||||
website="",
|
website="",
|
||||||
full_name="",
|
full_name="",
|
||||||
):
|
):
|
||||||
assert isinstance(owner, User)
|
assert isinstance(owner, User)
|
||||||
result = self.requests_post(
|
result = self.requests_post(
|
||||||
|
@ -998,20 +1009,20 @@ class Gitea:
|
||||||
return Organization.parse_response(self, result)
|
return Organization.parse_response(self, result)
|
||||||
|
|
||||||
def create_team(
|
def create_team(
|
||||||
self,
|
self,
|
||||||
org: Organization,
|
org: Organization,
|
||||||
name: str,
|
name: str,
|
||||||
description: str = "",
|
description: str = "",
|
||||||
permission: str = "read",
|
permission: str = "read",
|
||||||
units=(
|
units=(
|
||||||
"repo.code",
|
"repo.code",
|
||||||
"repo.issues",
|
"repo.issues",
|
||||||
"repo.ext_issues",
|
"repo.ext_issues",
|
||||||
"repo.wiki",
|
"repo.wiki",
|
||||||
"repo.pulls",
|
"repo.pulls",
|
||||||
"repo.releases",
|
"repo.releases",
|
||||||
"repo.ext_wiki",
|
"repo.ext_wiki",
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
""" Creates a Team.
|
""" Creates a Team.
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue