Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for local ruleset #7

Merged
merged 5 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/lint-using-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ jobs:
steps:
- name: Run Linter
uses: philips-labs/continuous-compliance@main
env:
target_repos: ${{ github.event.inputs.target_repos }}
GITHUB_TOKEN: ${{ secrets.TEMP_TOKEN }}
with:
target_repos: ${{ github.event.inputs.target_repos }}
gh_token: ${{ secrets.TEMP_TOKEN }}
gh_token: ${{ secrets.TEMP_TOKEN }}
ruleset: "https://gist.githubusercontent.com/Brend-Smits/385824d3422c0c06323bb1412cd5ba96/raw/08676dbf366a86641dd30fd5511b91afdee65adc/gistfile1.txt"
7 changes: 3 additions & 4 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ branding:
icon: lock
color: purple
inputs:
ruleset_file_url:
description: 'url that links to a ruleset config file'
ruleset:
description: 'file path or url that links to a ruleset config file'
required: true
default: 'https://gist.githubusercontent.com/Brend-Smits/385824d3422c0c06323bb1412cd5ba96/raw/08676dbf366a86641dd30fd5511b91afdee65adc/gistfile1.txt'
gh_token:
description: 'Github token that has permissions to create labels, issues and has read rights to view files.'
required: true
Expand All @@ -19,5 +18,5 @@ runs:
image: 'docker://ghcr.io/philips-labs/continuous-compliance:latest'
args:
- "${{ inputs.gh_token }}"
- "${{ inputs.ruleset_file_url }}"
- "${{ inputs.ruleset }}"
- "${{ inputs.target_repos }}"
34 changes: 26 additions & 8 deletions bin/loop.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
#!/bin/bash
[ -n "$1" ] && GITHUB_TOKEN=$1 || exit 1
[ -n "$2" ] && RULESET_FILE_URL=$2 || exit 1
[ -n "$2" ] && RULESET=$2 || exit 1
[ -n "$3" ] && TARGET_REPOS=$3 || exit 1

for i in $(echo "$TARGET_REPOS" | sed "s/,/ /g"); do
export TARGET_REPO=$i
echo " checking: $i"
/app/repolinter/bin/repolinter.js lint \
--rulesetUrl "$RULESET_FILE_URL" \
-g https://x-access-token:"$GITHUB_TOKEN"@github.com/"${i}"
done
# Function that checks the target repositories with repolinter
# $1 is the ruleset argument, valid examples here are:
# 1. --rulesetFile /config/ruleset.json
# 2. --rulesetUrl https://gist.github.com/ruleset.json
function check_target_repos {
for i in $(echo "$TARGET_REPOS" | sed "s/,/ /g"); do
export TARGET_REPO=$i
echo "Checking repository: $i"
echo "Using ruleset parameter: $1"
/app/repolinter/bin/repolinter.js lint \
"$1" \
-g https://x-access-token:"$GITHUB_TOKEN"@github.com/"${i}"
done
}

regex='(https?)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'

if [[ $RULESET =~ $regex ]]
then
echo "Link valid"
check_target_repos "--rulesetUrl ""$RULESET"""
else
echo "No link, assuming file path"
check_target_repos "--rulesetFile ""$RULESET"""
fi