Lines Matching +full:repo +full:- +full:owner
3 # NB: the following functions are used in Meta-internal workflows
183 query ($owner: String!, $name: String!, $number: Int!) {
184 repository(owner: $owner, name: $name) {
276 query ($owner: String!, $name: String!, $number: Int!, $cursor: String!) {
277 repository(name: $name, owner: $owner) {
296 query ($owner: String!, $name: String!, $number: Int!, $cursor: String!) {
297 repository(name: $name, owner: $owner) {
316 query ($owner: String!, $name: String!, $number: Int!, $cs_cursor: String, $cr_cursor: String!) {
317 repository(name: $name, owner: $owner) {
350 query ($owner: String!, $name: String!, $number: Int!, $cursor: String!) {
351 repository(name: $name, owner: $owner) {
377 # This query needs read-org permission
399 query ($owner: String!, $name: String!, $number: Int!, $cursor: String) {
400 repository(name: $name, owner: $owner) {
414 query ($owner: String!, $name: String!, $number: Int!, $cursor: String!) {
415 repository(name: $name, owner: $owner) {
427 query ($owner: String!, $name: String!) {
428 repository(owner: $owner, name: $name) {
442 RE_GHSTACK_HEAD_REF = re.compile(r"^(gh/[^/]+/[0-9]+/)head$")
446 r"https://github.com/(?P<owner>[^/]+)/(?P<repo>[^/]+)/pull/(?P<number>[0-9]+)",
450 RE_DIFF_REV = re.compile(r"^Differential Revision:.+?(D[0-9]+)", re.MULTILINE)
458 INTERNAL_CHANGES_CHECKRUN_NAME = "Meta Internal-Only Changes Check"
462 # This could be set to -1 to ignore all flaky and broken trunk failures. On the
467 def gh_get_pr_info(org: str, proj: str, pr_no: int) -> Any:
468 rc = gh_graphql(GH_GET_PR_INFO_QUERY, name=proj, owner=org, number=pr_no)
473 def gh_get_team_members(org: str, name: str) -> List[str]:
487 warn(f"Requested non-existing team {org}/{name}")
494 def get_check_run_name_prefix(workflow_run: Any) -> str:
501 def is_passing_status(status: Optional[str]) -> bool:
509 ) -> JobNameToStateDict:
513 # workflow -> job -> job info
519 def add_conclusions(edges: Any) -> None:
608 def parse_args() -> Any:
612 parser.add_argument("--dry-run", action="store_true")
613 parser.add_argument("--revert", action="store_true")
614 parser.add_argument("--force", action="store_true")
615 parser.add_argument("--ignore-current", action="store_true")
616 parser.add_argument("--check-mergeability", action="store_true")
617 parser.add_argument("--comment-id", type=int)
618 parser.add_argument("--reason", type=str)
623 def can_skip_internal_checks(pr: "GitHubPR", comment_id: Optional[int] = None) -> bool:
629 return comment.author_login == "facebook-github-bot"
633 repo: GitRepo,
637 ) -> List[Tuple["GitHubPR", str]]:
640 msg = repo.commit_message(rev)
644 f"Could not find PR-resolved string in {msg} of ghstacked PR {pr.pr_num}"
646 if pr.org != m.group("owner") or pr.project != m.group("repo"):
648 f"PR {m.group('number')} resolved to wrong owner/repo pair"
659 repo: GitRepo, pr: "GitHubPR", open_only: bool = True
660 ) -> List[Tuple["GitHubPR", str]]:
665 # For ghstack, cherry-pick commits based from origin
666 orig_ref = f"{repo.remote}/{pr.get_ghstack_orig_ref()}"
667 rev_list = repo.revlist(f"{pr.default_branch()}..{orig_ref}")
669 def skip_func(idx: int, candidate: "GitHubPR") -> bool:
678 entire_stack = _revlist_to_prs(repo, pr, reversed(rev_list), skip_func)
685 base_ref = repo.get_merge_base(
686 f"{repo.remote}/{base_ref}", f"{repo.remote}/{stacked_pr.head_ref()}"
688 if not are_ghstack_branches_in_sync(repo, stacked_pr.head_ref(), base_ref):
699 def __init__(self, org: str, project: str, pr_num: int) -> None:
714 def is_closed(self) -> bool:
717 def is_cross_repo(self) -> bool:
720 def base_ref(self) -> str:
723 def default_branch(self) -> str:
726 def head_ref(self) -> str:
729 def is_ghstack_pr(self) -> bool:
732 def get_ghstack_orig_ref(self) -> str:
736 def is_base_repo_private(self) -> bool:
739 def get_changed_files_count(self) -> int:
742 def last_commit(self) -> Any:
743 return self.info["commits"]["nodes"][-1]["commit"]
745 def get_merge_base(self) -> str:
767 def get_changed_files(self) -> List[str]:
779 owner=self.org,
790 def get_submodules(self) -> List[str]:
792 rc = gh_graphql(GH_GET_REPO_SUBMODULES, name=self.project, owner=self.org)
797 def get_changed_submodules(self) -> List[str]:
801 def has_invalid_submodule_updates(self) -> bool:
813 def _get_reviews(self) -> List[Tuple[str, str]]:
827 owner=self.org,
838 def get_approved_by(self) -> List[str]:
841 def get_commit_count(self) -> int:
844 def get_pr_creator_login(self) -> str:
847 def _fetch_authors(self) -> List[Tuple[str, str]]:
852 def add_authors(info: Dict[str, Any]) -> None:
871 owner=self.org,
879 def get_committer_login(self, num: int = 0) -> str:
882 def get_committer_author(self, num: int = 0) -> str:
885 def get_labels(self) -> List[str]:
896 def get_checkrun_conclusions(self) -> JobNameToStateDict:
897 """Returns dict of checkrun -> [conclusion, url]"""
904 ) -> Any:
908 owner=self.org,
910 cs_cursor=edges[edge_idx - 1]["cursor"] if edge_idx > 0 else None,
914 -1
916 checkruns = last_commit["checkSuites"]["nodes"][-1]["checkRuns"]
919 def get_pr_next_checksuites(checksuites: Any) -> Any:
923 owner=self.org,
925 cursor=checksuites["edges"][-1]["cursor"],
928 last_commit = info["commits"]["nodes"][-1]["commit"]
955 def get_authors(self) -> Dict[str, str]:
962 def get_author(self) -> str:
973 def get_title(self) -> str:
976 def get_body(self) -> str:
979 def get_merge_commit(self) -> Optional[str]:
983 def get_pr_url(self) -> str:
987 def _comment_from_node(node: Any) -> GitHubComment:
999 def get_comments(self) -> List[GitHubComment]:
1014 owner=self.org,
1021 def get_last_comment(self) -> GitHubComment:
1022 return self._comment_from_node(self.info["comments"]["nodes"][-1])
1024 def get_comment_by_id(self, database_id: int) -> GitHubComment:
1026 # Fastpath - try searching in partial prefetched comments
1047 def get_diff_revision(self) -> Optional[str]:
1051 def has_internal_changes(self) -> bool:
1060 def has_no_connected_diff(self) -> bool:
1069 repo: GitRepo,
1073 ) -> List["GitHubPR"]:
1076 repo, self, open_only=False
1091 repo,
1095 repo.cherry_pick(rev)
1096 repo.amend_commit_message(commit_msg)
1104 ) -> str:
1124 # Mention PR co-authors, which should be at the end of the message
1131 msg += f"\nCo-authored-by: {author_name}"
1135 def add_numbered_label(self, label_base: str, dry_run: bool) -> None:
1147 repo: GitRepo,
1153 ) -> None:
1162 repo,
1168 repo, skip_mandatory_checks, comment_id
1171 repo.push(self.default_branch(), dry_run)
1180 merge_commit_sha = repo.rev_parse(name=REMOTE_MAIN_BRANCH)
1187 owner=self.org,
1208 repo: GitRepo,
1213 ) -> List["GitHubPR"]:
1215 … :param skip_all_rule_checks: If true, skips all rule checks, useful for dry-running merge locally
1218 if repo.current_branch() != branch_to_merge_into:
1219 repo.checkout(branch_to_merge_into)
1222 pr_branch_name = f"__pull-request-{self.pr_num}__init__"
1223 repo.fetch(f"pull/{self.pr_num}/head", pr_branch_name)
1224 repo._run_git("merge", "--squash", pr_branch_name)
1225 repo._run_git("commit", f'--author="{self.get_author()}"', "-m", msg)
1229 repo,
1237 def __init__(self, message: str, rule: Optional["MergeRule"] = None) -> None:
1260 org: str, project: str, labels: List[str], template: str = "bug-report.yml"
1261 ) -> str:
1271 repo: Optional[GitRepo], org: str, project: str
1272 ) -> List[MergeRule]:
1273 """Returns the list of all merge rules for the repo or project.
1275 NB: this function is used in Meta-internal workflows, see the comment
1279 if repo is None:
1288 rules_path = Path(repo.repo_dir) / repo_relative_rules_path
1299 repo: Optional[GitRepo] = None,
1303 ) -> Tuple[
1313 NB: this function is used in Meta-internal workflows, see the comment at the top of
1326 rules = read_merge_rules(repo, pr.org, pr.project)
1350 # Score 0 to 10K - how many files rule matched
1351 # Score 10K - matched all files, but no overlapping approvers
1352 # Score 20K - matched all files and approvers, but mandatory checks are pending
1353 # Score 30k - Matched all files and approvers, but mandatory checks failed
1365 num_matching_files = len(changed_files) - len(non_matching_files)
1371 … f"{num_matching_files} files matched, but there are still non-matching files:",
1403 … f"- {name} ({', '.join(approved_by[:5])}{', ...' if len(approved_by) > 5 else ''})"
1494 def checks_to_str(checks: List[Tuple[str, Optional[str]]]) -> str:
1500 ) -> List[str]:
1502 f"- [{c[0]}]({c[1]})" if c[1] is not None else f"- {c[0]}" for c in checks[:5]
1510 owner: str,
1526 ) -> None:
1536 "owner": owner,
1554 "_id": f"{project}-{pr_num}-{comment_id}-{os.environ.get('GITHUB_RUN_ID')}",
1564 def get_rockset_results(head_sha: str, merge_base: str) -> List[Dict[str, Any]]:
1594 def get_drci_classifications(pr_num: int, project: str = "pytorch") -> Any:
1602 data=f"repo={project}",
1614 REMOVE_JOB_NAME_SUFFIX_REGEX = re.compile(r", [0-9]+, [0-9]+, .+\)$")
1617 def remove_job_name_suffix(name: str, replacement: str = ")") -> str:
1624 ) -> bool:
1641 ) -> bool:
1663 ) -> bool:
1681 ) -> bool:
1683 After https://github.com/pytorch/test-infra/pull/4579, invalid cancelled
1707 ) -> Dict[str, JobCheckState]:
1713 def get_readable_drci_results(drci_classifications: Any) -> str:
1816 ) -> List[JobCheckState]:
1820 def get_pr_commit_sha(repo: GitRepo, pr: GitHubPR) -> str:
1824 commits = repo.commits_resolving_gh_pr(pr.pr_num)
1831 repo: GitRepo, pr: GitHubPR, *, comment_id: Optional[int] = None
1832 ) -> Tuple[str, str]:
1842 allowed_reverters = ["COLLABORATOR", "MEMBER", "OWNER"]
1843 # For some reason, one can not be a member of private repo, only CONTRIBUTOR
1854 pr, repo, skip_mandatory_checks=True, skip_internal_checks=True
1856 commit_sha = get_pr_commit_sha(repo, pr)
1861 repo: GitRepo, pr: GitHubPR, only_closed: bool = True
1862 ) -> List[Tuple[str, GitHubPR]]:
1868 orig_ref = f"{repo.remote}/{pr.get_ghstack_orig_ref()}"
1869 rev_list = repo.revlist(f"{pr.default_branch()}..{orig_ref}")
1874 skip_len = len(rev_list) - 1
1875 for branch in repo.branches_containing_ref(orig_ref):
1876 candidate = repo.revlist(f"{pr.default_branch()}..{branch}")
1880 # Validate that candidate always ends rev-list
1881 if rev_list[-len(candidate) :] != candidate:
1887 rev_list = rev_list[:-skip_len]
1889 for pr_, sha in _revlist_to_prs(repo, pr, rev_list):
1894 commit_sha = get_pr_commit_sha(repo, pr_)
1900 repo: GitRepo,
1907 ) -> None:
1913 repo.checkout(pr.default_branch())
1914 repo.revert(commit_sha)
1915 msg = repo.commit_message("HEAD")
1918 repo.amend_commit_message(msg)
1919 repo.push(shas_and_prs[0][1].default_branch(), dry_run)
1932 revert_message += "\ncc: @pytorch/pytorch-dev-infra"
1944 repo: GitRepo,
1950 ) -> None:
1952 author_login, commit_sha = validate_revert(repo, pr, comment_id=comment_id)
1966 shas_and_prs = get_ghstack_dependent_prs(repo, pr)
1975 repo,
1984 def prefix_with_github_url(suffix_str: str) -> str:
1988 def check_for_sev(org: str, project: str, skip_mandatory_checks: bool) -> None:
1995 params={"q": f'repo:{org}/{project} is:open is:issue label:"ci: sev"'},
2009 def has_label(labels: List[str], pattern: Pattern[str] = CIFLOW_LABEL) -> bool:
2017 ) -> Tuple[
2095 repo: GitRepo,
2102 ) -> None:
2120 # ignored and is toggled by the --ignore-current flag
2124 get_ghstack_prs(repo, pr) # raises error if out of sync
2137 repo,
2144 find_matching_merge_rule(pr, repo, skip_mandatory_checks=True)
2175 elapsed_time = current_time - start_time
2190 pr, repo, ignore_current_checks=ignore_current_checks
2240 repo,
2255 gh_add_labels(pr.org, pr.project, pr.pr_num, ["land-failed"], dry_run)
2259 def main() -> None:
2261 repo = GitRepo(get_git_repo_dir(), get_git_remote_name())
2262 org, project = repo.gh_owner_and_name()
2265 def handle_exception(e: Exception, title: str = "Merge failed") -> None:
2304 repo,
2329 "Cross-repo ghstack merges are not supported",
2345 get_ghstack_prs(repo, pr) # raises error if out of sync
2347 repo,
2363 repo,
2379 owner=org,