def apply_updates(self, branch, initial, pin_unpinned, close_stale_prs=False):

        InitialUpdateClass = self.req_bundle.get_initial_update_class()

        if initial:
            # get the list of pending updates
            try:
                _, _, _, updates = list(
                    self.req_bundle.get_updates(initial=initial, pin_unpinned=pin_unpinned)
                )[0]
            except __HOLE__:
                # need to catch the index error here in case the intial update is completely
                # empty
                updates = False
            # if this is the initial run and the update list is empty, the repo is already
            # up to date. In this case, we create an issue letting the user know that the bot is
            # now set up for this repo and return early.
            if not updates:
                self.create_issue(
                    title=InitialUpdateClass.get_title(),
                    body=InitialUpdateClass.get_empty_update_body()
                )
                return

        # check if we have an initial PR open. If this is the case, we attach the initial PR
        # to all updates and are done. The `Initial Update` has to be merged (or at least closed)
        # before we continue to do anything here.
        initial_pr = next(
            (pr for pr in self.pull_requests if
             pr.title == InitialUpdateClass.get_title() and pr.is_open),
            False
        )

        for title, body, update_branch, updates in self.iter_updates(initial, pin_unpinned):
            if initial_pr:
                pull_request = initial_pr
            elif title not in [pr.title for pr in self.pull_requests]:
                pull_request = self.commit_and_pull(
                    initial=initial,
                    base_branch=branch,
                    new_branch=update_branch,
                    title=title,
                    body=body,
                    updates=updates
                )
            else:
                pull_request = next((pr for pr in self.pull_requests if pr.title == title), None)

            for update in updates:
                update.requirement.pull_request = pull_request
                if close_stale_prs and pull_request and not initial:
                    self.close_stale_prs(update, pull_request)
dataset/ETHPy150Open pyupio/pyup/pyup/bot.py/Bot.apply_updates