MCPcopy Create free account
hub / github.com/apache/arrow / merge

Method merge

dev/merge_arrow_pr.py:440–526  ·  view source on GitHub ↗

merge the requested PR and return the merge hash

(self)

Source from the content-addressed store, hash-verified

438 f"GH-XXX, but found {self.title}")
439
440 def merge(self):
441 """
442 merge the requested PR and return the merge hash
443 """
444 commits = self._github_api.get_pr_commits(self.number)
445
446 def format_commit_author(commit):
447 author = commit['commit']['author']
448 name = author['name']
449 email = author['email']
450 return f'{name} <{email}>'
451 commit_authors = [format_commit_author(commit) for commit in commits]
452 co_authored_by_re = re.compile(
453 r'^Co-authored-by:\s*(.*)', re.MULTILINE)
454
455 def extract_co_authors(commit):
456 message = commit['commit']['message']
457 return co_authored_by_re.findall(message)
458 commit_co_authors = []
459 for commit in commits:
460 commit_co_authors.extend(extract_co_authors(commit))
461
462 all_commit_authors = commit_authors + commit_co_authors
463 distinct_authors = sorted(set(all_commit_authors),
464 key=lambda x: commit_authors.count(x),
465 reverse=True)
466
467 for i, author in enumerate(distinct_authors):
468 print(f"Author {i + 1}: {author}")
469
470 if len(distinct_authors) > 1:
471 primary_author, distinct_other_authors = get_primary_author(
472 self.cmd, distinct_authors)
473 else:
474 # If there is only one author, do not prompt for a lead author
475 primary_author = distinct_authors.pop()
476 distinct_other_authors = []
477
478 commit_title = f'{self.title} (#{self.number})'
479 commit_message_chunks = []
480 if self.body is not None:
481 # Remove comments (i.e. <-- comment -->) from the PR description.
482 body = re.sub(r"<!--.*?-->", "", self.body, flags=re.DOTALL)
483 # avoid github user name references by inserting a space after @
484 body = re.sub(r"@(\w+)", "@ \\1", body)
485 commit_message_chunks.append(body)
486
487 committer_name = run_cmd("git config --get user.name").strip()
488 committer_email = run_cmd("git config --get user.email").strip()
489
490 authors = ("Authored-by:" if len(distinct_other_authors) == 0
491 else "Lead-authored-by:")
492 authors += " %s" % primary_author
493 if len(distinct_authors) > 0:
494 authors += "\n" + "\n".join(["Co-authored-by: %s" % a
495 for a in distinct_other_authors])
496 authors += "\n" + "Signed-off-by: %s <%s>" % (committer_name,
497 committer_email)

Callers 7

cliFunction · 0.95
MergeMethod · 0.45
ConsumeMethod · 0.45
MergeAllMethod · 0.45
apt_updateMethod · 0.45
bump_versionsMethod · 0.45
prepareMethod · 0.45

Calls 10

lenFunction · 0.85
get_primary_authorFunction · 0.85
get_pr_commitsMethod · 0.80
extendMethod · 0.80
merge_prMethod · 0.80
run_cmdFunction · 0.70
countMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45
failMethod · 0.45

Tested by 2

bump_versionsMethod · 0.36
prepareMethod · 0.36