From 0b6c790bab235d37e05223787d043693886ee5ef Mon Sep 17 00:00:00 2001 From: mike dupont Date: Thu, 13 Feb 2025 15:33:16 -0500 Subject: [PATCH 1/4] work in progress --- clientapi_forgejo/models/comment.py | 10 ++++- clientapi_forgejo/models/issue.py | 10 ++++- issues.py | 68 +++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 issues.py diff --git a/clientapi_forgejo/models/comment.py b/clientapi_forgejo/models/comment.py index ca1d317..ae4fc8d 100644 --- a/clientapi_forgejo/models/comment.py +++ b/clientapi_forgejo/models/comment.py @@ -16,6 +16,14 @@ import pprint import re # noqa: F401 import json +from datetime import date, datetime + +def json_serial(obj): + """JSON serializer for objects not serializable by default json code""" + + if isinstance(obj, (datetime, date)): + return obj.isoformat() + raise TypeError ("Type %s not serializable" % type(obj)) from datetime import datetime from typing import List, Optional @@ -51,7 +59,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - return json.dumps(self.to_dict()) + return json.dumps(self.to_dict(),default=json_serial) @classmethod def from_json(cls, json_str: str) -> Comment: diff --git a/clientapi_forgejo/models/issue.py b/clientapi_forgejo/models/issue.py index 6340198..eb6a8dd 100644 --- a/clientapi_forgejo/models/issue.py +++ b/clientapi_forgejo/models/issue.py @@ -16,6 +16,14 @@ import pprint import re # noqa: F401 import json +from datetime import date, datetime + +def json_serial(obj): + """JSON serializer for objects not serializable by default json code""" + + if isinstance(obj, (datetime, date)): + return obj.isoformat() + raise TypeError ("Type %s not serializable" % type(obj)) from datetime import datetime from typing import List, Optional @@ -69,7 +77,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - return json.dumps(self.to_dict()) + return json.dumps(self.to_dict(),default=json_serial) @classmethod def from_json(cls, json_str: str) -> Issue: diff --git a/issues.py b/issues.py new file mode 100644 index 0000000..c19c38f --- /dev/null +++ b/issues.py @@ -0,0 +1,68 @@ +import time +#import pdb +import json +import os +import clientapi_forgejo +from clientapi_forgejo.models.timeline_comment import TimelineComment +from clientapi_forgejo.rest import ApiException +from pprint import pprint + +# Defining the host is optional and defaults to /api/v1 +# See configuration.py for a list of all supported configuration parameters. +configuration = clientapi_forgejo.Configuration( + host = "https://codeberg.org/api/v1" +) + +# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed +# configuration.api_key_prefix['TOTPHeader'] = 'Bearer' + +# Configure API key authorization: AuthorizationHeaderToken +configuration.api_key['AuthorizationHeaderToken'] = os.environ["API_KEY"] + + +# Configure API key authorization: AccessToken +# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed +# configuration.api_key_prefix['SudoParam'] = 'Bearer' + +# Configure API key authorization: Token +configuration.api_key['Token'] = os.environ["API_KEY"] + +# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed +# configuration.api_key_prefix['Token'] = 'Bearer' +from datetime import date, datetime + +def json_serial(obj): + """JSON serializer for objects not serializable by default json code""" + + if isinstance(obj, (datetime, date)): + return obj.isoformat() + raise TypeError ("Type %s not serializable" % type(obj)) + +# Enter a context with an instance of the API client +with clientapi_forgejo.ApiClient(configuration) as api_client: + # Create an instance of the API class + api_instance = clientapi_forgejo.IssueApi(api_client) + owner = 'introspector' # str | owner of the repo + repo = 'SOLFUNMEME' # str | name of the repo + limit = 100 # int | page size of results (optional) + page = 0 + results = 1 + tickets = [] + while results>0: + api_response = api_instance.issue_list_issues(owner, repo, page=page, limit=limit) + if api_response: + for issue in api_response: + comments = [] + parent = issue.to_json() + clean_data = json.loads(parent) + detail_api_response = api_instance.issue_get_comments(owner, repo, index=issue.number, + #page=detail_page, + #limit=limit + ) + for c in detail_api_response: + data = json.loads(c.to_json()) + comments.append(data) + clean_data['details'] = comments + print(json.dumps(clean_data,default=json_serial,sort_keys=True)) + page = page + 1 + From 884d45995122b058f430b7113507d368a78e476a Mon Sep 17 00:00:00 2001 From: mike dupont Date: Thu, 13 Feb 2025 15:53:05 -0500 Subject: [PATCH 2/4] bugfix --- issues.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/issues.py b/issues.py index c19c38f..b15ce80 100644 --- a/issues.py +++ b/issues.py @@ -50,11 +50,13 @@ def json_serial(obj): tickets = [] while results>0: api_response = api_instance.issue_list_issues(owner, repo, page=page, limit=limit) + results = len(api_response) if api_response: for issue in api_response: comments = [] parent = issue.to_json() clean_data = json.loads(parent) + #print("debug",issue.number) detail_api_response = api_instance.issue_get_comments(owner, repo, index=issue.number, #page=detail_page, #limit=limit @@ -64,5 +66,5 @@ def json_serial(obj): comments.append(data) clean_data['details'] = comments print(json.dumps(clean_data,default=json_serial,sort_keys=True)) - page = page + 1 + page = page + 1 From 89000bf534f8aed61b3f47efe59c8fdc9037d8c7 Mon Sep 17 00:00:00 2001 From: mike dupont Date: Thu, 13 Feb 2025 15:58:29 -0500 Subject: [PATCH 3/4] update --- issues.py | 58 +++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/issues.py b/issues.py index b15ce80..b04bb58 100644 --- a/issues.py +++ b/issues.py @@ -39,32 +39,32 @@ def json_serial(obj): raise TypeError ("Type %s not serializable" % type(obj)) # Enter a context with an instance of the API client -with clientapi_forgejo.ApiClient(configuration) as api_client: - # Create an instance of the API class - api_instance = clientapi_forgejo.IssueApi(api_client) - owner = 'introspector' # str | owner of the repo - repo = 'SOLFUNMEME' # str | name of the repo - limit = 100 # int | page size of results (optional) - page = 0 - results = 1 - tickets = [] - while results>0: - api_response = api_instance.issue_list_issues(owner, repo, page=page, limit=limit) - results = len(api_response) - if api_response: - for issue in api_response: - comments = [] - parent = issue.to_json() - clean_data = json.loads(parent) - #print("debug",issue.number) - detail_api_response = api_instance.issue_get_comments(owner, repo, index=issue.number, - #page=detail_page, - #limit=limit - ) - for c in detail_api_response: - data = json.loads(c.to_json()) - comments.append(data) - clean_data['details'] = comments - print(json.dumps(clean_data,default=json_serial,sort_keys=True)) - page = page + 1 - +with open("issues.json",'w') as wo: + with clientapi_forgejo.ApiClient(configuration) as api_client: + api_instance = clientapi_forgejo.IssueApi(api_client) + owner = 'introspector' # str | owner of the repo + repo = 'SOLFUNMEME' # str | name of the repo + limit = 100 # int | page size of results (optional) + page = 0 + results = 1 + tickets = [] + while results>0: + api_response = api_instance.issue_list_issues(owner, repo, page=page, limit=limit) + results = len(api_response) + if results > 0: + print("results",results) + for issue in api_response: + comments = [] + parent = issue.to_json() + clean_data = json.loads(parent) + print("debug",issue.number) + detail_api_response = api_instance.issue_get_comments(owner, repo, index=issue.number, + #page=detail_page, + #limit=limit + ) + for c in detail_api_response: + data = json.loads(c.to_json()) + comments.append(data) + clean_data['details'] = comments + wo.write(json.dumps(clean_data,default=json_serial,sort_keys=True)) + page = page + 1 From da7e79cdee5ec524081c85cb7d75c773aa2c3898 Mon Sep 17 00:00:00 2001 From: mike dupont Date: Thu, 13 Feb 2025 16:07:03 -0500 Subject: [PATCH 4/4] update --- issues.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/issues.py b/issues.py index b04bb58..53f05a8 100644 --- a/issues.py +++ b/issues.py @@ -39,11 +39,14 @@ def json_serial(obj): raise TypeError ("Type %s not serializable" % type(obj)) # Enter a context with an instance of the API client -with open("issues.json",'w') as wo: + +owner = 'introspector' # str | owner of the repo +repos = ['meta-meme','SOLFUNMEME'] # str | name of the repo + +for repo in repos: + with open(repo + "issues.json",'w') as wo: with clientapi_forgejo.ApiClient(configuration) as api_client: api_instance = clientapi_forgejo.IssueApi(api_client) - owner = 'introspector' # str | owner of the repo - repo = 'SOLFUNMEME' # str | name of the repo limit = 100 # int | page size of results (optional) page = 0 results = 1