diff options
Diffstat (limited to 'rss_to_gitea')
-rw-r--r-- | rss_to_gitea/gitea.py | 38 | ||||
-rw-r--r-- | rss_to_gitea/main.py | 8 |
2 files changed, 43 insertions, 3 deletions
diff --git a/rss_to_gitea/gitea.py b/rss_to_gitea/gitea.py index e1aa62a..dbfba8e 100644 --- a/rss_to_gitea/gitea.py +++ b/rss_to_gitea/gitea.py @@ -42,6 +42,16 @@ class GiteaAPI: return result.json() + def _api_patch(self, _endpoint, _data): + headers={ + 'Authorization':f'token {self.token}', + 'Content-Type': 'application/json', + 'accept': 'application/json' + } + result = requests.patch(f'{self.address}/{_endpoint}',headers=headers, json=_data) + + return result.json() + def createIssue(self, _owner, _repo, _title, _content, _assign, _labels): data={ @@ -55,7 +65,15 @@ class GiteaAPI: return result - def searchIssue(self, _owner, _repo, _title, _labels, _state='all'): + def changeIssueState(self, _owner, _repo, _index, _state): + data= { + 'state':_state, + } + + result = self._api_patch(f'repos/{_owner}/{_repo}/issues/{_index}', data ) + + + def getFirstExactIssue(self, _owner, _repo, _title, _labels, _state='all'): data= { 'state':_state, 'labels':_labels, @@ -71,6 +89,24 @@ class GiteaAPI: return None + def getAllIssuesStartingWith(self, _owner, _repo, _title, _labels, _state='all'): + ret = [] + + data= { + 'state':_state, + 'labels':_labels, + 'created_by':self.username, + 'q':_title + } + + result = self._api_get(f'repos/{_owner}/{_repo}/issues', data ) + + for issue in result: + if issue['title'].startswith(_title): + ret.append(issue) + + return ret + def getLabelId(self, _owner, _repo, _label): data= {} diff --git a/rss_to_gitea/main.py b/rss_to_gitea/main.py index 8d31197..7de5106 100644 --- a/rss_to_gitea/main.py +++ b/rss_to_gitea/main.py @@ -37,11 +37,15 @@ def main(): issue_title = f'{feed["name"]}: {latest["title"]}' print("Title=", issue_title) - ticket = api.searchIssue(config.owner, config.repo, issue_title, [config.label]) + ticket = api.getFirstExactIssue(config.owner, config.repo, issue_title, [config.label]) if ticket is not None: print(f'{issue_title} already exists. Skipping') continue - print(feed) + # should we maybe just rename here? + prev_versions = api.getAllIssuesStartingWith(config.owner, config.repo, f'{feed["name"]}: ', [config.label], _state='open') + for prev in prev_versions: + print(f'{prev["title"]} (#{prev["number"]}) already exists. closing.') + api.changeIssueState(config.owner, config.repo, prev['number'], 'closed') result = api.createIssue(config.owner, config.repo, issue_title, latest['link'], feed['assign'], [label_id]) |