@@ -134,7 +134,8 @@ def get_existing_links(self, collection_id):
134
134
135
135
seen_links .update (new_links )
136
136
yield from new_links
137
- cursor += 50
137
+ cursor = links [len (links )- 1 ].get ("id" )
138
+
138
139
except requests .RequestException as e :
139
140
logger .error (f"Error fetching links from cursor { cursor } : { str (e )} " )
140
141
if hasattr (e , "response" ) and e .response is not None :
@@ -186,7 +187,7 @@ def create_collection(self, name, description=""):
186
187
logger .error (f"Response content: { e .response .text } " )
187
188
return None
188
189
189
- def upload_link (self , collection_id , repo ):
190
+ def upload_link (self , collection_id , repo , tags ):
190
191
description = repo .description or ""
191
192
if len (description ) > 2048 :
192
193
# Truncate and add ellipsis so final length is 2048
@@ -196,9 +197,9 @@ def upload_link(self, collection_id, repo):
196
197
"title" : repo .full_name ,
197
198
"description" : description ,
198
199
"collection" : {"id" : collection_id },
199
- "tags" : [{"name" : "GitHub" }, {"name" : "GitHub Stars" }],
200
200
}
201
-
201
+ if tags :
202
+ link_data ["tags" ] = tags
202
203
logger .debug (
203
204
f"Sending link data to Linkwarden: { json .dumps (link_data , indent = 2 )} "
204
205
)
@@ -267,6 +268,12 @@ def load_env(self):
267
268
self .github_username = os .getenv ("GITHUB_USERNAME" )
268
269
self .linkwarden_url = os .getenv ("LINKWARDEN_URL" )
269
270
self .linkwarden_token = os .getenv ("LINKWARDEN_TOKEN" )
271
+ self .opt_tag = os .getenv ('OPT_TAG' , 'false' ).lower () == 'true'
272
+ self .opt_tag_github = os .getenv ('OPT_TAG_GITHUB' , 'false' ).lower () == 'true'
273
+ self .opt_tag_githubStars = os .getenv ('OPT_TAG_GITHUBSTARS' , 'false' ).lower () == 'true'
274
+ self .opt_tag_language = os .getenv ('OPT_TAG_LANGUAGE' , 'false' ).lower () == 'true'
275
+ self .opt_tag_username = os .getenv ('OPT_TAG_USERNAME' , 'false' ).lower () == 'true'
276
+ self .opt_tag_custom = os .getenv ('OPT_TAG_CUSTOM' ) if os .getenv ('OPT_TAG_CUSTOM' ,'false' ).lower () != 'false' and len (os .getenv ('OPT_TAG_CUSTOM' ))> 0 else False
270
277
271
278
if not all ([self .github_username , self .linkwarden_url , self .linkwarden_token ]):
272
279
logger .error (
@@ -456,11 +463,27 @@ def run(self):
456
463
457
464
max_retries = 3
458
465
retry_count = 0
466
+ tags = []
467
+ if self .opt_tag :
468
+ if self .opt_tag_github :
469
+ tags .append ({"name" : "GitHub" })
470
+ if self .opt_tag_githubStars :
471
+ tags .append ({"name" : "GitHub Stars" })
472
+ if self .opt_tag_language and repo .language :
473
+ tags .append ({"name" : repo .language })
474
+ if self .opt_tag_username :
475
+ tags .append ({"name" : self .github_username })
476
+ if self .opt_tag_custom :
477
+ for tag in self .opt_tag_custom .split (',' ):
478
+ if len (tag )> 0 :
479
+ tags .append ({"name" : tag .strip ()})
480
+
481
+
459
482
while retry_count < max_retries :
460
483
try :
461
484
logger .info (f"Processing repository: { repo .full_name } " )
462
485
link_id = self .linkwarden_manager .upload_link (
463
- collection_id , repo
486
+ collection_id , repo , tags
464
487
)
465
488
466
489
if link_id :
0 commit comments