Skip to content

Commit 0d1d7dc

Browse files
committed
csfilter-kfp: record SHA1 hash of HEAD in JSON output
... in case `--kfp-git-url` is used without a pinned revision Related: https://issues.redhat.com/browse/OSH-737 Closes: #207
1 parent 89ee499 commit 0d1d7dc

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/csfilter-kfp

+8-5
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,19 @@ def construct_init_cmd(args):
5353

5454
def construct_git_cmd(kfp_git_url):
5555
# split kfp_git_url into the clone URL and (optional) revision
56-
m = re.match("^(.*)#([0-9a-f]+)", kfp_git_url)
56+
m = re.match("^(.*)#([0-9a-f]+)$", kfp_git_url)
5757
if m:
5858
# checkout a specific revision
5959
url = shlex.quote(m.group(1))
60-
rev = m.group(2)
60+
rev = m.group(2) # no need to quote `rev` because it matches [0-9a-f]+
6161
return f'git clone {url} ${{td}}/kfp\n' \
62-
f'git -C "${{td}}/kfp" reset -q --hard {rev}\n'
62+
f'git -C "${{td}}/kfp" reset -q --hard {rev}\n' \
63+
'git_url_suffix=\n'
6364
else:
6465
# shallow clone of the default branch
6566
url = shlex.quote(kfp_git_url)
66-
return f'git clone --depth 1 {url} "${{td}}/kfp"\n'
67+
return f'git clone --depth 1 {url} "${{td}}/kfp"\n' \
68+
f'git_url_suffix="#$(git -C "${{td}}/kfp" rev-parse HEAD)"\n'
6769

6870

6971
def construct_prep_cmd(args):
@@ -166,7 +168,8 @@ def construct_filter_cmd(args):
166168
cmd += f' --set-scan-prop=known-false-positives-dir:{kfp_dir}'
167169
elif args.kfp_git_url:
168170
kfp_git_url = shlex.quote(args.kfp_git_url)
169-
cmd += f' --set-scan-prop=known-false-positives-git-url:{kfp_git_url}'
171+
cmd += f' --set-scan-prop=known-false-positives-git-url:{kfp_git_url}' \
172+
'${git_url_suffix}'
170173
cmd += '\n'
171174

172175
return cmd

tests/csfilter-kfp/0002-stdout.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export td=$(mktemp --directory --tmpdir tmp-csfilter-kfp.XXXXXXXXXX)
55
trap "rm -fr '${td}'" EXIT
66
set -x
77
git clone --depth 1 https://github.com/csutils/kfp.git "${td}/kfp"
8+
git_url_suffix="#$(git -C "${td}/kfp" rev-parse HEAD)"
89
touch "${td}/empty.err"
910
(cd "${td}/kfp" && csgrep --mode=json --remove-duplicates ${td}/empty.err */ignore.err */true-positives-ignore.err >"${td}/kfp.json")
1011
csgrep --mode=json >"${td}/input.json"
@@ -21,4 +22,4 @@ path_filter() {
2122
fi
2223
}
2324
csdiff --show-internal "${td}/kfp.json" "${td}/input.json" | path_filter >${td}/output.json
24-
csgrep --mode=json "${td}/output.json" --set-scan-prop=known-false-positives-git-url:https://github.com/csutils/kfp.git
25+
csgrep --mode=json "${td}/output.json" --set-scan-prop=known-false-positives-git-url:https://github.com/csutils/kfp.git${git_url_suffix}

tests/csfilter-kfp/0003-stdout.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export td=$(mktemp --directory --tmpdir tmp-csfilter-kfp.XXXXXXXXXX)
55
trap "rm -fr '${td}'" EXIT
66
git clone https://github.com/csutils/kfp.git ${td}/kfp
77
git -C "${td}/kfp" reset -q --hard 96408af024db801c3cb6ebda2bff47fe6c45ad09
8+
git_url_suffix=
89
touch "${td}/empty.err"
910
(cd "${td}/kfp" && csgrep --mode=json --remove-duplicates ${td}/empty.err */ignore.err */true-positives-ignore.err >"${td}/kfp.json")
1011
csgrep --mode=json scan-results.json >"${td}/input.json"
@@ -13,4 +14,4 @@ path_filter() {
1314
}
1415
csdiff --show-internal "${td}/kfp.json" "${td}/input.json" | path_filter >${td}/output.json
1516
csdiff "${td}/output.json" "${td}/input.json" >excluded.json
16-
csgrep --mode=json "${td}/output.json" --set-scan-prop=known-false-positives-git-url:'https://github.com/csutils/kfp.git#96408af024db801c3cb6ebda2bff47fe6c45ad09'
17+
csgrep --mode=json "${td}/output.json" --set-scan-prop=known-false-positives-git-url:'https://github.com/csutils/kfp.git#96408af024db801c3cb6ebda2bff47fe6c45ad09'${git_url_suffix}

0 commit comments

Comments
 (0)