Skip to content

Commit 3ae0ae7

Browse files
committed
Add a little helper script for CodeQL database fetches
1 parent d3c7616 commit 3ae0ae7

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

misc/codeql_fetch_db.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
3+
# dep: https://github.com/cli/cli
4+
# e.g. get_codeql_db.sh ntp-project/ntp cpp
5+
6+
# CodeQL languages:
7+
#
8+
# - cpp: The C and C++ programming language
9+
# - csharp: The C# programming language
10+
# - go: The Go programming language
11+
# - java: The Java programming language
12+
# - python: The Python programming language
13+
# - ruby: The Ruby programming language
14+
# - swift: The Swift programming language
15+
# - rust: The Rust programming language
16+
17+
if [[ "$#" -ne 2 ]]; then
18+
echo "Usage: $0 github/nwo language"
19+
exit 1
20+
fi
21+
22+
db_info=$(gh api /repos/"$1"/code-scanning/codeql/databases --jq ".[] | select(.language == \"$2\")")
23+
24+
if [[ "$?" -ne 0 ]]; then
25+
exit 1
26+
fi
27+
28+
if [[ $db_info ]]; then
29+
dst=$(echo "$1_$2_codeql_db.zip" | sed 's/\//_/g')
30+
echo "Downloading CodeQL database to $PWD/$dst"
31+
if [ -e "$dst" ]; then
32+
echo "$dst already exists!"
33+
exit 1
34+
fi
35+
gh api /repos/"$1"/code-scanning/codeql/databases/"$2" -H 'Accept: application/zip' > "$dst"
36+
echo "Unzip database before use!"
37+
else
38+
echo "No $2 database available for $1"
39+
exit 1
40+
fi

0 commit comments

Comments
 (0)