Skip to content

Commit 0ac63ae

Browse files
fix(ci_visibility): use ||| as git show format separator when fetching user info [backport 1.20] (#8605)
Backport b887ed9 from #8559 to 1.20. Fixes an issue where git committer or author names containing a comma (eg: "Lastname, Firstname" instead of "Firstname Lastname") would cause the user info function to fail to unpack properly. This changes the separator for the git show command format to "|||" which should be far less common in committer or author names. ## Checklist - [x] Change(s) are motivated and described in the PR description - [x] Testing strategy is described if automated tests are not included in the PR - [x] Risks are described (performance impact, potential for breakage, maintainability) - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed or label `changelog/no-changelog` is set - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)) - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) - [x] If this PR changes the public interface, I've notified `@DataDog/apm-tees`. - [x] If change touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. ## Reviewer Checklist - [x] Title is accurate - [x] All changes are related to the pull request's stated goal - [x] Description motivates each change - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - [x] Testing strategy adequately addresses listed risks - [x] Change is maintainable (easy to change, telemetry, documentation) - [x] Release note makes sense to a user of the library - [x] Author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: Romain Komorn <[email protected]>
1 parent b904e48 commit 0ac63ae

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

ddtrace/ext/git.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ def extract_user_info(cwd=None):
140140
# type: (Optional[str]) -> Dict[str, Tuple[str, str, str]]
141141
"""Extract commit author info from the git repository in the current directory or one specified by ``cwd``."""
142142
# Note: `git show -s --format... --date...` is supported since git 2.1.4 onwards
143-
stdout = _git_subprocess_cmd("show -s --format=%an,%ae,%ad,%cn,%ce,%cd --date=format:%Y-%m-%dT%H:%M:%S%z", cwd=cwd)
144-
author_name, author_email, author_date, committer_name, committer_email, committer_date = stdout.split(",")
143+
stdout = _git_subprocess_cmd(
144+
"show -s --format=%an|||%ae|||%ad|||%cn|||%ce|||%cd --date=format:%Y-%m-%dT%H:%M:%S%z", cwd=cwd
145+
)
146+
author_name, author_email, author_date, committer_name, committer_email, committer_date = stdout.split("|||")
145147
return {
146148
"author": (author_name, author_email, author_date),
147149
"committer": (committer_name, committer_email, committer_date),

docs/spelling_wordlist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ autoreloading
55
CPython
66
Fargate
77
Firehose
8+
Firstname
89
Gunicorn
910
HTTPPropagator
1011
INfo
1112
IPv
13+
Lastname
1214
MySQL
1315
OpenTracing
1416
Runtimes
@@ -79,6 +81,7 @@ dogpile.cache
7981
dogstatsd
8082
dunder
8183
dsn
84+
eg
8285
elasticsearch
8386
elasticsearch1
8487
elasticsearch7
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
CI Visibility: fixes an issue where git author or committer names containing commas (eg: "Lastname, Firstname")
5+
would not work (and log an error) due to the use of comma as a separator.

tests/tracer/test_ci.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ def test_git_extract_user_info(git_repo):
6161
assert extracted_users["committer"] == expected_committer
6262

6363

64+
def test_git_extract_user_info_with_commas():
65+
with mock.patch(
66+
"ddtrace.ext.git._git_subprocess_cmd",
67+
return_value="Do, Jo|||[email protected]|||2021-01-19T09:24:53-0400|||Do, Ja|||[email protected]|||2021-01-20T04:37:21-0400",
68+
):
69+
extracted_users = git.extract_user_info()
70+
assert extracted_users["author"] == ("Do, Jo", "[email protected]", "2021-01-19T09:24:53-0400")
71+
assert extracted_users["committer"] == ("Do, Ja", "[email protected]", "2021-01-20T04:37:21-0400")
72+
73+
6474
def test_git_extract_user_info_error(git_repo_empty):
6575
"""On error, the author/committer tags should not be extracted, and should internally raise an error."""
6676
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)