Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion clientapi_forgejo/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion clientapi_forgejo/models/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
73 changes: 73 additions & 0 deletions issues.py
Original file line number Diff line number Diff line change
@@ -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