From ad3ec123d4543c8cc4106d9d11f6e8e806b90de3 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Tue, 8 Feb 2022 17:20:47 +0100 Subject: working --- rss_to_gitea/gitea.py | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'rss_to_gitea/gitea.py') diff --git a/rss_to_gitea/gitea.py b/rss_to_gitea/gitea.py index 39ea763..fcc985c 100644 --- a/rss_to_gitea/gitea.py +++ b/rss_to_gitea/gitea.py @@ -32,11 +32,30 @@ class GiteaAPI: return result.json() + def _api_post(self, _endpoint, _data): + headers={ + 'Authorization':f'token {self.token}', + 'Content-Type': 'application/json', + 'accept': 'application/json' + } + result = requests.post(f'{self.address}/{_endpoint}',headers=headers, json=_data) + + return result.json() + + + def createIssue(self, _owner, _repo, _title, _content, _assign, _labels): + data={ + 'assignee':_assign, +# 'body':_content, + 'labels':_labels, + 'title':_title + } + + result = self._api_post(f'repos/{_owner}/{_repo}/issues', data ) - def createIssue(self, _owner, _repo, _title, _content): - pass + return result - def searchIssue(self, _owner, _repo, _title, _labels, _state='open'): + def searchIssue(self, _owner, _repo, _title, _labels, _state='all'): data= { 'state':_state, 'labels':_labels, @@ -47,8 +66,23 @@ class GiteaAPI: result = self._api_get(f'repos/{_owner}/{_repo}/issues', data ) for issue in result: - print(issue['title']) + if issue['title'] == _title: + return issue + + return None + + def getLabelId(self, _owner, _repo, _label): + data= {} + + result = self._api_get(f'repos/{_owner}/{_repo}/labels', data ) + + label_filtered = filter(lambda a: a['name']==_label, result) + label = list(label_filtered) + + if len(label) != 1: + print('No or more than one label found') + return None + + return label[0]['id'] - def updateIssue(self, _owner, _repo, _issueid): - pass -- cgit v1.2.3