Process pull requets directly from mbox

Rather than letting b4 fetch a second time use the same one
that was already downloaded.

Signed-off-by: Mario Limonciello <superm1@gmail.com>
main
Mario Limonciello 2023-11-13 22:01:03 -06:00
parent 398b4605a3
commit 1f8f61d5cd
1 changed files with 9 additions and 9 deletions

View File

@ -142,14 +142,15 @@ def delete_branch(branch):
quiet_cmd(["git", "branch", "-D", branch]) quiet_cmd(["git", "branch", "-D", branch])




def process_pr(url, num, remote): def process_pr(mbox, num, remote):
branch = "robot/pr-{}-{}".format(num, int(time.time())) branch = "robot/pr-{}-{}".format(num, int(time.time()))
cmd = ["b4", "pr", "-b", branch, url]
try: cmd = ["b4", "--debug", "pr", "-b", branch, "-"]
quiet_cmd(cmd) logging.debug("Running {}".format(cmd))
except subprocess.CalledProcessError: p = subprocess.Popen(
logging.warning("Failed to apply PR") cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
return None )
stdout, stderr = p.communicate(mbox.encode("utf-8"))


# determine if it worked (we can't tell unfortunately by return code) # determine if it worked (we can't tell unfortunately by return code)
cmd = ["git", "branch", "--list", branch] cmd = ["git", "branch", "--list", branch]
@ -244,7 +245,6 @@ def process_database(conn, remote):


# loop over all unprocessed urls # loop over all unprocessed urls
for row in rows: for row in rows:

branch = None branch = None
msg = "Processing ({}%)".format(round(num / len(rows) * 100)) msg = "Processing ({}%)".format(round(num / len(rows) * 100))
print(msg, end="\r", flush=True) print(msg, end="\r", flush=True)
@ -260,7 +260,7 @@ def process_database(conn, remote):


if classification == ContentType.PULL_REQUEST: if classification == ContentType.PULL_REQUEST:
logging.debug("Processing PR ({})".format(row[0])) logging.debug("Processing PR ({})".format(row[0]))
branch = process_pr(row[0], num, remote) branch = process_pr(mbox, num, remote)


if classification == ContentType.SPAM: if classification == ContentType.SPAM:
logging.debug("Marking spam ({})".format(row[0])) logging.debug("Marking spam ({})".format(row[0]))