From 46870f2328a12f5be559a43836985898a2f46a97 Mon Sep 17 00:00:00 2001 From: Wabri <12409541+Wabri@users.noreply.github.com> Date: Tue, 5 Mar 2024 12:31:14 +0100 Subject: [PATCH] fix(open_issue): sanity issue resolve --- .../check_outdate_deps/check_outdate_deps.sh | 12 +++++------ workflows/check_outdate_deps/open_issue.py | 20 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/workflows/check_outdate_deps/check_outdate_deps.sh b/workflows/check_outdate_deps/check_outdate_deps.sh index f04195ac0..eed1198b1 100755 --- a/workflows/check_outdate_deps/check_outdate_deps.sh +++ b/workflows/check_outdate_deps/check_outdate_deps.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -pip3 install -r $REQUIREMENT_FILE -input=`pip3 list --outdated` +pip3 install -r "$REQUIREMENT_FILE" +input=$(pip3 list --outdated) compare_versions() { local version1=$1 @@ -12,8 +12,8 @@ compare_versions() { read -ra version2_splitted <<< "$version2" for ((i=0;i<${#version1_splitted[@]};i++)); do - delta=$(( ${version1_splitted[i]} - ${version2_splitted[i]} )) - if (( $delta != 0 )); then + delta=$(( version1_splitted[i] - version2_splitted[i] )) + if (( delta != 0 )); then echo $delta return fi @@ -27,8 +27,8 @@ while read -r line; do version="${BASH_REMATCH[2]}" latest="${BASH_REMATCH[3]}" - if [ $(compare_versions "$version" "$latest") -lt 0 ]; then - ./workflows/check_outdate_deps/open_issue.py $package $version $latest + if [ "$(compare_versions "$version" "$latest")" -lt 0 ]; then + ./workflows/check_outdate_deps/open_issue.py "$package" "$version" "$latest" fi fi done <<< "$input" diff --git a/workflows/check_outdate_deps/open_issue.py b/workflows/check_outdate_deps/open_issue.py index b141a350b..39689ef6f 100755 --- a/workflows/check_outdate_deps/open_issue.py +++ b/workflows/check_outdate_deps/open_issue.py @@ -1,19 +1,22 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python import argparse import requests import os import json + def get_description(requirement_file, package, latest): return f"""The package {package} is outdated in {requirement_file}. The latest version is {latest}. Please update the package to the latest version. Check the package [here](https://pypi.org/project/{package}/{latest}/) for more information. """ + def get_title(requirement_file, package_name, current_version, latest_version): return f"Dependency outdated in {requirement_file}: {package_name}:{current_version} -> {latest_version}" + if __name__ == '__main__': # Arguments parsing parser = argparse.ArgumentParser(description="Open issue with the correct argument") @@ -25,19 +28,19 @@ def get_title(requirement_file, package_name, current_version, latest_version): # Environment variable repo = os.environ.get("GITHUB_REPOSITORY") requirement_file = str(os.environ.get("REQUIREMENT_FILE")) - + # Define the title issue_title = get_title(requirement_file, args.package, args.version, args.latest) - + # The double quote on the issue_title is necessary to avoid duplicate issues query = f"repo:{repo} type:issue in:title \"{issue_title}\"" - + # Send the query response = requests.get("https://api.github.com/search/issues", params={"q": query}) data = response.json() - + # There is this error that we somehow try to avoid - # {'message': "API rate limit exceeded for 93.45.31.205. (But here's the good news: Authenticated requests get a higher rate limit. Check + # {'message': "API rate limit exceeded for 93.45.31.205. (But here's the good news: Authenticated requests get a higher rate limit. Check # out the documentation for more details.)", 'documentation_url': 'https://docs.github.com/rest/overview/resources-in-the-rest-api#rat # e-limiting'} if data["total_count"] > 0: @@ -47,12 +50,11 @@ def get_title(requirement_file, package_name, current_version, latest_version): token = os.environ.get("GITHUB_TOKEN") issue = {"title": issue_title, "body": issue_description} headers = {"Authorization": f"token {token}"} - + response = requests.post(f"https://api.github.com/repos/{repo}/issues", headers=headers, data=json.dumps(issue)) - + # Check the response if response.status_code == 201: print("Issue created successfully.") else: print(f"Failed to create issue. Status code: {response.status_code}.") -