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..53f05a8 --- /dev/null +++ b/issues.py @@ -0,0 +1,73 @@ +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 + +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) + 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