示例#1
0
    def __init__(self):
        GitMerger.__init__(self)
        PullValidator.__init__(self)

        self.gh = login(self.config["user"], token=self.config["auth_token"])
        self.repo = self.gh.repository(self.config["owner"],
                                       self.config["repo"])
示例#2
0
    def validate(self, pr=None, debug=False):
        self.repo.refresh()

        pr = self.get_pull(pr)
        if not pr: return False

        issue = self.repo.issue(pr.number)
        last_commit = deque(pr.iter_commits(), maxlen=1).pop()

        self.repo.create_status(sha=last_commit.sha, state="pending")

        status = PullValidator.validate(self, pr, debug)

        if status.warnings or status.ini_issues or status.file_issues or status.version_issues:
            #report them to the cops
            data = {
                "login": pr.user.login,
                "has-ini-issues": status.ini_issues != [],
                "info-issues": status.ini_issues,
                "has-file-issues": status.file_issues != [],
                "file-issues": status.file_issues,
                "has-warnings": status.warnings != [],
                "warnings": status.warnings,
                "has-version-issues": status.version_issues != [],
                "version-issues": status.version_issues,
                "qotd": self.gh.zen()
            }

            with open("templates/pr-issue.tpl") as f:
                issue_template = f.read()
            comments_md = pystache.render(issue_template, data)

            #failure commit status
            files = {"{0}.md".format(pr.number): {"content": comments_md}}
            gist = self.gh.create_gist(
                "Validation of PR #{0} for jsdelivr/jsdelivr".format(
                    pr.number),
                files=files,
                public=False)
            state = "error" if status.error_occured else "failure"
            message = "Automatic validation encountered an error" if status.error_occured else "Failed automatic validation"
            self.repo.create_status(sha=last_commit.sha,
                                    state=state,
                                    target_url=gist.html_url,
                                    description=message)

            #create a comment if nothings happening
            if not any(c.user.login == self.config["user"]
                       for c in issue.iter_comments()):
                issue.create_comment(comments_md)
        else:
            #success status and attempt to merge it
            self.repo.create_status(sha=last_commit.sha,
                                    state="success",
                                    target_url="http://www.lgtm.in/g",
                                    description="\"LGTM\" - bot")
            self.merge(pr)
示例#3
0
    def validate(self, pr=None, debug=False):
        self.repo.refresh()

        pr = self.get_pull(pr)
        if not pr: return False

        issue = self.repo.issue(pr.number)
        last_commit = deque(pr.iter_commits(), maxlen=1).pop()

        self.repo.create_status(sha=last_commit.sha, state="pending")

        status = PullValidator.validate(self, pr, debug)

        if status.warnings or status.ini_issues or status.file_issues or status.version_issues:
            #report them to the cops
            data = {
                "login": pr.user.login,

                "has-ini-issues": status.ini_issues != [],
                "info-issues": status.ini_issues,

                "has-file-issues": status.file_issues != [],
                "file-issues": status.file_issues,

                "has-warnings": status.warnings != [],
                "warnings": status.warnings,

                "has-version-issues": status.version_issues != [],
                "version-issues": status.version_issues,

                "qotd": self.gh.zen()
            }

            with open("templates/pr-issue.tpl") as f:
                issue_template = f.read()
            comments_md = pystache.render(issue_template, data)

            #failure commit status
            files = {"{0}.md".format(pr.number): {"content": comments_md}}
            gist = self.gh.create_gist("Validation of PR #{0} for jsdelivr/jsdelivr".format(pr.number), files=files, public=False)
            state = "error" if status.error_occured else "failure"
            message = "Automatic validation encountered an error" if status.error_occured else "Failed automatic validation"
            self.repo.create_status(sha=last_commit.sha, state=state, target_url=gist.html_url, description=message)

            if (debug):
                print comments_md

            #create a comment if nothings happening
            if not any(c.user.login == self.config["user"] for c in issue.iter_comments()):
                issue.create_comment(comments_md)
        else:
            if (debug == True):
                print 'Validation success'
            #success status and attempt to merge it
            self.repo.create_status(sha=last_commit.sha, state="success", target_url="http://www.lgtm.in/g", description="\"LGTM\" - bot")
            self.merge(pr)
示例#4
0
    def __init__(self):
        GitMerger.__init__(self)
        PullValidator.__init__(self)

        self.gh = login(self.config["user"], token=self.config["auth_token"])
        self.repo = self.gh.repository(self.config["owner"], self.config["repo"])