Skip to content

Commit beb5e9b

Browse files
meysholdtona-agent
andcommitted
Simplify command steps for demo readability
- Install: 3 lines, no version detection logic - Login: single pipeline, no temp variables - API call: use gh's {owner}/{repo} placeholders Co-authored-by: Ona <no-reply@ona.com>
1 parent 28e4ff6 commit beb5e9b

2 files changed

Lines changed: 18 additions & 52 deletions

File tree

.ona/fix-codescan-alert.yaml

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,23 @@ action:
1111
maxParallel: 1
1212
maxTotal: 10
1313
steps:
14+
# Step 1: Install gh CLI if not present
1415
- task:
1516
command: |
16-
set -e
17-
if command -v gh &>/dev/null; then
18-
echo "gh already installed: $(gh --version | head -1)"
19-
exit 0
20-
fi
21-
echo "Installing GitHub CLI..."
22-
GH_VERSION=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | grep -oP '"tag_name":\s*"v\K[^"]+')
23-
curl -sL "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_amd64.tar.gz" | tar xz -C /tmp
24-
sudo mv "/tmp/gh_${GH_VERSION}_linux_amd64/bin/gh" /usr/local/bin/gh
25-
rm -rf "/tmp/gh_${GH_VERSION}_linux_amd64"
26-
echo "gh version: $(gh --version | head -1)"
17+
command -v gh && exit 0
18+
curl -sL https://github.com/cli/cli/releases/latest/download/gh_2.74.0_linux_amd64.tar.gz | tar xz -C /tmp
19+
sudo mv /tmp/gh_2.74.0_linux_amd64/bin/gh /usr/local/bin/gh
20+
# Step 2: Authenticate gh using the git credential helper
2721
- task:
2822
command: |
29-
set -e
30-
TOKEN=$(git credential fill <<EOF | grep password | cut -d= -f2
31-
protocol=https
32-
host=github.com
33-
34-
EOF
35-
)
36-
echo "$TOKEN" | gh auth login --with-token
37-
gh auth status
23+
printf 'protocol=https\nhost=github.com\n\n' | git credential fill | awk -F= '/password/{print $2}' | gh auth login --with-token
24+
# Step 3: Fetch the highest-severity open code scanning alert
3825
- task:
3926
command: |
40-
set -e
41-
OWNER=$(gh repo view --json owner -q '.owner.login')
42-
REPO=$(gh repo view --json name -q '.name')
43-
gh api "repos/${OWNER}/${REPO}/code-scanning/alerts" \
27+
gh api repos/{owner}/{repo}/code-scanning/alerts \
4428
--jq '[.[] | select(.state=="open")] | sort_by(.rule.security_severity_level // "low") | reverse | .[0]' \
4529
> /tmp/codescan-alert.json
46-
echo "Selected alert:"
47-
cat /tmp/codescan-alert.json | head -50
30+
cat /tmp/codescan-alert.json
4831
- agent:
4932
prompt: |
5033
Read the file /tmp/codescan-alert.json which contains the highest-severity

.ona/fix-dependabot-alert.yaml

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,23 @@ action:
1111
maxParallel: 1
1212
maxTotal: 10
1313
steps:
14+
# Step 1: Install gh CLI if not present
1415
- task:
1516
command: |
16-
set -e
17-
if command -v gh &>/dev/null; then
18-
echo "gh already installed: $(gh --version | head -1)"
19-
exit 0
20-
fi
21-
echo "Installing GitHub CLI..."
22-
GH_VERSION=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | grep -oP '"tag_name":\s*"v\K[^"]+')
23-
curl -sL "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_amd64.tar.gz" | tar xz -C /tmp
24-
sudo mv "/tmp/gh_${GH_VERSION}_linux_amd64/bin/gh" /usr/local/bin/gh
25-
rm -rf "/tmp/gh_${GH_VERSION}_linux_amd64"
26-
echo "gh version: $(gh --version | head -1)"
17+
command -v gh && exit 0
18+
curl -sL https://github.com/cli/cli/releases/latest/download/gh_2.74.0_linux_amd64.tar.gz | tar xz -C /tmp
19+
sudo mv /tmp/gh_2.74.0_linux_amd64/bin/gh /usr/local/bin/gh
20+
# Step 2: Authenticate gh using the git credential helper
2721
- task:
2822
command: |
29-
set -e
30-
TOKEN=$(git credential fill <<EOF | grep password | cut -d= -f2
31-
protocol=https
32-
host=github.com
33-
34-
EOF
35-
)
36-
echo "$TOKEN" | gh auth login --with-token
37-
gh auth status
23+
printf 'protocol=https\nhost=github.com\n\n' | git credential fill | awk -F= '/password/{print $2}' | gh auth login --with-token
24+
# Step 3: Fetch the highest-severity open Dependabot alert
3825
- task:
3926
command: |
40-
set -e
41-
OWNER=$(gh repo view --json owner -q '.owner.login')
42-
REPO=$(gh repo view --json name -q '.name')
43-
gh api "repos/${OWNER}/${REPO}/dependabot/alerts" \
27+
gh api repos/{owner}/{repo}/dependabot/alerts \
4428
--jq '[.[] | select(.state=="open")] | sort_by(.security_advisory.cvss.score) | reverse | .[0]' \
4529
> /tmp/dependabot-alert.json
46-
echo "Selected alert:"
47-
cat /tmp/dependabot-alert.json | head -50
30+
cat /tmp/dependabot-alert.json
4831
- agent:
4932
prompt: |
5033
Read the file /tmp/dependabot-alert.json which contains the highest-severity

0 commit comments

Comments
 (0)