check duplicate issue before report

This commit is contained in:
shenyutao 2024-04-19 09:44:35 +08:00
parent 0e9829e82c
commit 4f38b4aeeb
2 changed files with 24 additions and 9 deletions

View File

@ -1,6 +1,7 @@
import json
import time
import requests
from datetime import datetime, timedelta, UTC
def github_api_headers(**kwargs):
@ -18,6 +19,23 @@ def report_issue(github_repository: str, title: str, body: str, **kwargs):
print('report issue repository not found')
return
try:
if issue_check_id := kwargs.get('id'):
body = f'{body}\n----{issue_check_id}'
try:
response = requests.get(f'https://api.github.com/repos/{github_repository}/issues',
headers=github_api_headers(github_token=kwargs.get('github_token')),
params={
'state': 'open',
'since': (datetime.now(UTC) - timedelta(days=10)).strftime('%Y-%m-%dT%H:%M:%S') + 'Z',
'per_page': 100,
})
exist_issues = response.json()
for issue in exist_issues:
if issue.get('body').endswith(f'----{issue_check_id}'):
return
except Exception as e:
print(f'fetch from exist issues failed: {e}')
response = requests.post(f'https://api.github.com/repos/{github_repository}/issues',
headers=github_api_headers(github_token=kwargs.get('github_token')),
json={

15
main.py
View File

@ -126,12 +126,6 @@ def parse(plugin: AddonInfo, **kwargs):
force_download=True)
details = addon_details(xpi_filepath)
except Exception as e:
report_issue(kwargs.get('github_repository'),
title=f'Parse xpi detail failed',
body=f'url:{xpi_url}\n'
f'repo:{plugin.repo}\n'
f'reason:{e}',
github_token=kwargs.get('github_token'))
print(f'fetch addon detail of {plugin.repo} with {xpi_url} failed: {e}')
if details:
@ -156,12 +150,14 @@ def parse(plugin: AddonInfo, **kwargs):
report_issue(kwargs.get('github_repository'),
title=f'Parse {plugin.repo} of zotero version failed',
body=f'xpi:{plugin.repo}@{release.tagName} on {release.targetZoteroVersion}\n',
github_token=kwargs.get('github_token'))
github_token=kwargs.get('github_token'),
id=f'Parse min/max version failed: {plugin.repo}+{release.tagName}@{release.targetZoteroVersion}')
else:
report_issue(kwargs.get('github_repository'),
title=f'Parse {plugin.repo} addon details failed',
body=f'xpi:{plugin.repo}@{release.tagName} on {release.targetZoteroVersion}\n',
github_token=kwargs.get('github_token'))
github_token=kwargs.get('github_token'),
id=f'Parse details failed: {plugin.repo}+{release.tagName}@{release.targetZoteroVersion}')
except Exception as e:
@ -175,7 +171,8 @@ def parse(plugin: AddonInfo, **kwargs):
f'min zotero Version:{invalid_release.minZoteroVersion}\n'
f'max Zotero version:{invalid_release.maxZoteroVersion}'
f'expect Zotero version:{invalid_release.zotero_check_version}\n',
github_token=kwargs.get('github_token'))
github_token=kwargs.get('github_token'),
id=f'Target zotero version not match: {plugin.repo}+{invalid_release.tagName}@{release.targetZoteroVersion}')
plugin.releases.remove(invalid_release)
return plugin