Skip to content

Commit

Permalink
Update auto_cl.py
Browse files Browse the repository at this point in the history
  • Loading branch information
themanyfaceddemon authored Jun 27, 2024
1 parent df3e9ce commit 599cf6b
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions Tools/ATD/auto_cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ def get_pr_info(token, repo, pr_number):
else:
response.raise_for_status()

def get_latest_pr_number(token, repo):
url = f"https://api.github.com/repos/{repo}/pulls?state=all&sort=created&direction=desc&per_page=1"
headers = {
"Authorization": f"token {token}",
"Accept": "application/vnd.github.v3+json"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
pr_list = response.json()
if pr_list:
return pr_list[0]['number']
response.raise_for_status()

def load_yaml(file_path):
if os.path.exists(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
Expand Down Expand Up @@ -155,20 +168,19 @@ def update_cl_file(file_path, new_data):
logging.info("Updated PR data saved to ChangelogADT.yml")

def main():
if len(sys.argv) != 4:
logging.error("Usage: auto_cl.py <GITHUB_TOKEN> <REPO> <PR_NUMBER>")
if len(sys.argv) < 3:
logging.error("Usage: auto_cl.py <GITHUB_TOKEN> <REPO>")
sys.exit(1)

github_token = sys.argv[1]
repo = sys.argv[2]
pr_number = sys.argv[3]


pr_number = get_latest_pr_number(github_token, repo)
if pr_number is None:
logging.error("PR_NUMBER cannot be null")
logging.error("Failed to get the latest PR number")
sys.exit(1)

pr_number = int(pr_number)

pr_data = fetch_pr_data(github_token, repo, pr_number)

update_cl_file(CHANGELOG_PATH, pr_data)
Expand Down

0 comments on commit 599cf6b

Please sign in to comment.