Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60585de

Browse files
p0edoardopirovano
andauthored
Improve version guessing logic. (#9)
* Improve version guessing logic. We will now only prefix a user-supplied version for the release channel with `v` if it does not exist as-entered, and if the prefixed version exists. * Validate the existence of `set-version` arguments early. * Use correct name of owner and repo instead of hardcoded Co-authored-by: Edoardo Pirovano <[email protected]>
1 parent 41214ac commit 60585de

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

gh-codeql

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ error() {
1212

1313
rootdir="$(dirname "$0")"
1414
channel="$(gh config get extensions.codeql.channel)"
15+
version="$(gh config get extensions.codeql.version)"
1516

1617
if [ -z "$1" ]; then
1718
cat <<EOF
@@ -123,10 +124,24 @@ function set_version() {
123124
error "Version must be specified. Use 'latest' to automatically determine the latest version."
124125
elif [ "$version" = "latest" ]; then
125126
version="$(gh api "repos/$repo/releases/latest" --jq ".tag_name")"
126-
fi
127-
if [ $repo = 'github/codeql-cli-binaries' ] && [[ "$version" != v* ]] ; then
128-
# Versions in github/codeql-cli-binaries have tags prefixed with v; we add this in if the user forgot.
129-
version="v$version"
127+
else
128+
# Versions in github/codeql-cli-binaries have tags prefixed with v, which the user might have omitted.
129+
# If necessary, we add it in here.
130+
repoName=${repo#*/}
131+
repoOwner=${repo%/*}
132+
version="$(gh api graphql -f query='{
133+
repository(owner: "'"$repoOwner"'", name: "'"$repoName"'") {
134+
asEntered: release(tagName: "'"$version"'") {
135+
tagName
136+
}
137+
vPrefixed: release(tagName: "v'"$version"'") {
138+
tagName
139+
}
140+
}
141+
}' --jq '[.data.repository.[] | values][0].tagName')"
142+
if [ -z "$version" ] ; then
143+
error "Unknown version: '$1'."
144+
fi
130145
fi
131146
download "$version"
132147
gh config set extensions.codeql.version "$version"
@@ -168,7 +183,6 @@ if [ "$1" = "cleanup-all" ]; then
168183
exit 0
169184
fi
170185

171-
version="$(gh config get extensions.codeql.version)"
172186
if [ -z "$version" ]; then
173187
set_version latest
174188
version="$(gh config get extensions.codeql.version)"

0 commit comments

Comments
 (0)