From 4f38b4aeeb08d00db1e5accf1a0798661ca75935 Mon Sep 17 00:00:00 2001 From: shenyutao Date: Fri, 19 Apr 2024 09:44:35 +0800 Subject: [PATCH] check duplicate issue before report --- github_operations.py | 18 ++++++++++++++++++ main.py | 15 ++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/github_operations.py b/github_operations.py index 4f04036..bfeab27 100644 --- a/github_operations.py +++ b/github_operations.py @@ -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={ diff --git a/main.py b/main.py index fccf3fa..7bda776 100644 --- a/main.py +++ b/main.py @@ -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