Skip to content

Commit

Permalink
Merge pull request #100 from MikroElektronika/improvement/indexed-url…
Browse files Browse the repository at this point in the history
…-check

Fixed issue with non-existent gh asset links
  • Loading branch information
StrahinjaJacimovic authored Oct 15, 2024
2 parents e441d80 + 6480883 commit eb71c52
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checkIndexes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ on:
- main # This will trigger on every push (merge) to the 'main' branch

schedule:
- cron: "*/30 * * * *" # This will run every 30 minutes
- cron: "0/30 7-16 * * 1-5" # Every 30 minutes, between 07:00 AM and 04:59 PM, Monday through Friday

jobs:
manual_run:
Expand Down
24 changes: 19 additions & 5 deletions scripts/check_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
parser.add_argument("es_password", help="ES instance password value", type=str)
parser.add_argument("es_index", help="ES instance index value", type=str)
parser.add_argument("--es_regex", help="Regex to use to fetch indexed items", type=str, default=".+")
parser.add_argument("--log_only", help="Regex to use to fetch indexed items", type=bool, default=False)
parser.add_argument("--log_only", help="If True, will not fix broken links, just log them to std out", type=bool, default=False)
parser.add_argument("--index_package_names", help="If True, will add \"gh_package_name\" to indexed item", type=bool, default=True)
args = parser.parse_args()

es_instance = es.index(
Expand All @@ -36,11 +37,24 @@
err = True
print("%sERROR: Asset \"%s\" download link is incorrect. - %s" % (es_instance.Colors.FAIL, indexed_item['source']['name'], indexed_item['source']['download_link']))
if not args.log_only:
package_name = (json.loads(asset_status.text))['name']
url = gh_instance.asset_fetch_url_api(package_name, loose=False)
indexed_item['source']['download_link'] = url
es_instance.update(indexed_item['doc']['type'], indexed_item['doc']['id'], indexed_item['source'])
if 'gh_package_name' in indexed_item['source']:
url = gh_instance.asset_fetch_url_api(indexed_item['source']['gh_package_name'], loose=False)
indexed_item['source']['download_link'] = url
es_instance.update(indexed_item['doc']['type'], indexed_item['doc']['id'], indexed_item['source'])
else:
print("%sWARNING: Asset \"%s\" has no \"gh_package_name\" in the index." % (es_instance.Colors.WARNING, indexed_item['source']['name']))
else: ## code 200 - success, no need to reindex
if args.index_package_names:
package_name = (json.loads(asset_status.text))['name']
if 'gh_package_name' not in indexed_item['source']:
indexed_item['source'].update({"gh_package_name": package_name})
es_instance.update(indexed_item['doc']['type'], indexed_item['doc']['id'], indexed_item['source'])
print("%sINFO: Added \"gh_package_name\" to %s" % (es_instance.Colors.UNDERLINE, indexed_item['source']['name']))
else:
if package_name != indexed_item['source']['gh_package_name']:
indexed_item['source']['gh_package_name'] = package_name
es_instance.update(indexed_item['doc']['type'], indexed_item['doc']['id'], indexed_item['source'])
print("%sINFO: Updated \"gh_package_name\" for %s" % (es_instance.Colors.UNDERLINE, indexed_item['source']['name']))
print("%sOK: Asset \"%s\" download link is correct. - %s" % (es_instance.Colors.OKBLUE, indexed_item['source']['name'], indexed_item['source']['download_link']))

if err and args.log_only:
Expand Down
14 changes: 9 additions & 5 deletions scripts/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai
'published_at': published_at,
'category': 'Software Development Kit',
'download_link': asset['url'], # Adjust as needed for actual URL
"install_location" : "%APPLICATION_DATA_DIR%/packages/sdk",
'package_changed': version != version_index
'install_location' : "%APPLICATION_DATA_DIR%/packages/sdk",
'package_changed': version != version_index,
'gh_package_name': "mikrosdk.7z"
}
elif 'templates' == name_without_extension:
package_changed = True
Expand All @@ -291,7 +292,8 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai
"type" : "application",
"download_link" : asset['url'],
"install_location" : "%APPLICATION_DATA_DIR%/templates",
"package_changed": package_changed
"package_changed": package_changed,
"gh_package_name": "templates.7z"
}
elif 'images' == name_without_extension:
package_changed = True
Expand All @@ -308,7 +310,8 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai
"type" : "images",
"download_link" : asset['url'],
"install_location" : "%APPLICATION_DATA_DIR%/resources/images",
"package_changed": True
"package_changed": True,
"gh_package_name": "images.7z"
}
elif asset['name'].startswith('board') or \
asset['name'].startswith('mikromedia') or \
Expand Down Expand Up @@ -387,7 +390,8 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai
"install_location" : metadata_content[0]['packages'][package_name]['install_location'],
'package_changed': asset_version_previous != asset_version_new,
'show_package_info': show_package,
'hash': hash_new
'hash': hash_new,
'gh_package_name': os.path.splitext(os.path.basename(asset['name']))[0]
}

check_types = ['board', 'card']
Expand Down

0 comments on commit eb71c52

Please sign in to comment.