Skip to content

Commit 51c7b16

Browse files
Warn on a detached HEAD and on an ignored --branch
With --job-name, a detached HEAD is resolved as a feature branch, just as an empty branch is, but only the empty branch warned. Both warn now. A --branch (or DASHBOARD_BRANCH) without --job-name is ignored by design, and the report now says so instead of dropping it silently. Also shortens an overlong docstring line. Signed-off-by: Miguel Dalberto Pedro <miguel.pedro@precisioninno.com>
1 parent 1ef6243 commit 51c7b16

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎flow/test/test_checkQorMetrics.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ def test_checkout_sends_only_the_commit(self):
149149
self.assertEqual(payload["Metrics"], {"finish__timing__setup__ws": 1.5})
150150

151151
def test_branch_is_dropped_without_a_job_name(self):
152-
_, _, payloads = self.run_check("--branch", "feature")
152+
_, output, payloads = self.run_check("--branch", "feature")
153153
self.assertEqual(payloads[0]["BranchName"], "")
154+
self.assertIn("--branch (DASHBOARD_BRANCH) is ignored", output)
154155

155156
def test_job_name_sends_the_branch(self):
156157
_, _, payloads = self.run_check("--job-name", "orfs-ci", "--branch", "feature")
@@ -233,8 +234,11 @@ def test_detached_head_reads_as_head(self):
233234
repository, master, _ = self.repository()
234235
git(repository, "checkout", "-q", "--detach", master)
235236
self.enter(repository)
236-
_, _, payloads = self.run_check("--job-name", "orfs-ci")
237+
_, output, payloads = self.run_check("--job-name", "orfs-ci")
237238
self.assertEqual(payloads[0]["BranchName"], "HEAD")
239+
self.assertIn(
240+
"[WARN] Checking as a build of orfs-ci with a detached HEAD", output
241+
)
238242

239243
def test_no_branch_outside_a_repository_warns(self):
240244
_, output, payloads = self.run_check("--job-name", "orfs-ci")

‎flow/util/checkQorMetrics.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class MetadataError(Exception):
169169

170170

171171
def load_metadata(path, only_prefix=None):
172-
"""Returns (metrics, commit_sha, dropped). Raises MetadataError if the file is unusable.
172+
"""Returns (metrics, commit_sha, dropped), or raises MetadataError.
173173
174174
dropped names the metrics left out because their value is not finite.
175175
@@ -871,6 +871,11 @@ def run_check(argv=None):
871871
)
872872
if base_commit:
873873
header.append(f"[INFO] Baseline pinned to commit {base_commit}")
874+
elif args.job_name and branch == "HEAD":
875+
header.append(
876+
f"[WARN] Checking as a build of {args.job_name} with a detached HEAD "
877+
"(no --branch): resolved as a feature branch."
878+
)
874879
elif args.job_name and branch:
875880
header.append(
876881
f"[INFO] Checking as a build of {args.job_name}, branch {branch}"
@@ -891,6 +896,11 @@ def run_check(argv=None):
891896
f"[INFO] A commit on no remote branch is pinned to its merge base with "
892897
f"{merge_base_ref} (DASHBOARD_MERGE_BASE=none turns this off)"
893898
)
899+
if args.branch and not args.job_name:
900+
header.append(
901+
"[WARN] --branch (DASHBOARD_BRANCH) is ignored without --job-name: "
902+
"a checkout is resolved from its commit."
903+
)
894904
if args.only_prefix:
895905
prefixes = " ".join(args.only_prefix)
896906
header.append(f"[INFO] Sending only metrics prefixed {prefixes}")

0 commit comments

Comments
 (0)