Skip to content

Commit 7c93d15

Browse files
authored
create a validation for se packs (demisto#40993)
* create a validation for se packs * change to accepts zero or more values in changed_files
1 parent 6bab007 commit 7c93d15

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import sys
2+
from github import Github
3+
import argparse
4+
import urllib3
5+
from github.Repository import Repository
6+
from github.PullRequest import PullRequest
7+
from utils import timestamped_print
8+
9+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
10+
print = timestamped_print
11+
12+
SE_APPROVED_LABEL = "se-approved"
13+
SE_PACKS = {
14+
"FortiGate",
15+
"CheckpointFirewall",
16+
"Zscaler",
17+
"ZscalerZPA",
18+
"CiscoASA",
19+
"CorelightZeek",
20+
"Okta",
21+
"MicrosoftEntraID",
22+
"GoogleCloudLogging",
23+
"MicrosoftEntraID",
24+
"AWS-CloudTrail",
25+
"GoogleCloudLogging",
26+
"Office365",
27+
"Dropbox",
28+
"DuoAdminApi",
29+
"MicrosoftWindowsEvents",
30+
"Box",
31+
"OneLogin",
32+
}
33+
34+
35+
def arguments_handler():
36+
"""Validates and parses script arguments.
37+
Returns:
38+
Namespace: Parsed arguments object.
39+
"""
40+
parser = argparse.ArgumentParser(description="Check if se-packs-approved label exists.")
41+
parser.add_argument("-p", "--pr_number", help="The PR number to check if the label exists.")
42+
parser.add_argument("-g", "--github_token", help="The GitHub token to authenticate the GitHub client.")
43+
parser.add_argument("-c", "--changed_files", nargs="*", help="The path of modified files")
44+
return parser.parse_args()
45+
46+
47+
def main():
48+
"""
49+
This script is checking that "docs-approved" label exists for a PR in case
50+
the label exists the workflow will pass, if the label is missing the workflow will fail.
51+
"""
52+
org_name = "demisto"
53+
repo_name = "content"
54+
options = arguments_handler()
55+
pr_number = options.pr_number
56+
github_token = options.github_token
57+
changed_files = options.changed_files
58+
59+
github_client: Github = Github(github_token, verify=False)
60+
content_repo: Repository = github_client.get_repo(f"{org_name}/{repo_name}")
61+
pr: PullRequest = content_repo.get_pull(int(pr_number))
62+
63+
pr_label_names = [label.name for label in pr.labels]
64+
se_approved = SE_APPROVED_LABEL in pr_label_names
65+
66+
watched_folders = SE_PACKS
67+
watched_folders = {folder.lower() for folder in watched_folders if folder}
68+
# Detect if watched folder changed
69+
folder_changed = any(file.split("/")[1].lower() in watched_folders for file in changed_files)
70+
# Validation logic
71+
if folder_changed and not se_approved:
72+
print(f"❌ Missing {SE_APPROVED_LABEL} label: This pack has XSIAM content that is also available in SE, please verify.")
73+
sys.exit(1)
74+
75+
if not folder_changed and se_approved:
76+
print(f"❌ Label '{SE_APPROVED_LABEL}' added, but no changes found in SE packs")
77+
sys.exit(1)
78+
79+
sys.exit(0)
80+
81+
82+
if __name__ == "__main__":
83+
main()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: se-packs-approved label verification
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, labeled, unlabeled]
5+
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
check_label_job:
12+
runs-on: ubuntu-latest
13+
if: github.repository == 'demisto/content'
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.10" # The Python version set here is the minimum supported by content, if you change it here, please change all the places containing this comment.
21+
- name: Setup Poetry
22+
uses: Gr1N/setup-poetry@v9
23+
- name: Install python dependencies
24+
run: |
25+
poetry install --with github-actions
26+
- name: set pythonpath
27+
run: |
28+
echo "PYTHONPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
29+
- name: Get changed files
30+
id: changed-files
31+
uses: tj-actions/changed-files@v46.0.1 # disable-secrets-detection
32+
with:
33+
files: |
34+
Packs/**/ModelingRules/**
35+
since_last_remote_commit: false
36+
- name: Check if se-packs-approved label exists
37+
id: check_label
38+
env:
39+
PR_NUMBER: ${{ github.event.pull_request.number }}
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
42+
run: |
43+
echo "Checking label SE-packs-approved for: $PR_NUMBER"
44+
cd .github/github_workflow_scripts
45+
poetry run python check_if_se_packs_approved_label_exists.py --pr_number $PR_NUMBER --github_token $GITHUB_TOKEN --changed_files $CHANGED_FILES

0 commit comments

Comments
 (0)