|
| 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() |
0 commit comments