示例#1
0
 def sync_remote():
     try:
         git.fetch('--force')
         git.checkout('master', '--force')
         git.branch('--create-reflog', '-f', 'deploy', '-t', 'origin/deploy')
         git.checkout('deploy', '--force')
         git.branch('--create-reflog', '-f', 'master', '-t', 'origin/master')
         return True, "Synced to origin/master and origin/deploy. You'll probably want to !!/reboot now."
     except Exception as e:
         return False, str(e)
示例#2
0
 def sync_remote_hard():
     try:
         git.fetch('--force')
         git.checkout('master', '--force')
         git.reset('origin/master', '--hard')
         git.checkout('deploy', '--force')
         git.reset('origin/deploy', '--hard')
         git.checkout('master', '--force')
         git.checkout('deploy', '--force')
         return True, "Synced hard to origin/master and origin/deploy."
     except Exception as e:
         return False, str(e)
示例#3
0
    def merge_pull_request(cls, pr_id, comment=""):
        response = requests.get(
            "https://api.github.com/repos/{}/pulls/{}".format(
                GlobalVars.bot_repo_slug, pr_id))
        if not response:
            raise ConnectionError("Cannot connect to GitHub API")
        pr_info = response.json()
        if pr_info["user"]["login"] != "SmokeDetector":
            raise ValueError(
                "PR #{} is not created by me, so I can't approve it.".format(
                    pr_id))
        if "<!-- METASMOKE-BLACKLIST" not in pr_info["body"]:
            raise ValueError("PR description is malformed. Blame a developer.")
        if pr_info["state"] != "open":
            raise ValueError(
                "PR #{} is not currently open, so I won't merge it.".format(
                    pr_id))
        ref = pr_info['head']['ref']

        if comment:  # yay we have comments now
            GitHubManager.comment_on_thread(pr_id, comment)

        try:
            # Remote checks passed, good to go here
            cls.gitmanager_lock.acquire()
            git.checkout('master')
            origin_or_auth = cls.get_origin_or_auth()
            git.fetch(origin_or_auth, '+refs/pull/{}/head'.format(pr_id))
            git(
                "-c", "user.name=" + GlobalVars.git_name, "-c",
                "user.email=" + GlobalVars.git_email, "merge", 'FETCH_HEAD',
                '--no-ff', '-m', 'Merge pull request #{} from {}/{}'.format(
                    pr_id,
                    GlobalVars.bot_repo_slug.split("/")[0], ref))
            git.push(origin_or_auth, 'master')
            try:
                git.push('-d', origin_or_auth, ref)
            except GitError as e:
                # TODO: PR merged, but branch deletion has something wrong, generate some text
                pass
            return "Merged pull request [#{0}](https://github.com/{1}/pull/{0}).".format(
                pr_id, GlobalVars.bot_repo_slug)
        finally:
            git.checkout('deploy')
            cls.gitmanager_lock.release()
示例#4
0
    def reject_pull_request(cls, pr_id, comment=""):
        response = requests.get(
            "https://api.github.com/repos/{}/pulls/{}".format(
                GlobalVars.bot_repo_slug, pr_id))
        if not response:
            raise ConnectionError("Cannot connect to GitHub API")
        pr_info = response.json()
        if pr_info["user"]["login"] != "SmokeDetector":
            raise ValueError(
                "PR #{} is not created by me, so I can't reject it.".format(
                    pr_id))
        if "<!-- METASMOKE-BLACKLIST" not in pr_info["body"]:
            raise ValueError("PR description is malformed. Blame a developer.")
        if pr_info["state"] != "open":
            raise ValueError(
                "PR #{} is not currently open, so I won't reject it.".format(
                    pr_id))
        ref = pr_info['head']['ref']

        if comment:  # yay we have comments now
            GitHubManager.comment_on_thread(pr_id, comment)

        with cls.gitmanager_lock:
            origin_or_auth = cls.get_origin_or_auth()
            git.fetch(origin_or_auth, '+refs/pull/{}/head'.format(pr_id))
            payload = {"state": "closed"}
            response = GitHubManager.update_pull_request(pr_id, payload)
            if response:
                if response.json()["state"] == "closed":
                    git.push('-d', origin_or_auth, ref)
                    return "Closed pull request [#{0}](https://github.com/{1}/pull/{0}).".format(
                        pr_id, GlobalVars.bot_repo_slug)

        raise RuntimeError(
            "Closing pull request #{} failed. Manual operations required.".
            format(pr_id))
示例#5
0
 def get_remote_diff():
     git.fetch()
     if GlobalVars.on_windows:
         return git.diff_filenames("HEAD", "deploy@{u}")
     else:
         return git.diff("--name-only", "HEAD", "deploy@{u}")