Last active
February 23, 2017 06:46
-
-
Save N3X15/a04aedd4188490235dcb300695813297 to your computer and use it in GitHub Desktop.
Retrofit for github.py in MoMMI
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
@command(r"testmerge\s*\[?(\d+)\]?$") | |
async def test_merger(content, match, message): | |
if not isowner(message.author): | |
await output(message.channel, "No") | |
return | |
id = int(match.group(1)) | |
async with aiohttp.ClientSession() as session: | |
# GET /repos/:owner/:repo/pulls/:number | |
url = github_url("/repos/{}/{}/pulls/{}".format(get_config("github.repo.owner"), get_config("github.repo.name"), id)) | |
# I have old-fashioned ideas about scope, I guess. | |
content = None | |
async with session.get(url, headers=HEADERS) as resp: | |
content = json.loads(await resp.text()) | |
origin_uri = 'https://github.com/{}/{}.git'.format(get_config('github.repo.owner'), get_config('github.repo.name')) | |
HEAD_URI = content['head']['repo']['git_url'] | |
BRANCH = content['head']['ref'] | |
# And MY API sucks, eh? | |
#from buildtools.repo.git import GitRepository | |
#from buildtools.os_utils import Chdir, cmd #, cmd_output - If we were interested in output. | |
#repo = GitRepository(get_config('git.repo.paths.testmerge'), origin_uri) | |
# Clones and checks the branch we want, if necessary or if the repo is fucked up. | |
#if repo.CheckForUpdates(branch=get_config('git.repo.branch')): | |
# # Also does --reset for us, among other things. (git clean -fdx) | |
# repo.Pull(branch=get_config('git.repo.branch'), cleanup=True) | |
#with Chdir(get_config('git.repo.paths.testmerge'), quiet=True): | |
# # Handled by the above | |
# #cmd(['git', 'reset', '--hard', critical=True]) | |
# #cmd(['git', 'branch', '-B', get_config('git.repo.testbranch'), get_config('git.repo.testbranch')], critical=True]) | |
# cmd(['git', 'pull', HEAD_URI, BRANCH], critical=True) | |
# cmd(['git', 'push', '-f', 'origin', get_config('git.repo.testbranch')], critical=True) | |
proc = await create_subprocess_exec("git", "reset", "--hard") # type: asyncio.Process | |
await proc.wait() | |
proc = await create_subprocess_exec("git", "branch", "-B", get_config('git.repo.testbranch'), get_config('git.repo.testbranch')) # type: asyncio.Process | |
await proc.wait() | |
proc = await create_subprocess_exec("git", "pull", HEAD_URI, BRANCH) # type: asyncio.Process | |
await proc.wait() | |
proc = await create_subprocess_exec("git", "push", "-f", origin_uri, get_config('git.repo.testbranch')) # type: asyncio.Process | |
await proc.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment