Skip to content

Commit eef8d15

Browse files
author
Cesar Rodriguez
authored
Merge pull request #27 from nasir-rabbani/repo-url-arg
Repo URL arg support
2 parents ba4ac4f + a5774a8 commit eef8d15

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ If this variable is included, the scan results and the normalized config will be
4646

4747
### `webhook_token`
4848
Included this variable if the notification webhook url requires authentication.
49+
4950
## Example usage
5051

5152
```yaml

entrypoint.sh

+26-2
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,40 @@ echo "INPUT_VERBOSE=${INPUT_VERBOSE}"
1515
echo "INPUT_FIND_VULNERABILITIES=${INPUT_FIND_VULNERABILITIES}"
1616
echo "INPUT_WEBHOOK_URL=${INPUT_WEBHOOK_URL}"
1717

18-
# Retrieving SCM URL from CI variables
18+
# Retrieving SCM URL, Repository URL and REF from CI variables
1919
if [ "x${GITHUB_SERVER_URL}" != "x" ]; then
2020
# Handling GitHub
2121
SCM_SERVER_URL="${GITHUB_SERVER_URL}"
22+
REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
23+
24+
if [ "x${GITHUB_REF}" != "x" ]; then
25+
REF_NAME="$(echo ${GITHUB_REF#refs/heads/})"
26+
else
27+
REF_NAME="$(echo ${GITHUB_HEAD_REF#refs/heads/})"
28+
fi
2229
elif [ "x${CI_SERVER_URL}" != "x" ]; then
2330
# Handling GitLab
2431
SCM_SERVER_URL="${CI_SERVER_URL}"
32+
REPO_URL="${CI_REPOSITORY_URL}"
33+
REF_NAME="${CI_COMMIT_REF_NAME}"
34+
2535
elif [ "x${BITBUCKET_GIT_HTTP_ORIGIN}" != "x" ]; then
2636
# Handling Bitbucket
27-
SCM_SERVER_URL="https://$(echo ${BITBUCKET_URL#"https://"} | cut -d'/' -f 1)"
37+
SCM_SERVER_URL="https://$(echo ${BITBUCKET_GIT_HTTP_ORIGIN#"http://"} | cut -d'/' -f 1)"
38+
REPO_URL="${SCM_SERVER_URL}/${BITBUCKET_REPO_FULL_NAME}"
39+
40+
if [ "x${BITBUCKET_BRANCH}" != "x" ]; then
41+
REF_NAME="${BITBUCKET_BRANCH}"
42+
else
43+
REF_NAME="${BITBUCKET_TAG}"
44+
fi
2845
else
2946
echo "WARNING: No SCM server URL found."
3047
fi
3148

3249
echo "SCM_SERVER_URL=${SCM_SERVER_URL}"
50+
echo "REPO_URL=${REPO_URL}"
51+
echo "REF_NAME=${REF_NAME}"
3352

3453
# Creating arguments for terrascan
3554
args=""
@@ -72,6 +91,11 @@ fi
7291
if [ "x${INPUT_WEBHOOK_TOKEN}" != "x" ]; then
7392
args="${args} --webhook-token ${INPUT_WEBHOOK_TOKEN}"
7493
fi
94+
if [ "x${REPO_URL}" != "x" ]; then
95+
args="${args} --repo-url ${REPO_URL}"
96+
args="${args} --repo-ref ${REF_NAME}"
97+
fi
98+
7599
#Executing terrascan
76100
echo "Executing terrascan as follows:"
77101
echo "terrascan scan ${args}"

0 commit comments

Comments
 (0)