Skip to content

Commit

Permalink
Support contributions when the name of the repo isn't content (#31320)
Browse files Browse the repository at this point in the history
* update handle_external_pr.py

* set repo_name arg as optional
  • Loading branch information
adi88d authored Dec 5, 2023
1 parent c256974 commit ca346d3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions github_workflow_scripts/handle_external_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def packs_to_check_in_pr(file_paths: list[str]) -> set:
return pack_dirs_to_check


def get_packs_support_level_label(file_paths: list[str], external_pr_branch: str) -> str:
def get_packs_support_level_label(file_paths: list[str], external_pr_branch: str, repo_name: str = 'content') -> str:
"""
Get The contributions' support level label.
Expand All @@ -129,6 +129,7 @@ def get_packs_support_level_label(file_paths: list[str], external_pr_branch: str
Args:
file_paths(str): file paths
external_pr_branch (str): the branch of the external PR.
repo_name(str): the name of the forked repo (without the owner)
Returns:
highest support level of the packs that were changed, empty string in case no packs were changed.
Expand All @@ -148,7 +149,8 @@ def get_packs_support_level_label(file_paths: list[str], external_pr_branch: str
repo=Repo(Path().cwd(), search_parent_directories=True),
branch_to_checkout=external_pr_branch,
# in marketplace contributions the name of the owner should be xsoar-contrib
fork_owner=fork_owner if fork_owner != 'xsoar-bot' else 'xsoar-contrib'
fork_owner=fork_owner if fork_owner != 'xsoar-bot' else 'xsoar-contrib',
repo_name=repo_name
):
packs_support_levels = get_support_level(pack_dirs_to_check_support_levels_labels)
except Exception as error:
Expand Down Expand Up @@ -269,13 +271,17 @@ def main():
content_repo = gh.get_repo(f'{org_name}/{repo_name}')

pr_number = payload.get('pull_request', {}).get('number')
repo_name = payload.get('pull_request', {}).get('head', {}).get('repo', {}).get('name')

print(f'{t.cyan}PR origin repo: {repo_name} {t.normal}')

pr = content_repo.get_pull(pr_number)

pr_files = [file.filename for file in pr.get_files()]
print(f'{pr_files=} for {pr_number=}')

labels_to_add = [CONTRIBUTION_LABEL, EXTERNAL_LABEL]
if support_label := get_packs_support_level_label(pr_files, pr.head.ref):
if support_label := get_packs_support_level_label(pr_files, pr.head.ref, repo_name):
labels_to_add.append(support_label)

# Add the initial labels to PR:
Expand Down

0 comments on commit ca346d3

Please sign in to comment.