Skip to content

Commit f179829

Browse files
committed
Prevent unnecessary GitHub API request
In order to access information about private repositories via the GitHub API, a GitHub access token is required. The only use of the GitHub API by the action is in determining the base ref of the pull request to use for reporting size deltas. A change was inadvertently made that caused this GitHub API request to be made every time the action was run, even when size deltas reporting was disabled. This resulted in the action failing when triggered from a private repository when the github-token input was not provided by the workflow.
1 parent 882d768 commit f179829

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

compilesketches/compilesketches.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,19 @@ def __init__(self, cli_version, fqbn_arg, platforms, libraries, sketch_paths, ve
126126
else:
127127
self.github_api = github.Github(login_or_token=github_token)
128128

129-
self.deltas_base_ref = self.get_deltas_base_ref()
130-
131129
self.enable_size_deltas_report = parse_boolean_input(boolean_input=enable_size_deltas_report)
132130
# The enable-size-deltas-report input has a default value so it should always be either True or False
133131
if self.enable_size_deltas_report is None:
134132
print("::error::Invalid value for enable-size-deltas-report input")
135133
sys.exit(1)
136134

135+
if self.enable_size_deltas_report:
136+
self.deltas_base_ref = self.get_deltas_base_ref()
137+
else:
138+
# If deltas reports are not enabled, there is no use for the base ref and it could result in an GitHub API
139+
# request which requires a GitHub token when used in a private repository
140+
self.deltas_base_ref = None
141+
137142
self.sketches_report_path = pathlib.PurePath(sketches_report_path)
138143

139144
def get_deltas_base_ref(self):

compilesketches/tests/test_compilesketches.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ def test_compilesketches():
208208
with pytest.raises(expected_exception=SystemExit, match="1"):
209209
get_compilesketches_object(enable_size_deltas_report="fooInvalidEnableSizeDeltasBoolean")
210210

211+
# Test deltas_base_ref when size deltas report is disabled
212+
compile_sketches = get_compilesketches_object(enable_size_deltas_report="false")
213+
assert compile_sketches.deltas_base_ref is None
214+
211215

212216
@pytest.mark.parametrize("event_name, expected_ref",
213217
[("pull_request", unittest.mock.sentinel.pull_request_base_ref),
@@ -1443,7 +1447,7 @@ def fetch(self):
14431447
def checkout(self):
14441448
pass
14451449

1446-
compile_sketches = get_compilesketches_object(deltas_base_ref=deltas_base_ref)
1450+
compile_sketches = get_compilesketches_object(enable_size_deltas_report="true", deltas_base_ref=deltas_base_ref)
14471451

14481452
mocker.patch("git.Repo", autospec=True, return_value=Repo())
14491453
mocker.patch.object(Repo, "fetch")

0 commit comments

Comments
 (0)