Skip to content

Commit b65c1c6

Browse files
committed
github actions: jira pr checker init
Test will write a real PR later.
1 parent 353ee37 commit b65c1c6

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: JIRA PR Check
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
jira-pr-check:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
14+
steps:
15+
- name: Checkout kernel-src-tree
16+
uses: actions/checkout@v4
17+
with:
18+
path: kernel-src-tree
19+
fetch-depth: 0
20+
21+
- name: Checkout kernel-src-tree-tools
22+
uses: actions/checkout@v4
23+
with:
24+
repository: ctrliq/kernel-src-tree-tools
25+
ref: '{jmaple}_pr_jira_test'
26+
path: kernel-src-tree-tools
27+
28+
- name: Set up Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: '3.x'
32+
33+
- name: Install dependencies
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install jira
37+
38+
- name: Mask JIRA credentials
39+
run: |
40+
echo "::add-mask::${{ secrets.JIRA_API_USER }}"
41+
echo "::add-mask::${{ secrets.JIRA_API_TOKEN }}"
42+
43+
- name: Run JIRA PR Check
44+
id: jira_check
45+
continue-on-error: true
46+
env:
47+
JIRA_URL: ${{ secrets.JIRA_URL }}
48+
JIRA_API_USER: ${{ secrets.JIRA_API_USER }}
49+
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
50+
run: |
51+
cd kernel-src-tree-tools
52+
53+
# Run script and capture output, ensuring credentials are never echoed
54+
set +x # Disable command echo to prevent credential exposure
55+
set +e # Don't exit on error, we want to capture the output
56+
OUTPUT=$(python3 jira_pr_check.py \
57+
--jira-url "${JIRA_URL}" \
58+
--jira-user "${JIRA_API_USER}" \
59+
--jira-key "${JIRA_API_TOKEN}" \
60+
--kernel-src-tree ../kernel-src-tree \
61+
--merge-target ${{ github.base_ref }} \
62+
--pr-branch ${{ github.head_ref }} 2>&1)
63+
EXIT_CODE=$?
64+
65+
# Filter out any potential credential leaks from output
66+
FILTERED_OUTPUT=$(echo "$OUTPUT" | grep -v "jira-user\|jira-key\|basic_auth\|Authorization" || true)
67+
68+
echo "$FILTERED_OUTPUT"
69+
echo "output<<EOF" >> $GITHUB_OUTPUT
70+
echo "$FILTERED_OUTPUT" >> $GITHUB_OUTPUT
71+
echo "EOF" >> $GITHUB_OUTPUT
72+
73+
# Check if there are any issues based on output patterns
74+
if echo "$FILTERED_OUTPUT" | grep -q "❌ Errors:"; then
75+
echo "has_issues=true" >> $GITHUB_OUTPUT
76+
77+
# Check specifically for LTS mismatch errors
78+
if echo "$FILTERED_OUTPUT" | grep -q "expects branch"; then
79+
echo "has_lts_mismatch=true" >> $GITHUB_OUTPUT
80+
else
81+
echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT
82+
fi
83+
elif echo "$FILTERED_OUTPUT" | grep -q "⚠️ Warnings:"; then
84+
echo "has_issues=true" >> $GITHUB_OUTPUT
85+
echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT
86+
else
87+
echo "has_issues=false" >> $GITHUB_OUTPUT
88+
echo "has_lts_mismatch=false" >> $GITHUB_OUTPUT
89+
fi
90+
91+
# Exit with the script's exit code
92+
exit $EXIT_CODE
93+
94+
- name: Comment PR with issues
95+
if: steps.jira_check.outputs.has_issues == 'true'
96+
uses: actions/github-script@v7
97+
with:
98+
github-token: ${{ secrets.GITHUB_TOKEN }}
99+
script: |
100+
const output = process.env.CHECK_OUTPUT;
101+
102+
github.rest.issues.createComment({
103+
issue_number: context.issue.number,
104+
owner: context.repo.owner,
105+
repo: context.repo.repo,
106+
body: output
107+
});
108+
env:
109+
CHECK_OUTPUT: ${{ steps.jira_check.outputs.output }}
110+
111+
- name: Request changes if LTS mismatch
112+
if: steps.jira_check.outputs.has_lts_mismatch == 'true'
113+
uses: actions/github-script@v7
114+
with:
115+
github-token: ${{ secrets.GITHUB_TOKEN }}
116+
script: |
117+
github.rest.pulls.createReview({
118+
owner: context.repo.owner,
119+
repo: context.repo.repo,
120+
pull_number: context.issue.number,
121+
event: 'REQUEST_CHANGES',
122+
body: '⚠️ This PR contains VULN tickets that do not match the target LTS product. Please review the JIRA ticket assignments and ensure they match the merge target branch.'
123+
});
124+
125+
- name: Fail workflow if errors found
126+
if: steps.jira_check.outcome == 'failure'
127+
run: |
128+
echo "❌ JIRA PR check failed - errors were found in one or more commits"
129+
exit 1

0 commit comments

Comments
 (0)