def handle(self): commit = Commit() commit.opcode = "created_debt_engine" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") debt = debt_engine_interface.get_debt_by_id(self._id) error = False balance = 0 model = debt.get("model") creator = debt.get("creator") oracle = debt.get("oracle") created = str(self._block_timestamp()) data = { "error": error, "balance": str(balance), "model": model, "creator": creator, "oracle": oracle, "created": created, "id": self._args.get("_id") } commit.id_loan = self._args.get("_id") commit.data = data return [commit]
def group_commits(tags, commits): tags = sorted(tags, key=lambda t: t.date) # Adding the tag's commit manually because those seem to be skipped commits.extend([Commit(t._commit) for t in tags]) # Sort the commits and filter out those not formatted correctly commits = sorted(commits, key=lambda c: c.date) commits = list(filter(lambda c: c.category, commits)) for index, tag in enumerate(tags): # Everything is sorted in ascending order (earliest to most recent), # So everything before the first tag belongs to that one if index == 0: children = filter(lambda c: c.date <= tag.date, commits) else: prev_tag = tags[index - 1] children = filter(lambda c: prev_tag.date < c.date <= tag.date, commits) for child in children: commits.remove(child) tag.add_commit(child) left_overs = list(filter(lambda c: c.date > tags[-1].date, commits)) return left_overs
def handle(self): commit = Commit() commit.opcode = "closed_auction" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") collateral_id = str(self._args.get("_entryId")) collateral = Collateral.objects.get(id=collateral_id) print(collateral.debt_id) loan = Loan.objects.get(id=collateral.debt_id) if loan.status == "2": status = str(CollateralState.TO_WITHDRAW.value) else: status = str(CollateralState.STARTED.value) data = { "id": collateral_id, "received": str(self._args.get("_received")), "leftover": str(self._args.get("_leftover")), "status": status } commit.data = data return [commit]
def test_repo_commits(self): repo = Repo.create(**self.TEST_REPO) repo.save() response = self.fetch(self.get_app().reverse_url('view', repo.id)) self.assertIn(self.MESSAGES['no_records'], response.body.decode()) self.assertIn(self.MESSAGES['get_more'], response.body.decode()) for commit in range(self.TEST_COUNT): commit_data = self.TEST_COMMIT commit_data.update({'repo': repo}) c = Commit(**commit_data) c.save() response = self.fetch(self.get_app().reverse_url('view', repo.id)) self.assertEqual(response.body.decode().count(self.TEST_COMMIT['message']), self.TEST_COUNT) self.assertIn(self.MESSAGES['get_more'], response.body.decode()) repo.next_page = None repo.save() response = self.fetch(self.get_app().reverse_url('view', repo.id)) self.assertNotIn(self.MESSAGES['get_more'], response.body.decode())
def load_commits(user, author, start_date, end_date): print('loading commits for ' + author) result = github_api.commits(user, author, start_date, end_date) for r in result: print('putting ' + r['sha']) commit = Commit(id=r['sha']) commit.author = author ts = time.mktime(parse(r['commit']['author']['date']).timetuple()) commit.date = datetime.datetime.utcfromtimestamp(ts) commit.html_url = r['html_url'] commit.put()
def init_commit_from_summary(self, line): commit_parameters, author_parameters = self.map_parameters(line) commit = Commit(**commit_parameters) self.commit_list.append(commit) if not author_parameters['author_email'] in self.author_dict: author = Author(**author_parameters) self.author_list.append(author) self.author_dict[author.author_email] = author self.current_author = self.author_dict[author_parameters['author_email']] self.current_author.commits.append(commit)
def handle(self): commit = Commit() commit.opcode = "pool_started_loanDAO" commit.timestamp = self._block_timestamp() commit.proof = self._transaction data = {"poolId": self._args.get("_poolId")} commit.data = data return [commit]
async def commit_scan_loop(self): leaderboard_cog = self.bot.get_cog("Leaderboard") await leaderboard_cog.create_leaderboard() repositories = self.bot.db_session.query(Repository).all() user_cache = {} summaries = {} repo_cache = {} for repository in repositories: repository_user, repository_repo = repository.repository.split("/") raw_commits = await self.utils.get_commits(repository_user, repository_repo) commits = self.utils.parse_commits(raw_commits) for commit in commits: commit["author"] = commit["author"].lower() if commit["author"] not in user_cache.keys(): user = self.bot.db_session.query(User).filter( User.github_username == commit["author"]).first() if user is None: continue user_cache[commit["author"]] = user user = user_cache[commit["author"]] old_commit = self.bot.db_session.query(Commit).filter(Commit.commit_hash == commit["hash"]).first() if old_commit is not None: continue database_commit = Commit(commit_hash=commit["hash"], user_id=user.id) self.bot.db_session.add(database_commit) old_summary = summaries.get(user.id, []) old_summary.append(commit) summaries[user.id] = old_summary repo_cache[commit["hash"]] = repository.repository self.bot.db_session.commit() for user_id, commits in summaries.items(): user = await self.bot.fetch_user(user_id) if user is None: continue discord_user = self.bot.get_user(user) for commit in commits: if user is not None: embed = discord.Embed( description=f"https://github.com/{repo_cache[commit['hash']]}/commit/{commit['hash']}", color=0x00FFFF) embed.set_author(name=str(user), icon_url=user.avatar_url) await self.commit_webhook.send(embed=embed) summary_pages = self.create_summary(user, commits) self.logger.debug(f"Sending a dm to {user}!") for page in summary_pages: try: await user.send(page) except: pass await leaderboard_cog.post_leaderboard()
def handle(self): commit = Commit() commit.opcode = "requested_loan_manager" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") oracle = self._args.get("_oracle") try: if oracle != "0x0000000000000000000000000000000000000000": oracle_contract = OracleInterface(oracle) currency = oracle_contract.currency() else: currency = loan_manager_interface.get_currency( self._args.get('_id')) if currency: currency = utils.add_0x_prefix(currency) except BadFunctionCallOutput: currency = "0x" print("currency: {}".format(currency)) data = { "id": self._args.get("_id"), "open": True, "approved": self._args.get("_creator") == self._args.get("_borrower"), "position": "0", "expiration": str(self._args.get("_expiration")), "amount": str(self._args.get("_amount")), "cosigner": "0x0000000000000000000000000000000000000000", "model": self._args.get("_model"), "creator": self._args.get("_creator"), "oracle": self._args.get("_oracle"), "borrower": self._args.get("_borrower"), "callback": self._args.get("_callback"), "salt": str(self._args.get("_salt")), "loanData": self._args.get("_loanData"), "created": str(self._block_timestamp()), "currency": currency, "status": "0" } descriptor = loan_manager_interface.get_descriptor(data) data["descriptor"] = descriptor commit.id_loan = self._args.get("_id") commit.data = data return [commit]
def handle(self): commit = Commit() config_data = installments_model_interface.get_config_by_id(self._args.get("_id")) commit.opcode = "created_installments" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") commit.data = config_data commit.id_loan = self._args.get("_id") return [commit]
def handle(self): commits = [] commit = Commit() commit.opcode = "changed_status_installments" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") data = { "id": self._args.get("_id"), "timestamp": str(self._args.get("_timestamp")), "status": str(self._args.get("_status")) } commit.id_loan = self._args.get("_id") commit.data = data commits.append(commit) # commit full payment loan manager commit_full_payment = Commit() commit_full_payment.opcode = "full_payment_loan_manager" commit_full_payment.timestamp = commit.timestamp commit_full_payment.proof = self._transaction commit_full_payment.proof = self._tx.get("from") data = { "id": self._args.get("_id"), "status": str(self._args.get("_status")) } commit_full_payment.id_loan = self._args.get("_id") commit_full_payment.data = data commits.append(commit_full_payment) return commits
def parse_push(ctxt, hook): commits = [ Commit(id=commit["id"], message=commit["message"], url=commit["url"], author=ctxt.get_or_create_user(commit["committer"]["name"], commit["committer"]["email"])) for commit in hook["commits"] ] return Push(branch=hook["ref"].split('/')[-1], commits=commits, url=hook["compare"], user=ctxt.user, project=ctxt.project)
def handle(self): commit = Commit() commit.opcode = "set_URIProvider_collateral" commit.timestamp = self._block_timestamp() commit.proof = self._transaction data = { "uriProvider": self._args.get("_uriProvider"), } commit.data = data return [commit]
def handle(self): commit = Commit() commit.opcode = "error_recover_debt_engine" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") data = {"id": self._args.get("_id"), "error": False} commit.id_loan = self._args.get("_id") commit.data = data return [commit]
def handle(self): commit = Commit() commit.opcode = "approved_loan_manager" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") data = {"id": self._args.get("_id"), "approved": True} commit.id_loan = self._args.get("_id") commit.data = data return [commit]
def handle(self): commit = Commit() commit.opcode = "ownership_transferred_collateral" commit.timestamp = self._block_timestamp() commit.proof = self._transaction data = { "previousOwner": self._args.get("_previousOwner"), "newOwner": self._args.get("_newOwner"), } commit.data = data return [commit]
def handle(self): commit = Commit() commit.opcode = "redeemed_collateral" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") data = { "id": str(self._args.get("_entryId")), "to": str(self._args.get("_to")), } commit.data = data return [commit]
def handle(self): commit = Commit() commit.opcode = "approval_for_all_collateral" commit.timestamp = self._block_timestamp() commit.proof = self._transaction data = { "owner": self._args.get("_owner"), "operator": self._args.get("_operator"), "approved": self._args.get("_approved") } commit.data = data return []
def handle(self): commit = Commit() commit.opcode = "pay_back_loanDAO" commit.timestamp = self._block_timestamp() commit.proof = self._transaction data = { "poolId": self._args.get("_poolId"), "lender": self._args.get("_lender"), "rest": str(self._args.get("_rest")) } commit.data = data return [commit]
def handle(self): commit = Commit() commit.opcode = "started_collateral" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") data = { "id": str(self._args.get("_entryId")), "status": str(CollateralState.STARTED.value) } commit.data = data return [commit]
def handle(self): commit = Commit() commit.opcode = "paid_ERC20D" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._address data = { "from": self._args.get("_from"), "value": self._args.get("_value"), "contractAddress": self._address } commit.data = data return [commit]
def handle(self): commit = Commit() commit.opcode = "set_paid_base_installments" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") data = { "id": self._args.get("_id"), "paid_base": str(self._args.get("_paidBase")) } commit.id_loan = self._args.get("_id") commit.data = data return [commit]
def test_push(self): commits = [ Commit(id="1d8d58ec4c8865394cd5ff91ce8e54b1d598346f", message="Fix py2 compat", url="http://example.com/project/commit/...", author=self.user) ] push = Push(user=self.user, project=self.project, branch="hotfix/Issue214", commits=commits, url="too long don't write") self.assertEqual( push.render_simple(), "[My Project] Mrs Foobar pushed 1 commits to hotfix/Issue214. " "(too long don't write)\n" "1d8d58e Mrs Foobar: Fix py2 compat")
def handle(self): commit = Commit() commit.opcode = "provide_oracleFactory" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") data = { "oracle": self._args.get("_oracle"), "signer": self._args.get("_signer"), "rate": str(self._args.get("_rate")) } commit.data = data return [commit]
def handle(self): commit = Commit() commit.opcode = "transfer_collateral" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") data = { "from": self._args.get("_from"), "to": self._args.get("_to"), "tokenId": str(self._args.get("_tokenId")) } commit.data = data return [commit]
def handle(self): commit = Commit() commit.opcode = "ownership_transferred_debt_engine" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") data = { "previous_owner": self._args.get("_previousOwner"), "new_owner": self._args.get("_newOwner"), } commit.data = data # return [commit] return []
def handle(self): commit = Commit() commit.opcode = "pay_batch_error_debt_engine" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") data = { "id": self._args.get("_id"), "oracle": self._args.get("_oracle") } commit.id_loan = self._args.get("_id") commit.data = data return [commit]
def handle(self): commit = Commit() commit.opcode = "settled_lend_loan_manager" commit.timestamp = self._block_timestamp() commit.proof = self._transaction commit.address = self._tx.get("from") data = { "id": self._args.get("_id"), "lender": self._args.get("_lender"), "tokens": self._args.get("_tokens") } commit.id_loan = self._args.get("_id") commit.data = data return [commit]
def parse_creation(ctxt, hook): commits = [ Commit( id=commit["id"], message=commit["message"], url=commit["url"], author=ctxt.get_or_create_user(**commit["author"]), ) for commit in hook["commits"] ] return Creation( branch=hook["ref"].split('/')[-1], commits=commits, url=("{}/compare/{}...{}".format(hook["project"]["web_url"], hook["project"]["default_branch"], hook["after"])), user=ctxt.user, project=ctxt.project, )
def parse_push(ctxt, hook): # First generate the list of all commits commits = [ Commit( id=commit["id"], message=commit["message"], url=commit["url"], author=ctxt.get_or_create_user(**commit["author"]), ) for commit in hook["commits"] ] return Push( branch=hook["ref"].split('/')[-1], commits=commits, url=("{}/compare/{}...{}".format(hook["project"]["web_url"], hook["before"], hook["after"])), user=ctxt.user, project=ctxt.project, )