示例#1
0
def build(num, targets):
    """Build TARGETS for pull request NUM.

    NUM is the PR number you want to build targets
    for, and TARGETS is the list of apps you want
    to build within that PR. If no targets are passed
    in, then all apps modified in the PR are built.
    """
    repo = Github().get_repo(APPS)

    try:
        pull = repo.get_pull(int(num))
    except UnknownObjectException:
        raise Exception("Couldn't find that PR.")

    if pull.state == "closed":
        raise Exception("Cannot build targets for a closed PR!")

    print(f"PR {num}: {pull.title}")
    print(f"Building targets: {targets if targets else ['all']}")

    for target in targets:
        trigger_build_sync(
            pr_number=int(num),
            target_app=target,
            _impersonate="buildserver",
            noreply=True,
        )

    print("Build triggered!")
    def _process(self):
        if "friend computer please build" not in self._message.lower():
            return

        if "cs61a" != self._course:
            return

        users = requests.get("https://slack.com/api/users.list",
                             params={
                                 "token": self._bot_token
                             }).json()

        for member in users["members"]:
            if member["id"] == self._event["user"]:
                sender_email = member["profile"].get("email")
                break

        if not sender_email or not is_admin(course="cs61a",
                                            email=sender_email):
            return

        match = re.search(REGEX_TEMPLATE, self._message)

        if not match:
            return

        try:
            pr = int(match.group("path"))
        except ValueError:
            return

        trigger_build_sync(pr_number=pr, noreply=True)
        self.reply = ":building_construction: Build triggered!"
示例#3
0
def trigger_build():
    if not is_staff("cs61a"):
        return login()
    email = get_user()["email"]
    if not is_admin(course="cs61a", email=email):
        abort(401)
    if "app" in request.args:
        target = request.args["app"]
    else:
        target = None

    pr_number = int(request.args["pr_number"])

    g = Github(get_secret(secret_name="GITHUB_ACCESS_TOKEN"))
    repo = g.get_repo(GITHUB_REPO)
    pr = repo.get_pull(pr_number)

    if DO_NOT_BUILD in [l.name for l in pr.labels]:
        return html(
            f"PR <code>{pr_number}</code> has a DO NOT BUILD label on it, so it cannot be built. Remove this label to build the PR."
        )

    trigger_build_sync(pr_number=pr_number, target_app=target, noreply=True)
    return html(f"Building PR <code>{pr_number}</code>!")