Skip to content

Commit bb15bd0

Browse files
health script updates to run in pipeline (Azure#37162)
1 parent 5807bde commit bb15bd0

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
httpx==0.25.2
22
markdown==3.6
33
PyGitHub>=1.59.0
4-
setuptools==67.6.0
5-
-e ../../sdk/identity/azure-identity
6-
-e ../../tools/azure-sdk-tools
4+
setuptools==69.2.0
5+
-e ./sdk/identity/azure-identity
6+
-e ./tools/azure-sdk-tools

scripts/repo_health_status_report/output_health_report.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@
3434
GIT_TOKEN = os.environ["GH_TOKEN"]
3535
auth = Auth.Token(GIT_TOKEN)
3636
github = Github(auth=auth)
37-
# repo = github.get_repo("Azure/azure-sdk-for-python")
37+
repo = github.get_repo("Azure/azure-sdk-for-python")
38+
health_report_path = pathlib.Path(__file__).parent
3839

3940
# Azure DevOps
40-
DEVOPS_RESOURCE_UUID = "499b84ac-1321-427f-aa17-267ca6975798"
41-
token = DefaultAzureCredential().get_token(f"{DEVOPS_RESOURCE_UUID}/.default").token
41+
if not in_ci():
42+
DEVOPS_RESOURCE_UUID = "499b84ac-1321-427f-aa17-267ca6975798"
43+
token = DefaultAzureCredential().get_token(f"{DEVOPS_RESOURCE_UUID}/.default").token
44+
else:
45+
token =os.environ["SYSTEM_ACCESSTOKEN"]
4246
AUTH_HEADERS = {"Authorization": f"Bearer {token}"}
4347
DEVOPS_TASK_STATUS = typing.Literal[
4448
"abandoned",
@@ -252,7 +256,7 @@ def get_pipelines(
252256

253257
response = httpx.get(LIST_BUILDS, headers=AUTH_HEADERS)
254258
if response.status_code != 200:
255-
raise Exception(f"Failed to get pipelines - {response.status_code}")
259+
raise Exception(f"Failed to get pipelines - {response.status_code} {response.text}")
256260
pipelines_json = json.loads(response.text)
257261
python_pipelines = [
258262
pipeline
@@ -283,7 +287,8 @@ def get_pipelines(
283287

284288
def record_check_result(task: dict[str, str], type: str, pipeline: PipelineResultsUnion):
285289
pipeline.update({type: CheckStatus(status=task["result"])})
286-
pipeline[type]["log"] = task["log"]["url"]
290+
if task["log"]:
291+
pipeline[type]["log"] = task["log"].get("url")
287292

288293

289294
def record_test_result(
@@ -652,7 +657,6 @@ def report_sla_and_total_issues(
652657

653658
tracked_labels = map_codeowners_to_label(libraries)
654659
today = datetime.datetime.now(datetime.UTC)
655-
repo = github.get_repo("Azure/azure-sdk-for-python")
656660
filter_labels = ["issue-addressed", "needs-author-feedback", "feature-request"]
657661
issues = list(repo.get_issues(state="open", labels=["customer-reported", "Client"]))
658662
record_total_customer_reported_issues(libraries, tracked_labels, issues)
@@ -668,7 +672,7 @@ def report_sla_and_total_issues(
668672

669673

670674
def write_to_csv(libraries: dict[ServiceDirectory, dict[LibraryName, LibraryStatus]]) -> None:
671-
with open("./health_report.csv", mode="w", newline="", encoding="utf-8") as file:
675+
with open(health_report_path / "health_report.csv", mode="w", newline="", encoding="utf-8") as file:
672676
writer = csv.writer(file)
673677

674678
column_names = [
@@ -760,12 +764,12 @@ def write_to_markdown(libraries: dict[ServiceDirectory, dict[LibraryName, Librar
760764
sla = details.get("sla")
761765
if sla:
762766
question_link = (
763-
f"([link]({sla.get("question", {}).get("link", None)}))"
767+
f"([link]({sla.get('question', {}).get('link', None)}))"
764768
if sla.get("question", {}).get("link", None) is not None
765769
else ""
766770
)
767771
bug_link = (
768-
f"([link]({sla.get("bug", {}).get("link", None)}))"
772+
f"([link]({sla.get('bug', {}).get('link', None)}))"
769773
if sla.get("bug", {}).get("link", None) is not None
770774
else ""
771775
)
@@ -777,29 +781,29 @@ def write_to_markdown(libraries: dict[ServiceDirectory, dict[LibraryName, Librar
777781
library,
778782
status_colored,
779783
details["mypy"]["status"]
780-
+ (f" ([link]({details["mypy"]["link"]}))" if details["mypy"]["link"] is not None else ""),
784+
+ (f" ([link]({details['mypy']['link']}))" if details["mypy"]["link"] is not None else ""),
781785
details["pyright"]["status"]
782-
+ (f" ([link]({details["pyright"]["link"]}))" if details["pyright"]["link"] is not None else ""),
786+
+ (f" ([link]({details['pyright']['link']}))" if details["pyright"]["link"] is not None else ""),
783787
details["type_check_samples"],
784788
details["pylint"]["status"]
785-
+ (f" ([link]({details["pylint"]["link"]}))" if details["pylint"]["link"] is not None else ""),
789+
+ (f" ([link]({details['pylint']['link']}))" if details["pylint"]["link"] is not None else ""),
786790
details["sphinx"]["status"]
787-
+ (f" ([link]({details["sphinx"]["link"]}))" if details["sphinx"]["link"] is not None else ""),
791+
+ (f" ([link]({details['sphinx']['link']}))" if details["sphinx"]["link"] is not None else ""),
788792
details["ci"]["status"]
789-
+ (f" ([link]({details["ci"]["link"]}))" if details["ci"]["link"] is not None else ""),
793+
+ (f" ([link]({details['ci']['link']}))" if details["ci"]["link"] is not None else ""),
790794
details["tests"]["status"]
791-
+ (f" ([link]({details["tests"]["link"]}))" if details["tests"]["link"] is not None else ""),
795+
+ (f" ([link]({details['tests']['link']}))" if details["tests"]["link"] is not None else ""),
792796
sla_str,
793797
str(details.get("customer_issues", {}).get("num", 0))
794798
+ (
795-
f" ([link]({details.get("customer_issues", {}).get("link", "")}))"
796-
if details.get("customer_issues", {}).get("link", None) is not None
799+
f" ([link]({details.get('customer_issues', {}).get('link', '')}))"
800+
if details.get('customer_issues', {}).get('link', None) is not None
797801
else ""
798802
),
799803
]
800804
rows.append(row)
801805

802-
with open("./health_report.md", mode="w", newline="", encoding="utf-8") as file:
806+
with open(health_report_path / "health_report.md", mode="w", newline="", encoding="utf-8") as file:
803807

804808
file.write("|" + "|".join(column_names) + "|\n")
805809
file.write("|" + "---|" * len(column_names) + "\n")
@@ -811,7 +815,7 @@ def write_to_markdown(libraries: dict[ServiceDirectory, dict[LibraryName, Librar
811815

812816
def write_to_html(libraries: dict[ServiceDirectory, dict[LibraryName, LibraryStatus]]) -> None:
813817
write_to_markdown(libraries)
814-
with open("./health_report.md", "r") as f:
818+
with open(health_report_path / "health_report.md", "r", encoding="utf-8") as f:
815819
markd = f.read()
816820

817821
html = markdown.markdown(markd, extensions=["tables"])
@@ -830,7 +834,7 @@ def write_to_html(libraries: dict[ServiceDirectory, dict[LibraryName, LibrarySta
830834

831835
html_with_css = css_styles + html
832836

833-
with open("./health_report.html", "w", encoding="utf-8") as file:
837+
with open(health_report_path / "health_report.html", "w", encoding="utf-8") as file:
834838
file.write(html_with_css)
835839

836840

@@ -872,11 +876,13 @@ def write_to_html(libraries: dict[ServiceDirectory, dict[LibraryName, LibrarySta
872876
elif args.format == "html":
873877
write_to_html(libraries)
874878

875-
# if in_ci():
876-
# repo = github.get_repo("Azure/azure-sdk-for-python")
877-
# repo.create_file(
878-
# path="scripts/library_health_status/health_report.csv",
879-
# message="Update health report",
880-
# content=open("health_report.csv", "rb").read(),
881-
# branch="health-status-script",
882-
# )
879+
if in_ci():
880+
path = "scripts/repo_health_status_report/health_report.csv"
881+
content = repo.get_contents(path, ref="python-sdk-health-report")
882+
repo.update_file(
883+
path=path,
884+
message="Update health report",
885+
content=open(path, "rb").read(),
886+
branch="python-sdk-health-report",
887+
sha=content.sha
888+
)

0 commit comments

Comments
 (0)