-
-
Save projectgus/0aa5264d193bd58017205aa5486a9217 to your computer and use it in GitHub Desktop.
Script to comment on any MicroPython PRs that use the STATIC macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from github import Github | |
from github import Auth | |
from subprocess import check_output | |
from unidiff import PatchSet | |
import requests | |
import re | |
MSG = """This is an automated heads-up that we've just merged a Pull Request | |
that removes the STATIC macro from MicroPython's C API. | |
A search suggests this PR might apply the STATIC macro to some C code. If it | |
does, then next time you rebase the PR (or merge from master) then you should | |
please replace all the `STATIC` keywords with `static`. | |
Although this is an automated message, feel free to @-reply to me directly if | |
you have any questions about this. """ | |
def adds_static_macro(patch): | |
for f in patch: | |
if f.target_file.endswith(".c") or f.target_file.endswith(".h"): | |
for hunk in f: | |
for new_line in hunk.target: | |
if re.search(r"^\+STATIC", new_line) or re.search(r"^\+.+ STATIC( |$)", new_line): | |
return new_line | |
return None | |
def main(): | |
token = check_output(["gh", "auth", "token"]).strip().decode() | |
g = Github(auth=Auth.Token(token)) | |
repo = g.get_repo("micropython/micropython") | |
for pr in repo.get_pulls(state="open"): | |
diff = requests.get(pr.diff_url).text | |
patch = PatchSet(diff) | |
static_match = adds_static_macro(patch) | |
if static_match: | |
print(pr.html_url) | |
print(static_match) | |
# pr.create_issue_comment(MSG) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment