@@ -88,73 +88,80 @@ def report_size_deltas(self):
88
88
"""Comment a report of memory usage change to pull request(s)."""
89
89
if os .environ ["GITHUB_EVENT_NAME" ] == "pull_request" :
90
90
# The sketches reports will be in a local folder location specified by the user
91
- sketches_reports_folder = pathlib .Path (os .environ ["GITHUB_WORKSPACE" ], self .sketches_reports_source_name )
92
- sketches_reports = self .get_sketches_reports (artifact_folder_object = sketches_reports_folder )
93
-
94
- if sketches_reports :
95
- report = self .generate_report (sketches_reports = sketches_reports )
96
-
97
- with open (file = os .environ ["GITHUB_EVENT_PATH" ]) as github_event_file :
98
- pr_number = json .load (github_event_file )["pull_request" ]["number" ]
99
-
100
- self .comment_report (pr_number = pr_number , report_markdown = report )
101
-
91
+ self .report_size_deltas_from_local_reports ()
102
92
else :
103
93
# The script is being run from a workflow triggered by something other than a PR
104
94
# Scan the repository's pull requests and comment memory usage change reports where appropriate.
105
- # Get the repository's pull requests
106
- logger .debug ("Getting PRs for " + self .repository_name )
107
- page_number = 1
108
- page_count = 1
109
- while page_number <= page_count :
110
- api_data = self .api_request (request = "repos/" + self .repository_name + "/pulls" ,
111
- page_number = page_number )
112
- prs_data = api_data ["json_data" ]
113
- for pr_data in prs_data :
114
- # Note: closed PRs are not listed in the API response
115
- pr_number = pr_data ["number" ]
116
- pr_head_sha = pr_data ["head" ]["sha" ]
117
- print ("::debug::Processing pull request number:" , pr_number )
118
- # When a PR is locked, only collaborators may comment. The automatically generated GITHUB_TOKEN will
119
- # likely be used, which is owned by the github-actions bot, who doesn't have collaborator status. So
120
- # locking the thread would cause the job to fail.
121
- if pr_data ["locked" ]:
122
- print ("::debug::PR locked, skipping" )
123
- continue
95
+ self .report_size_deltas_from_workflow_artifacts ()
124
96
125
- if self .report_exists (pr_number = pr_number ,
126
- pr_head_sha = pr_head_sha ):
127
- # Go on to the next PR
128
- print ("::debug::Report already exists" )
129
- continue
97
+ def report_size_deltas_from_local_reports (self ):
98
+ """Comment a report of memory usage change to the pull request."""
99
+ sketches_reports_folder = pathlib .Path (os .environ ["GITHUB_WORKSPACE" ], self .sketches_reports_source_name )
100
+ sketches_reports = self .get_sketches_reports (artifact_folder_object = sketches_reports_folder )
130
101
131
- artifact_download_url = self .get_artifact_download_url_for_sha (
132
- pr_user_login = pr_data ["user" ]["login" ],
133
- pr_head_ref = pr_data ["head" ]["ref" ],
134
- pr_head_sha = pr_head_sha )
135
- if artifact_download_url is None :
136
- # Go on to the next PR
137
- print ("::debug::No sketches report artifact found" )
138
- continue
102
+ if sketches_reports :
103
+ report = self .generate_report (sketches_reports = sketches_reports )
139
104
140
- artifact_folder_object = self .get_artifact (artifact_download_url = artifact_download_url )
105
+ with open (file = os .environ ["GITHUB_EVENT_PATH" ]) as github_event_file :
106
+ pr_number = json .load (github_event_file )["pull_request" ]["number" ]
141
107
142
- sketches_reports = self .get_sketches_reports ( artifact_folder_object = artifact_folder_object )
108
+ self .comment_report ( pr_number = pr_number , report_markdown = report )
143
109
144
- if sketches_reports :
145
- if sketches_reports [0 ][self .ReportKeys .commit_hash ] != pr_head_sha :
146
- # The deltas report key uses the hash from the report, but the report_exists() comparison is
147
- # done using the hash provided by the API. If for some reason the two didn't match, it would
148
- # result in the deltas report being done over and over again.
149
- print ("::warning::Report commit hash doesn't match PR's head commit hash, skipping" )
150
- continue
110
+ def report_size_deltas_from_workflow_artifacts (self ):
111
+ """Scan the repository's pull requests and comment memory usage change reports where appropriate."""
112
+ # Get the repository's pull requests
113
+ logger .debug ("Getting PRs for " + self .repository_name )
114
+ page_number = 1
115
+ page_count = 1
116
+ while page_number <= page_count :
117
+ api_data = self .api_request (request = "repos/" + self .repository_name + "/pulls" ,
118
+ page_number = page_number )
119
+ prs_data = api_data ["json_data" ]
120
+ for pr_data in prs_data :
121
+ # Note: closed PRs are not listed in the API response
122
+ pr_number = pr_data ["number" ]
123
+ pr_head_sha = pr_data ["head" ]["sha" ]
124
+ print ("::debug::Processing pull request number:" , pr_number )
125
+ # When a PR is locked, only collaborators may comment. The automatically generated GITHUB_TOKEN will
126
+ # likely be used, which is owned by the github-actions bot, who doesn't have collaborator status. So
127
+ # locking the thread would cause the job to fail.
128
+ if pr_data ["locked" ]:
129
+ print ("::debug::PR locked, skipping" )
130
+ continue
131
+
132
+ if self .report_exists (pr_number = pr_number ,
133
+ pr_head_sha = pr_head_sha ):
134
+ # Go on to the next PR
135
+ print ("::debug::Report already exists" )
136
+ continue
137
+
138
+ artifact_download_url = self .get_artifact_download_url_for_sha (
139
+ pr_user_login = pr_data ["user" ]["login" ],
140
+ pr_head_ref = pr_data ["head" ]["ref" ],
141
+ pr_head_sha = pr_head_sha )
142
+ if artifact_download_url is None :
143
+ # Go on to the next PR
144
+ print ("::debug::No sketches report artifact found" )
145
+ continue
146
+
147
+ artifact_folder_object = self .get_artifact (artifact_download_url = artifact_download_url )
148
+
149
+ sketches_reports = self .get_sketches_reports (artifact_folder_object = artifact_folder_object )
150
+
151
+ if sketches_reports :
152
+ if sketches_reports [0 ][self .ReportKeys .commit_hash ] != pr_head_sha :
153
+ # The deltas report key uses the hash from the report, but the report_exists() comparison is
154
+ # done using the hash provided by the API. If for some reason the two didn't match, it would
155
+ # result in the deltas report being done over and over again.
156
+ print ("::warning::Report commit hash doesn't match PR's head commit hash, skipping" )
157
+ continue
151
158
152
- report = self .generate_report (sketches_reports = sketches_reports )
159
+ report = self .generate_report (sketches_reports = sketches_reports )
153
160
154
- self .comment_report (pr_number = pr_number , report_markdown = report )
161
+ self .comment_report (pr_number = pr_number , report_markdown = report )
155
162
156
- page_number += 1
157
- page_count = api_data ["page_count" ]
163
+ page_number += 1
164
+ page_count = api_data ["page_count" ]
158
165
159
166
def report_exists (self , pr_number , pr_head_sha ):
160
167
"""Return whether a report has already been commented to the pull request thread for the latest workflow run
0 commit comments